mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 14:25:23 +00:00
Add rstgen.rstToLatex convenience proc for renderRstToOut and initRstGenerator with outLatex output, see https://github.com/nim-lang/fusion/pull/11#issuecomment-641804899 (#14629)
This commit is contained in:
@@ -29,6 +29,7 @@ import strutils, os, hashes, strtabs, rstast, rst, highlite, tables, sequtils,
|
||||
algorithm, parseutils
|
||||
import "$lib/../compiler/nimpaths"
|
||||
import "$lib/../compiler/pathutils"
|
||||
import ../../std/private/since
|
||||
|
||||
const
|
||||
HtmlExt = "html"
|
||||
@@ -1344,6 +1345,16 @@ proc rstToHtml*(s: string, options: RstParseOptions,
|
||||
renderRstToOut(d, rst, result)
|
||||
|
||||
|
||||
proc rstToLatex*(rstSource: string; options: RstParseOptions): string {.inline, since: (1, 3).} =
|
||||
## Convenience proc for `renderRstToOut` and `initRstGenerator`.
|
||||
runnableExamples: doAssert rstToLatex("*Hello* **world**", {}) == """\emph{Hello} \textbf{world}"""
|
||||
if rstSource.len == 0: return
|
||||
var option: bool
|
||||
var rstGenera: RstGenerator
|
||||
rstGenera.initRstGenerator(outLatex, defaultConfig(), "input", options)
|
||||
rstGenera.renderRstToOut(rstParse(rstSource, "", 1, 1, option, options), result)
|
||||
|
||||
|
||||
when isMainModule:
|
||||
assert rstToHtml("*Hello* **world**!", {},
|
||||
newStringTable(modeStyleInsensitive)) ==
|
||||
|
||||
Reference in New Issue
Block a user