diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-07-03 14:10:06 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-07-03 14:10:06 +0200 |
commit | dab9bee4b46aaa1241cdb6b565ddbe0f19137c5e (patch) | |
tree | 7a5b22717797a08c8165bc2346f1204d90f74f31 /api/japanese.ts | |
parent | 14c31de2f166d9e6d874984cdee5a2876c1ddec5 (diff) |
add utility wrap method
Diffstat (limited to 'api/japanese.ts')
-rw-r--r-- | api/japanese.ts | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/api/japanese.ts b/api/japanese.ts index 9319cdd..ffbc773 100644 --- a/api/japanese.ts +++ b/api/japanese.ts @@ -3,20 +3,23 @@ import { escape } from "https://deno.land/std@0.192.0/html/entities.ts"; import "../util/string.ts"; import "../util/japanese.ts"; import "../util/array.ts"; +import { Wrap } from "../util/wrap.ts"; const formatters = { "HTML": tokens => tokens.reduce((out, token) => { - if (token.ruby) out += `<ruby>${escape(token.writing)}<rt>${escape(token.reading)}</rt></ruby>`; - else out += token.writing; + if (token.ruby) { + out += (escape(token.writing) + + escape(token.reading).wrap(Wrap.HTML.rubyText)).wrap(Wrap.HTML.ruby); + } else out += token.writing; return out; }, ""), "parenthesis": tokens => tokens.reduce((out, token) => { - if (token.ruby) out += `${token.writing}(${token.reading}) `; + if (token.ruby) out += token.writing + token.reading.wrap(Wrap.parenthesis) + " "; else out += token.writing; return out; }, ""), "refold-tools": tokens => tokens.reduce((out, token) => { - if (token.ruby) out += `[${token.writing}](${token.reading})`; + if (token.ruby) out += token.writing.wrap(Wrap.bracket) + token.reading.wrap(Wrap.parenthesis); else out += token.writing; return out; }, ""), |