;;; web-article.scm -- A style to produce web articles. ;;; -*- coding: iso-8859-1 -*- ;;; ;;; Copyright 2007, 2008 Ludovic Courtès ;;; Copyright 2003, 2004 Manuel Serrano ;;; ;;; ;;; This file is part of Skribilo. ;;; ;;; Skribilo is free software: you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation, either version 3 of the License, or ;;; (at your option) any later version. ;;; ;;; Skribilo is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Skribilo. If not, see . (define-module (skribilo package web-article) #:use-module (skribilo utils syntax) #:use-module (skribilo ast) #:use-module (skribilo engine) #:use-module (skribilo writer) #:use-module (skribilo package base) #:autoload (skribilo output) (output) #:autoload (skribilo evaluator) (evaluate-document) #:autoload (skribilo engine html) (html-width html-title-authors) #:autoload (skribilo utils strings) (string-canonicalize) #:use-module (srfi srfi-1)) (skribilo-module-syntax) ;; FIXME: The purpose of this package is unclear, and it relies on "documents ;; made of sections" (according to the doc), which sucks (we want all ;; documents to consist of chapters at the top-level, so that engines can at ;; least assume that), so better not advertise it. ;*---------------------------------------------------------------------*/ ;* &web-article-load-options ... */ ;*---------------------------------------------------------------------*/ (define &web-article-load-options (*load-options*)) ;*---------------------------------------------------------------------*/ ;* web-article-body-width ... */ ;*---------------------------------------------------------------------*/ (define (web-article-body-width e) (let ((w (engine-custom e 'body-width))) (if (or (number? w) (string? w)) w 98.))) ;*---------------------------------------------------------------------*/ ;* html-document-title-web ... */ ;*---------------------------------------------------------------------*/ (define (html-document-title-web n e) (let* ((title (markup-body n)) (authors (markup-option n 'author)) (tbg (engine-custom e 'title-background)) (tfg (engine-custom e 'title-foreground)) (tfont (engine-custom e 'title-font))) (format #t "
\n" (html-width (web-article-body-width e))) (if (string? tbg) (format #t "
" tbg) (display "")) (if (string? tfg) (format #t "" tfg)) (if title (begin (display "
") (if (string? tfont) (begin (format #t "" tfont) (output title e) (display "")) (begin (display "

") (output title e) (display "

"))) (display "
\n"))) (if (not authors) (display "\n") (html-title-authors authors e)) (if (string? tfg) (display "
")) (display "
\n"))) ;*---------------------------------------------------------------------*/ ;* web-article-css-document-title ... */ ;*---------------------------------------------------------------------*/ (define (web-article-css-document-title n e) (let* ((title (markup-body n)) (authors (markup-option n 'author)) (id (markup-ident n))) ;; the title (format #t "
\n" (string-canonicalize id)) (output title e) (display "
\n") ;; the authors (format #t "
\n" (string-canonicalize id)) (for-each (lambda (a) (output a e)) (cond ((is-markup? authors 'author) (list authors)) ((list? authors) authors) (else '()))) (display "
\n"))) ;*---------------------------------------------------------------------*/ ;* web-article-css-author ... */ ;*---------------------------------------------------------------------*/ (define (web-article-css-author n e) (let ((name (markup-option n :name)) (title (markup-option n :title)) (affiliation (markup-option n :affiliation)) (email (markup-option n :email)) (url (markup-option n :url)) (address (markup-option n :address)) (phone (markup-option n :phone))) (when name (format #t "" (string-canonicalize (markup-ident n))) (output name e) (display "\n")) (when title (format #t "" (string-canonicalize (markup-ident n))) (output title e) (display "\n")) (when affiliation (format #t "" (string-canonicalize (markup-ident n))) (output affiliation e) (display "\n")) (when (pair? address) (format #t "" (string-canonicalize (markup-ident n))) (for-each (lambda (a) (output a e) (newline)) address) (display "\n")) (when phone (format #t "" (string-canonicalize (markup-ident n))) (output phone e) (display "\n")) (when email (format #t "" (string-canonicalize (markup-ident n))) (output email e) (display "\n")) (when url (format #t "" (string-canonicalize (markup-ident n))) (output url e) (display "\n")))) ;*---------------------------------------------------------------------*/ ;* HTML settings */ ;*---------------------------------------------------------------------*/ (define (web-article-modern-setup he) (let ((sec (markup-writer-get 'section he)) (ft (markup-writer-get '&html-footnotes he))) ;; &html-document-title (markup-writer '&html-document-title he :action html-document-title-web) ;; section (markup-writer 'section he :options 'all :before "
" :action (lambda (n e) (let ((e1 (make-engine 'html-web :delegate e)) (bg (engine-custom he 'section-background))) (markup-writer 'section e1 :options 'all :action (lambda (n e2) (output n e sec))) (evaluate-document (center (color :width (web-article-body-width e) :margin 5 :bg bg n)) e1)))) ;; &html-footnotes (markup-writer '&html-footnotes he :options 'all :before "
" :action (lambda (n e) (let ((e1 (make-engine 'html-web :delegate e)) (bg (engine-custom he 'section-background)) (fg (engine-custom he 'subsection-title-foreground))) (markup-writer '&html-footnotes e1 :options 'all :action (lambda (n e2) (invoke (writer-action ft) n e))) (evaluate-document (center (color :width (web-article-body-width e) :margin 5 :bg bg :fg fg n)) e1)))))) ;*---------------------------------------------------------------------*/ ;* web-article-css-setup ... */ ;*---------------------------------------------------------------------*/ (define (web-article-css-setup he) (let ((sec (markup-writer-get 'section he)) (ft (markup-writer-get '&html-footnotes he))) ;; &html-document-title (markup-writer '&html-document-title he :before (lambda (n e) (format #t "
\n" (string-canonicalize (markup-ident n)))) :action web-article-css-document-title :after "
\n") ;; author (markup-writer 'author he :options '(:name :title :affiliation :email :url :address :phone :photo :align) :before (lambda (n e) (format #t "\n" (string-canonicalize (markup-ident n)))) :action web-article-css-author :after "" (string-canonicalize (markup-ident n)))) :action (lambda (n e) (output n e sec)) :after "\n") ;; &html-footnotes (markup-writer '&html-footnotes he :options 'all :before (lambda (n e) (format #t "
" (string-canonicalize (markup-ident n)))) :action (lambda (n e) (output n e ft)) :after "
\n"))) ;*---------------------------------------------------------------------*/ ;* Setup ... */ ;*---------------------------------------------------------------------*/ ;; FIXME: The `*load-options*' stuff is not usable from `use-modules', so we ;; must provide another mechanism, e.g., exporting a `customize-engine!' ;; method or so. (let* ((opt &web-article-load-options) (p (memq :style opt)) (css (memq :css opt)) (he (find-engine 'html))) (cond ((and (pair? p) (pair? (cdr p)) (eq? (cadr p) 'css)) (web-article-css-setup he)) ((and (pair? css) (pair? (cdr css)) (string? (cadr css))) (engine-custom-set! he 'css (cadr css)) (web-article-css-setup he)) (else (web-article-modern-setup he))))