Changeset 14228 for lang/gauche

Show
Ignore:
Timestamp:
06/18/08 23:39:31 (5 months ago)
Author:
kiyoka
Message:

Supported plain text layouter.

Location:
lang/gauche/oldtype/trunk
Files:
2 added
5 modified

Legend:

Unmodified
Added
Removed
  • lang/gauche/oldtype/trunk/Kahua/oldtype/oldtype/format.scm

    r13023 r14228  
    5252          oldtype:expand-page 
    5353          oldtype:format-line-plainly 
    54           ) 
    55   ) 
     54          oldtype:oldtype-page->plain-text 
     55  )) 
    5656(select-module oldtype.format) 
    5757 
     
    6565(define (oldtype:calculate-heading-id headings) 
    6666  (string-append "H-" (number->string (hash headings) 36))) 
     67 
     68 
     69(define (oldtype:wikiname->plain wikiname) 
     70  (let1 m (#/[|](.+)/ wikiname) 
     71        (if m 
     72            (rxmatch-substring m 1) 
     73            wikiname))) 
     74 
     75(define (oldtype:wiki-macro->plain expr) 
     76  (let ((command (car expr)) 
     77        (arg  ;; symbol list to string list. 
     78         (map 
     79          (lambda (x) 
     80            (if (number? x) 
     81                (number->string x) 
     82                (symbol->string x))) 
     83          (cdr expr))) 
     84        (len (length (cdr expr)))) 
     85    (case command 
     86      ((img)        "[img] ") 
     87      ((todo)       "[TODO] ") 
     88      ((done)       "[DONE] ") 
     89      ((youtube)    "[YouTube] ") 
     90      ((thumb) 
     91       (if (< 0 len) 
     92           (let1 _url (car arg) 
     93                 (string-append "[Thumb " _url "] ")) 
     94           "!!Error : No argument ##(thumb URL) command")) 
     95      ((amazon) 
     96       (if (< 0 len) 
     97           (let* ((_asin (car arg)) 
     98                  (_asin (if (#/^[0-9]+$/ _asin) 
     99                             (format "~10,,,'0@a" _asin) 
     100                             _asin))) 
     101             (if (#/^[0-9a-zA-Z]+$/ _asin) 
     102                 (format "[Amazon ~a] " _asin) 
     103                 (format "!!Error : ASIN code format error for ##(amazon asin) command \"~a\"!!" _asin))) 
     104           "!!Error : No argument ##(amazon URL) command")) 
     105      ;; timestamp 
     106      ((timestamp)   "[timestamp] ") 
     107      ;; since 
     108      ((since)       "[since] ") 
     109      ;; download link oldtype-mode.el source code 
     110      ((download-el) "[Download oldtype-mode.el now]") 
     111      (else 
     112       (format "!!Error : no such macro \"~a\"!!" command))))) 
     113 
     114 
     115(define (oldtype:oldtype-page->plain-text sxmls) 
     116  (let rec 
     117      ((sxmls sxmls)) 
     118    (match sxmls 
     119           (()  '()) 
     120           (((and (name . _) sxml) . rest) ;; generic node 
     121            (let1 arg (cdr sxml) 
     122                  (cons 
     123                   (case name 
     124                     ((div) 
     125                      (let* ((param (car arg)) ;; param is assoc-list 
     126                             (lineno (assq-ref param 'lineno))) 
     127                        (rec (cdr arg)))) 
     128                     ((a) 
     129                      (let1 param (car arg) ;; param is assoc-list 
     130                            (rec (cdr arg)))) 
     131                     ((p-normal)    (rec arg)) 
     132                     ((pre-quote)   (rec arg)) 
     133                     ((pre-verb)    (rec arg)) 
     134                     ((pre-ul1)     (cons "- "     (rec arg))) 
     135                     ((pre-ul2)     (cons "-- "    (rec arg))) 
     136                     ((pre-ul3)     (cons "--- "   (rec arg))) 
     137                     ((pre-ol1)     (cons "# "     (rec arg))) 
     138                     ((pre-ol2)     (cons "## "    (rec arg))) 
     139                     ((pre-ol3)     (cons "### "   (rec arg))) 
     140                     ((h1)          (cons "[] "    (rec (cdr arg)))) 
     141                     ((h2)          (cons "* "     (rec (cdr arg)))) 
     142                     ((h3)          (cons "** "    (rec (cdr arg)))) 
     143                     ((h4)          (cons "*** "   (rec (cdr arg)))) 
     144                     ((h5)          (cons "**** "  (rec (cdr arg)))) 
     145                     ((h6)          (cons "***** " (rec (cdr arg)))) 
     146                     ((wiki-macro)  (oldtype:wiki-macro->plain arg)) 
     147                     ((wiki-name)   (oldtype:wikiname->plain (car arg))) 
     148                     ((hr)          (list "----\n")) 
     149                     (else 
     150                      (format "!!Error : no such tag \"~a\"!!" name))) 
     151                   (rec rest)))) 
     152           ((other . rest) 
     153            (cons other (rec rest)))))) 
     154 
     155 
    67156 
    68157;; utility : strips wiki markup and returns a plaintext line. 
  • lang/gauche/oldtype/trunk/Kahua/oldtype/oldtype/parse.scm

    r7811 r14228  
    181181              ((string=? "----" line)            '(hr)) 
    182182              ((string-prefix? "!" line)         `(open-single-verb . ,line)) 
    183               ((string=? "{{{" line)             '(open-verb)) 
    184               ((string=? "<<<" line)             '(open-quote)) 
    185               ((and (string=? ">>>" line) 
    186                     (memq 'blockquote ctx))      '(close-quote)) 
    187183              ((string-prefix? " " line)         `(pre . ,line)) 
    188184              ((rxmatch #/^(\*{1,}) / line)      => (cut cons 'heading <>)) 
     
    212208      (case (token-type tok) 
    213209        ((eof)  (reverse! seed)) 
    214         ((null) (block (next-token ctx) ctx seed)) 
     210        ((null) (block (next-token ctx) ctx (cons `(div (@@ (lineno ,line-no)) (p-normal "\n")) seed))) 
    215211        ((hr)   (block (next-token ctx) ctx (cons `(div (@@ (lineno ,line-no)) (hr)) seed))) 
    216212        ((open-single-verb) 
     
    243239                (pre-verb  
    244240                 ,@(expand-tab  
    245                     (string-drop (token-value tok) 1)))))) 
     241                    (string-drop (token-value tok) 1)) 
     242                 "\n")))) 
    246243 
    247244  ;; Verbatim 
     
    444441      (cond ((eof-object? line) 
    445442             (if (null? r) line (string-concatenate-reverse r))) 
    446             (verbatim 
    447              (when (string=? "}}}" line) (set! verbatim #f)) 
    448              line) 
    449             ((string-prefix? ";;" line) 
    450              (rec (getline) r)) 
    451             ((string=? "{{{" line) 
    452              (if (null? r) 
    453                (begin (set! verbatim #t) line) 
    454                (begin (ungetline line) (string-concatenate-reverse r)))) 
    455             ((string-prefix? "~" line) 
    456              (rec (getline) (cons (string-drop line 1) r))) 
    457443            (else 
    458444             (if (null? r) 
    459                (rec (getline) (cons line r)) 
    460                (begin (ungetline line) (string-concatenate-reverse r)))) 
     445                 (rec (getline) (cons line r)) 
     446                 (begin (ungetline line) (string-concatenate-reverse r)))) 
    461447            ))) 
    462448  ) 
  • lang/gauche/oldtype/trunk/src

    • Property svn:ignore
      •  

        old new  
        1212out.txt 
        1313test.log 
         14Sample1.sxml 
         15Sample1.txt 
         16Sample2.sxml 
         17Sample2.txt 
  • lang/gauche/oldtype/trunk/src/Makefile

    r13389 r14228  
    33OTSAMPLE='../edit/Test.ot' 
    44 
    5 all: log.txt  Test.ann.txt  Entry1.ann.txt  Entry2.ann.txt  
     5all: log.txt  Test.ann.txt  Entry1.ann.txt  Entry2.ann.txt 
    66        gosh -I ../Kahua/oldtype ./oldtype_to internal  ../edit/Test.ot    log.txt Test.ann.txt    > Test.sexp 
    77        gosh -I ../Kahua/oldtype ./oldtype_to internal  ../edit/Entry1.ot  log.txt Entry1.ann.txt  > Entry1.sexp 
    88        gosh -I ../Kahua/oldtype ./oldtype_to internal  ../edit/Entry2.ot  log.txt Entry2.ann.txt  > Entry2.sexp 
    9         gosh -I ../Kahua/oldtype ./oldtype_to sxml      ${OTSAMPLE} > out.sxml 
    10         gosh -I ../Kahua/oldtype ./oldtype_to plain     ${OTSAMPLE} > out.txt 
     9        gosh -I ../Kahua/oldtype ./oldtype_to sxml      ../edit/Sample1.ot > Sample1.sxml 
     10        gosh -I ../Kahua/oldtype ./oldtype_to sxml      ../edit/Sample2.ot > Sample2.sxml 
     11        gosh -I ../Kahua/oldtype ./oldtype_to plain     ../edit/Sample1.ot > Sample1.txt 
     12        gosh -I ../Kahua/oldtype ./oldtype_to plain     ../edit/Sample2.ot > Sample2.txt 
    1113 
    1214test: log.txt Test.ann.txt 
  • lang/gauche/oldtype/trunk/src/oldtype_to

    r13237 r14228  
    158158      ('plain 
    159159       (let* ( 
    160               (tree           (oldtype:format-line-plainly converted-str))) 
    161          (for-each 
    162           print 
    163           tree))) 
     160              (sxml           (oldtype-parse input-port)) 
     161              (sexp           (oldtype:oldtype-page->plain-text sxml))) 
     162         (print 
     163          (tree->string 
     164           sexp)))) 
    164165      (else 
    165166       (cerr (format "Unsupported type. [~a]" (symbol->string type)))