diff options
author | bptato <nincsnevem662@gmail.com> | 2024-08-30 00:06:27 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-08-30 00:12:23 +0200 |
commit | 209210fe06be1c77da5c2fd0e2e17cfb4397a50b (patch) | |
tree | 7af9777a5c66c721b2c8c8ec010835fcc4b09c9c /adapter/format | |
parent | b721c669670bfbf95672780bf473dc418c2d32be (diff) | |
download | chawan-209210fe06be1c77da5c2fd0e2e17cfb4397a50b.tar.gz |
md2html: support blockquote
+ update todo, readme
Diffstat (limited to 'adapter/format')
-rw-r--r-- | adapter/format/gmi2html.nim | 4 | ||||
-rw-r--r-- | adapter/format/md2html.nim | 34 |
2 files changed, 28 insertions, 10 deletions
diff --git a/adapter/format/gmi2html.nim b/adapter/format/gmi2html.nim index ee3c06bd..9dde28f1 100644 --- a/adapter/format/gmi2html.nim +++ b/adapter/format/gmi2html.nim @@ -23,7 +23,7 @@ a, pre, ul, blockquote, li, h1, h2, h3 { margin-top: 0; margin-bottom: 0 } while not stdin.endOfFile: let line = stdin.readLine() if inpre and not line.startsWith("```"): - stdout.write(line.htmlEscape() & "\n") + stdout.write(line.htmlEscape() & '\n') continue if inul and not line.startsWith("* "): stdout.write("</ul>") @@ -64,6 +64,6 @@ a, pre, ul, blockquote, li, h1, h2, h3 { margin-top: 0; margin-bottom: 0 } stdout.write(line.substr(1).htmlEscape()) stdout.write("</blockquote>") else: - stdout.write(line.htmlEscape() & "\n") + stdout.write(line.htmlEscape() & '\n') main() diff --git a/adapter/format/md2html.nim b/adapter/format/md2html.nim index 5d06acc5..3428d34c 100644 --- a/adapter/format/md2html.nim +++ b/adapter/format/md2html.nim @@ -275,8 +275,8 @@ proc matchHTMLPreEnd(line: string): bool = type BlockType = enum - btNone, btPar, btList, btPre, btTabPre, btSpacePre, btHTML, btHTMLPre, - btComment + btNone, btPar, btList, btPre, btTabPre, btSpacePre, btBlockquote, btHTML, + btHTMLPre, btComment ParseState = object blockType: BlockType @@ -312,26 +312,33 @@ proc parseNone(state: var ParseState; line: string) = elif line.startsWith("```"): state.blockType = btPre stdout.write("<PRE>") + elif line[0] == '\t': + state.blockType = btTabPre + if state.hasp: + state.hasp = false + stdout.write("</P>\n") + stdout.write("<PRE>") + state.blockData = line.substr(1) & '\n' elif line.startsWith(" "): state.blockType = btSpacePre if state.hasp: state.hasp = false stdout.write("</P>\n") stdout.write("<PRE>") - state.blockData = line.substr(4) & "\n" - elif line.startsWith("\t"): - state.blockType = btTabPre + state.blockData = line.substr(4) & '\n' + elif line[0] == '>': + state.blockType = btBlockquote if state.hasp: state.hasp = false stdout.write("</P>\n") - stdout.write("<PRE>") - state.blockData = line.substr(1) & "\n" + state.blockData = line.substr(1) & "<BR>" + stdout.write("<BLOCKQUOTE>") elif (let (n, len, t) = line.getListDepth(); n != -1): state.blockType = btList state.listDepth = n state.hasp = false state.pushList(t) - state.blockData = line.substr(len + 1) & "\n" + state.blockData = line.substr(len + 1) & '\n' else: state.blockType = btPar state.hasp = true @@ -444,6 +451,16 @@ proc parseSpacePre(state: var ParseState; line: string) = dec state.numPreLines state.blockData &= line.substr(4) & "\n" +proc parseBlockquote(state: var ParseState; line: string) = + if line.len == 0 or line[0] != '>': + stdout.write(state.blockData) + stdout.write("</BLOCKQUOTE>") + state.blockData = "" + state.reprocess = true + state.blockType = btNone + else: + state.blockData &= line.substr(1) & "<BR>" + proc parseComment(state: var ParseState; line: string) = let i = line.find("-->") if i != -1: @@ -463,6 +480,7 @@ proc main() = of btPre: state.parsePre(line) of btTabPre: state.parseTabPre(line) of btSpacePre: state.parseSpacePre(line) + of btBlockquote: state.parseBlockquote(line) of btList: state.parseList(line) of btPar: state.parsePar(line) of btHTML: state.parseHTML(line) |