From cd6ac77684194a5f0ee9a8672f207d1edfdd6640 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Fri, 25 Aug 2023 23:56:09 +0100 Subject: html: Abstract out opening and closing of HTML tags. * src/guile/skribilo/engine/html.scm: Import (srfi srfi-26). (html-open, html-close): New functions. (html-markup-class, &html-head, &html-body, &html-page, &html-header-favicon, &html-header-css, &html-header-javascript, &html-generic-title, &html-footnotes, html-title-authors, author, toc, chapter, html-section-title, paragraph, footnote, linebreak, hrule, color, frame, font, flush, itemize, enumerate, description, item, blockquote, figure, &html-figure-legend, table, tr, tc, image, mailto, mark, ref, url-ref, &prog-line, &bib-entry-label, &the-index-header): Use html-open and html-close. --- src/guile/skribilo/engine/html.scm | 848 ++++++++++++++++++++++--------------- 1 file changed, 499 insertions(+), 349 deletions(-) (limited to 'src/guile') diff --git a/src/guile/skribilo/engine/html.scm b/src/guile/skribilo/engine/html.scm index da40475..088d168 100644 --- a/src/guile/skribilo/engine/html.scm +++ b/src/guile/skribilo/engine/html.scm @@ -44,6 +44,7 @@ #:use-module (srfi srfi-1) #:use-module (srfi srfi-13) #:use-module (srfi srfi-14) + #:use-module (srfi srfi-26) #:use-module (srfi srfi-39) #:export (html-engine html-title-engine html-file @@ -574,14 +575,42 @@ (if (or (string? c) (symbol? c) (number? c)) (format #t " class=\"~a\"" c))))) +;*---------------------------------------------------------------------*/ +;* html-open ... */ +;*---------------------------------------------------------------------*/ +(define* (html-open tag #:optional (attributes '())) + "Output opening TAG with ATTRIBUTES, an association list mapping +attribute names to their values. Attribute names may be symbols or +strings. Values may be symbols, strings or numbers. Attributes with +unspecified or #f values are ignored." + (display "<") + (display tag) + (for-each (match-lambda + ((name . value) + (when (and value + (not (unspecified? value))) + (format #t " ~a=\"~a\"" name value)))) + attributes) + (display ">") + (newline)) + +;*---------------------------------------------------------------------*/ +;* html-close ... */ +;*---------------------------------------------------------------------*/ +(define (html-close tag) + "Output closing TAG." + (display "") + (display tag) + (display ">") + (newline)) + ;*---------------------------------------------------------------------*/ ;* html-markup-class ... */ ;*---------------------------------------------------------------------*/ (define (html-markup-class m) - (lambda (n e) - (format #t "<~a" m) - (html-class n) - (display ">"))) + (lambda (n e) + (html-open m + `((class . ,(markup-class n)))))) ;*---------------------------------------------------------------------*/ ;* html-color-spec? ... */ @@ -629,10 +658,12 @@ ;*---------------------------------------------------------------------*/ (markup-writer '&html-head :before (lambda (n e) - (display "
\n") - (display "\n" (engine-custom (find-engine 'html) - 'charset)) + (html-open 'head) + (html-open 'meta + `((http-equiv . "Content-Type") + (content . "text/html;") + (charset . ,(engine-custom (find-engine 'html) + 'charset)))) (let ((head (engine-custom e 'head))) (when head (display head) @@ -655,10 +686,10 @@ (markup-writer '&html-body :before (lambda (n e) (let ((bg (engine-custom e 'background))) - (display "\n"))) + (html-open 'body + `((class . ,(markup-class n)) + (bgcolor . ,(and (html-color-spec? bg) + bg)))))) :after "\n") ;*---------------------------------------------------------------------*/ @@ -667,26 +698,30 @@ (markup-writer '&html-page :action (lambda (n e) (define (html-margin m fn size bg fg cla) - (format #t "