diff options
| author | kj_sh604 | 2026-02-19 21:16:23 -0500 |
|---|---|---|
| committer | kj_sh604 | 2026-02-19 21:16:23 -0500 |
| commit | d15e968e3d884e2df5b301cd54654c76c808150b (patch) | |
| tree | 080d946949e3229aaa32ea428d36fc42d6576474 /src | |
| parent | 545935816dcb70adf35acf347ce06f593d05a137 (diff) | |
refactor: go ASCII only mode for now
Diffstat (limited to '')
| -rw-r--r-- | src/app.nim | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/app.nim b/src/app.nim index 930e592..80c0502 100644 --- a/src/app.nim +++ b/src/app.nim @@ -233,13 +233,23 @@ proc runPandoc(sourceMarkdown: string; outputPath: string; paperSize: string; ma let tempDir = getTempDir() / (AppName & "-" & randomHex(10)) createDir(tempDir) let tempMarkdownPath = tempDir / "source.md" + let tempRawPath = tempDir / "raw.md" try: - writeFile(tempMarkdownPath, sourceMarkdown) + # write raw markdown first + writeFile(tempRawPath, sourceMarkdown) + + # preprocess markdown: convert to ascii with transliteration and normalize quotes + let iconvCmd = "iconv -c -t ASCII//TRANSLIT " & quoteShell(tempRawPath) & " | sed 's/'\\''/'/g; s/\"\"/\"/g' > " & quoteShell(tempMarkdownPath) + let (iconvOutput, iconvExitCode) = execCmdEx(iconvCmd) + + if iconvExitCode != 0: + # if preprocessing fails, fall back to original content + writeFile(tempMarkdownPath, sourceMarkdown) let args = @[ tempMarkdownPath, - "--from", "markdown+emoji", + "--from", "markdown+emoji+hard_line_breaks", "--pdf-engine=lualatex", "--template", latexTemplatePath(), "-V", "papersize=" & paperSize, @@ -264,6 +274,8 @@ proc runPandoc(sourceMarkdown: string; outputPath: string; paperSize: string; ma return (ok: false, output: output, missingPandoc: false) finally: try: + if fileExists(tempRawPath): + removeFile(tempRawPath) if fileExists(tempMarkdownPath): removeFile(tempMarkdownPath) if dirExists(tempDir): |
