diff options
author | Ludovic Court`es | 2006-11-17 09:06:30 +0000 |
---|---|---|
committer | Ludovic Court`es | 2006-11-17 09:06:30 +0000 |
commit | b2aec83973f1b7c2bf9e952ed8e713611cbdc7fb (patch) | |
tree | 17b8eb6efc0dbea3cbbf142ef6a9a33d3ec4d022 /src | |
parent | 62443764135d6810a8e45d888b282344c5de42a5 (diff) | |
download | skribilo-b2aec83973f1b7c2bf9e952ed8e713611cbdc7fb.tar.gz skribilo-b2aec83973f1b7c2bf9e952ed8e713611cbdc7fb.tar.lz skribilo-b2aec83973f1b7c2bf9e952ed8e713611cbdc7fb.zip |
outline reader: Support keywords.
* src/guile/skribilo/reader/outline.scm (outline-reader)[keywords-rx]:
New.
[author-rx]: Support "Authors" (plural).
[extract-keywords]: New.
Use a `cond' instead of nested `if's when matching the
title/author/keywords regexps.
git-archimport-id: skribilo@sv.gnu.org--2006/skribilo--devo--1.2--patch-16
Diffstat (limited to 'src')
-rw-r--r-- | src/guile/skribilo/reader/outline.scm | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/src/guile/skribilo/reader/outline.scm b/src/guile/skribilo/reader/outline.scm index 09792f5..7411892 100644 --- a/src/guile/skribilo/reader/outline.scm +++ b/src/guile/skribilo/reader/outline.scm @@ -22,7 +22,10 @@ :use-module (skribilo utils syntax) :use-module (skribilo reader) :use-module (ice-9 optargs) + :use-module (srfi srfi-11) + :use-module (srfi srfi-13) + :use-module (srfi srfi-14) :autoload (ice-9 rdelim) (read-line) :autoload (ice-9 regex) (make-regexp) @@ -380,12 +383,19 @@ to @var{node-type}." (define modeline-rx (make-regexp "^[[:space:]]*-\\*- [a-zA-Z-]+ -\\*-[[:space:]]*$")) (define title-rx (make-regexp "^[Tt]itle: (.+)$" regexp/extended)) - (define author-rx (make-regexp "^[Aa]uthor: (.+)$" regexp/extended)) + (define author-rx (make-regexp "^[Aa]uthors?: (.+)$" regexp/extended)) + (define keywords-rx + (make-regexp "^[Kk]ey ?[wW]ords?: (.+)$" regexp/extended)) + + (define (extract-keywords str) + (map string-trim-both + (string-tokenize str (char-set-complement (char-set #\,))))) (let ((doc-proc (make-document-processor %node-processors %line-processor))) (let loop ((title #f) (author #f) + (keywords '()) (line (read-line port))) (if (eof-object? line) @@ -394,20 +404,34 @@ to @var{node-type}." line) (if (or (empty-line? line) (regexp-exec modeline-rx line)) - (loop title author (read-line port)) - (let ((title-match (regexp-exec title-rx line))) - (if title-match - (loop (match:substring title-match 1) - author (read-line port)) - (let ((author-match (regexp-exec author-rx line))) - (if author-match - (loop title (match:substring author-match 1) - (read-line port)) - - ;; Let's go. - `(document :title ,title - :author (author :name ,author) - ,@(doc-proc line port))))))))))) + (loop title author keywords (read-line port)) + (cond ((regexp-exec title-rx line) + => + (lambda (title-match) + (loop (match:substring title-match 1) + author keywords (read-line port)))) + + ((regexp-exec author-rx line) + => + (lambda (author-match) + (loop title (match:substring author-match 1) + keywords (read-line port)))) + + ((regexp-exec keywords-rx line) + => + (lambda (kw-match) + (loop title author + (append keywords + (extract-keywords + (match:substring kw-match 1))) + (read-line port)))) + + (else + ;; Let's go. + `(document :title ,title + :author (author :name ,author) + :keywords ',keywords + ,@(doc-proc line port))))))))) (define* (make-outline-reader :optional (version "0.1")) |