docs: make inline markup more compatible with Markdown (#18053)

fixes https://github.com/timotheecour/Nim/issues/739
This commit is contained in:
Andrey Makarov 2021-05-21 07:54:20 +03:00 • committed by GitHub
commit 9f7e2e3057
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 168 additions and 62 deletions

View file

@ -10,7 +10,7 @@ import unittest, strutils, strtabs
import std/private/miscdollars
proc toHtml(input: string,
rstOptions: RstParseOptions = {roSupportMarkdown, roNimFile},
rstOptions: RstParseOptions = {roPreferMarkdown, roSupportMarkdown, roNimFile},
error: ref string = nil,
warnings: ref seq[string] = nil): string =
## If `error` is nil then no errors should be generated.
@ -23,18 +23,20 @@ proc toHtml(input: string,
toLocation(message, filename, line, col + ColRstOffset)
message.add " $1: $2" % [$mc, a]
if mc == mcError:
doAssert error != nil, "unexpected RST error '" & message & "'"
if error == nil:
raise newException(EParseError, "[unexpected error] " & message)
error[] = message
# we check only first error because subsequent ones may be meaningless
raise newException(EParseError, message)
raise newException(EParseError, "")
else:
doAssert warnings != nil, "unexpected RST warning '" & message & "'"
warnings[].add message
try:
result = rstToHtml(input, rstOptions, defaultConfig(),
msgHandler=testMsgHandler)
except EParseError:
discard
except EParseError as e:
if e.msg != "":
result = e.msg
# inline code tags (for parsing originated from highlite.nim)
proc id(str: string): string = """<span class="Identifier">""" & str & "</span>"