add remove-newline-between-cjk plugin
Some checks failed
CI / Build on Racket 'stable' (BC) (push) Has been cancelled
CI / Build on Racket 'stable' (CS) (push) Has been cancelled
CI / Build on Racket 'current' (BC) (push) Has been cancelled
CI / Build on Racket 'current' (CS) (push) Has been cancelled

This commit is contained in:
Tan, Kian-ting 2025-10-08 21:07:16 +08:00
parent 5b17332500
commit b9403f2858

View file

@ -49,12 +49,32 @@
(define two-newlines-into-par (make-hash `(["lang" . "all"] ; for all languages (define two-newlines-into-par (make-hash `(["lang" . "all"] ; for all languages
["body" . ,two-newlines-into-par-aux]))) ["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! (define-syntax append-plugin!
(syntax-rules () (syntax-rules ()
[(_ ls plugin) (set! ls (reverse (cons plugin (reverse ls))))])) [(_ ls plugin) (set! ls (reverse (cons plugin (reverse ls))))]))
[append-plugin! plugin-list two-newlines-into-par] [append-plugin! plugin-list two-newlines-into-par]
[append-plugin! plugin-list remove-newline-between-cjk]
(define (main-text txt) (define (main-text txt)
(begin (begin