add remove-newline-between-cjk plugin
This commit is contained in:
parent
5b17332500
commit
b9403f2858
1 changed files with 20 additions and 0 deletions
20
expander.rkt
20
expander.rkt
|
@ -49,12 +49,32 @@
|
|||
(define two-newlines-into-par (make-hash `(["lang" . "all"] ; for all languages
|
||||
["body" . ,two-newlines-into-par-aux])))
|
||||
|
||||
(define [is-cjk-matched? char]
|
||||
(define cjk-range #rx"[\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF\U00020000-\U0002EBEF\u3000-\u303F,。!.?()—:;]")
|
||||
(regexp-match? cjk-range char)
|
||||
)
|
||||
|
||||
(define [remove-newline-between-cjk-aux cont]
|
||||
(display (list-ref cont 1))
|
||||
(define (sexp-processing res remain)
|
||||
[cond
|
||||
[(eq? remain '()) (reverse res)]
|
||||
[(and(equal? (car remain) "\n") (is-cjk-matched? (car res)) (= (length remain) 1) (sexp-processing(cons (car remain) res) [cdr remain]))]
|
||||
[(and(equal? (car remain) "\n") (is-cjk-matched? (car res)) (is-cjk-matched? (cadr remain)))
|
||||
(sexp-processing (cons (cadr remain) res) [cddr remain])]
|
||||
[else (sexp-processing(cons (car remain) res) [cdr remain])]])
|
||||
(list-set cont 1 (sexp-processing '() (list-ref cont 1))))
|
||||
|
||||
(define remove-newline-between-cjk (make-hash `(["lang" . "zh"]
|
||||
["body" . ,remove-newline-between-cjk-aux])))
|
||||
|
||||
|
||||
(define-syntax append-plugin!
|
||||
(syntax-rules ()
|
||||
[(_ ls plugin) (set! ls (reverse (cons plugin (reverse ls))))]))
|
||||
|
||||
[append-plugin! plugin-list two-newlines-into-par]
|
||||
[append-plugin! plugin-list remove-newline-between-cjk]
|
||||
|
||||
(define (main-text txt)
|
||||
(begin
|
||||
|
|
Loading…
Reference in a new issue