From 0636cbf55a48e06b40a91bbcae460ef71122c48f Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 10 Jun 2020 16:46:39 -0300 Subject: [PATCH] Add rstgen.rstToLatex convenience proc for renderRstToOut and initRstGenerator with outLatex output, see https://github.com/nim-lang/fusion/pull/11#issuecomment-641804899 --- changelog.md | 2 ++ lib/packages/docutils/rstgen.nim | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/changelog.md b/changelog.md index e86e42b339c61..623b3f6bcf29e 100644 --- a/changelog.md +++ b/changelog.md @@ -111,6 +111,8 @@ - new module `std/jsonutils` with hookable `jsonTo,toJson,fromJson` for json serialization/deserialization of custom types. - new proc `heapqueue.find[T](heap: HeapQueue[T], x: T): int` to get index of element ``x``. +- Add `rstgen.rstToLatex` convenience proc for `renderRstToOut` and `initRstGenerator` with `outLatex` output. + ## Language changes - In the newruntime it is now allowed to assign discriminator field without restrictions as long as case object doesn't have custom destructor. Discriminator value doesn't have to be a constant either. If you have custom destructor for case object and you do want to freely assign discriminator fields, it is recommended to refactor object into 2 objects like this: diff --git a/lib/packages/docutils/rstgen.nim b/lib/packages/docutils/rstgen.nim index 6a7b33cc05ea8..2ec25cc6e4e19 100644 --- a/lib/packages/docutils/rstgen.nim +++ b/lib/packages/docutils/rstgen.nim @@ -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)) ==