diff --git a/minorg.nim b/minorg.nim index d2c8893..856b7bc 100644 --- a/minorg.nim +++ b/minorg.nim @@ -7,8 +7,7 @@ import std/strformat import std/tables import std/paths -import nim_pandoc/pd_block_h -import nim_pandoc/pd_block +import nim_pandoc import src/utils import src/file_utils import src/pd2norg diff --git a/minorg.nimble b/minorg.nimble index 9075395..8963011 100644 --- a/minorg.nimble +++ b/minorg.nimble @@ -11,6 +11,6 @@ bin = @["minorg"] # Dependencies requires "nim >= 2.0.0" -requires "nim_pandoc >= 3.0.5" +requires "nim_pandoc >= 4.0.0" requires "cligen >= 1.6.16" requires "regex >= 0.23.0" diff --git a/nimble.lock b/nimble.lock index 0645222..bdf847e 100644 --- a/nimble.lock +++ b/nimble.lock @@ -2,13 +2,13 @@ "version": 2, "packages": { "nim_pandoc": { - "version": "3.0.5", - "vcsRevision": "e0c7f2c89ffaa596aee0d08bc7fb61e16e585c2d", + "version": "4.0.0", + "vcsRevision": "7141a75172427c0fbc319272a5a091b6d872dea1", "url": "https://github.com/pysan3/nim_pandoc", "downloadMethod": "git", "dependencies": [], "checksums": { - "sha1": "e72c1140fda593d85014c098e32bcdaadb9d8b90" + "sha1": "b761cc1f00175b2a29d352467e9f62c893f69a06" } }, "unicodedb": { diff --git a/src/pd2norg.nim b/src/pd2norg.nim index fa94409..1e68b84 100644 --- a/src/pd2norg.nim +++ b/src/pd2norg.nim @@ -9,19 +9,7 @@ import std/paths import std/enumerate import regex -import nim_pandoc/pd_attr_h -import nim_pandoc/pd_inline_h -import nim_pandoc/pd_caption_h -import nim_pandoc/pd_citation_h -import nim_pandoc/pd_format_h -import nim_pandoc/pd_list_h -import nim_pandoc/pd_table_h -import nim_pandoc/pd_target_h -import nim_pandoc/pd_types_h -import nim_pandoc/pd_block_h -import nim_pandoc/pd_caption_h -import nim_pandoc/pd_inline -import nim_pandoc/pd_block +import nim_pandoc import str_utils import log_utils @@ -68,11 +56,11 @@ func chainReplace*(s: string, replaces: openArray[ReplacePair]): auto = func escapeSpaces*(s: string): auto = s.replace(" ", "\\ ") -func lstrip*(s: string): auto = - s.strip(leading = true, trailing = false) +func lstrip*(s: string, chars: set[char] = Whitespace): auto = + s.strip(leading = true, trailing = false, chars = chars) -func rstrip*(s: string): auto = - s.strip(leading = false, trailing = true) +func rstrip*(s: string, chars: set[char] = Whitespace): auto = + s.strip(leading = false, trailing = true, chars = chars) func iterEnum*[T](arr: openArray[T]): seq[(int, T)] = for (i, e) in enumerate(arr): @@ -97,7 +85,7 @@ proc attachAttr*(s: string, attr: PDAttr, global: bool = true): string = let tagChar = if global: "#" else: "+" result = s if attr.identifier.len() > 0: - defer: result = &"{tagChar}id {attr.identifier}\n" & result.lstrip() + defer: result = &"\n{tagChar}id {attr.identifier}\n" & result.lstrip() if attr.classes.len() > 0: defer: result = tagChar & "class " & attr.classes.mapIt(it.strip().escapeSpaces()).join(" ") & "\n" & result.lstrip() if attr.pairs.len() > 0: @@ -138,10 +126,6 @@ proc toStr*(self: PDInlineSpace): string = unreachable(&"PDInlineSpace: {self.t=}") func linkMaybeMergeable*(tag: string, target: string): (bool, string) = - # debugEcho &"`{tag=}`" - # debugEcho &"`{target=}`" - # defer: - # debugEcho &"`{result=}`" if target.len() == 0: return (true, &"# {tag}") var noDashes = target.replace('-', ' ') @@ -195,7 +179,7 @@ proc toStr*(self: PDInlineLink): string = proc toStr*(self: PDInlineCode): string = let (attr, text) = self.c - attachAttr(&"`{text}`", attr) + &"`{text}`" proc toStr*(self: PDInlineEmph): string = let symbol = symbols[self.t] @@ -211,21 +195,22 @@ proc parseHTML*(s: string): string = "u": "Underline", "!-- null modifier --": "NullModifier", }.toTable() - var matches: RegexMatch2 - if s.match(re2"", matches) and html2symbols.hasKey(s[matches.group(0)]): - return symbols[html2symbols[s[matches.group(0)]]] + var m: RegexMatch2 + if s.len() == 0: + return s + elif s.find(re2"^.*", m): + let startFrom = m.boundaries.b + 1 + if startFrom >= s.len(): + return "" + else: + return s.substr(startFrom).parseHTML() + elif s.match(re2"", m) and html2symbols.hasKey(s[m.group(0)]): + return symbols[html2symbols[s[m.group(0)]]] elif s.startsWith("