diff options
author | Ludovic Courtes | 2006-11-25 17:40:28 +0000 |
---|---|---|
committer | Ludovic Courtes | 2006-11-25 17:40:28 +0000 |
commit | 45b606578f7bae67ee92ca77b894d71a3ebab82a (patch) | |
tree | 4719f45d90ddf001ef4c761813b5d4465883e636 | |
parent | a5b8c2cfaf31b5d81a900b1020eb45252d775dd0 (diff) | |
download | skribilo-45b606578f7bae67ee92ca77b894d71a3ebab82a.tar.gz skribilo-45b606578f7bae67ee92ca77b894d71a3ebab82a.tar.lz skribilo-45b606578f7bae67ee92ca77b894d71a3ebab82a.zip |
Introduced `markup-number-string'.
* src/guile/skribilo/ast.scm: Use `(ice-9 optargs)'.
(markup-number-string): New (stolen from the Lout engine).
* src/guile/skribilo/engine/lout.scm: Use it.
(lout-structure-number-string): Redefined in terms of
`markup-number-string'.
git-archimport-id: skribilo@sv.gnu.org--2006/skribilo--devo--1.2--patch-18
-rw-r--r-- | src/guile/skribilo/ast.scm | 22 | ||||
-rw-r--r-- | src/guile/skribilo/engine/lout.scm | 22 |
2 files changed, 30 insertions, 14 deletions
diff --git a/src/guile/skribilo/ast.scm b/src/guile/skribilo/ast.scm index 542f629..55f37bf 100644 --- a/src/guile/skribilo/ast.scm +++ b/src/guile/skribilo/ast.scm @@ -30,6 +30,9 @@ :autoload (skribilo location) (location?) :autoload (srfi srfi-1) (fold) + + :use-module (ice-9 optargs) + :export (<ast> ast? ast-loc ast-loc-set! ast-parent ast->string ast->file-location ast-resolved? @@ -62,6 +65,9 @@ find-up find1-up ast-document ast-chapter ast-section + ;; numbering + markup-number-string + ;; error conditions &ast-error &ast-orphan-error &ast-cycle-error &markup-unknown-option-error &markup-already-bound-error @@ -596,6 +602,22 @@ (define (ast-section m) (find1-up (lambda (n) (is-markup? n 'section)) m)) + +;;; +;;; Section numbering. +;;; + +(define* (markup-number-string markup :optional (sep ".")) + ;; Return a structure number string such as "1.2". + (let loop ((markup markup)) + (if (document? markup) + "" + (let ((parent-num (loop (ast-parent markup))) + (num (markup-option markup :number))) + (string-append parent-num + (if (string=? "" parent-num) "" sep) + (if (number? num) (number->string num) "")))))) + ;;; arch-tag: e2489bd6-1b6d-4b03-bdfb-83cffd2f7ce7 diff --git a/src/guile/skribilo/engine/lout.scm b/src/guile/skribilo/engine/lout.scm index 272b131..6106f35 100644 --- a/src/guile/skribilo/engine/lout.scm +++ b/src/guile/skribilo/engine/lout.scm @@ -502,7 +502,7 @@ (if num (begin (if (is-markup? node 'chapter) (display "@B { ")) - (printf "~a. |2s " (lout-structure-number-string node)) + (printf "~a. |2s " (markup-number-string node)) (output title engine) (if (is-markup? node 'chapter) (display " }"))) (if (is-markup? node 'chapter) @@ -525,7 +525,7 @@ (define (lout-pdf-bookmark-title node engine) ;; Default implementation of the `pdf-bookmark-title-proc' custom that ;; returns a title (a string) for the PDF bookmark of `node'. - (let ((number (lout-structure-number-string node))) + (let ((number (markup-number-string node))) (string-append (if (string=? number "") "" (string-append number ". ")) (ast->string (markup-option node :title))))) @@ -1321,17 +1321,11 @@ doc-type))))) (define-public (lout-structure-number-string markup) - ;; Return a structure number string such as "1.2". - ;; FIXME: External code has started to rely on this. This should be - ;; generalized and moved elsewhere. - (let loop ((struct markup)) - (if (document? struct) - "" - (let ((parent-num (loop (ast-parent struct))) - (num (markup-option struct :number))) - (string-append parent-num - (if (string=? "" parent-num) "" ".") - (if (number? num) (number->string num) "")))))) + ;; FIXME: External code has started to rely on this before this was moved + ;; to the `ast' module as `markup-number-string'. Thus, we'll have to keep it + ;; here for some time. + (markup-number-string markup ".")) + ;*---------------------------------------------------------------------*/ ;* lout-block-before ... */ @@ -1360,7 +1354,7 @@ (if (number? number) (printf " @BypassNumber { ~a }\n" - (lout-structure-number-string n)) + (markup-number-string n)) (if (not number) ;; this trick hides the section number (printf " @BypassNumber { } # unnumbered\n"))) |