mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-01 19:44:44 +00:00
docs: make inline markup more compatible with Markdown (#18053)
fixes https://github.com/timotheecour/Nim/issues/739
This commit is contained in:
@@ -23,7 +23,7 @@ import std/private/miscdollars
|
||||
import os
|
||||
|
||||
proc toAst(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.
|
||||
@@ -36,10 +36,11 @@ proc toAst(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
|
||||
@@ -54,8 +55,9 @@ proc toAst(input: string,
|
||||
var rst = rstParse(input, filen, line=LineRstInit, column=ColRstInit,
|
||||
dummyHasToc, rstOptions, myFindFile, testMsgHandler)
|
||||
result = renderRstToStr(rst)
|
||||
except EParseError:
|
||||
discard
|
||||
except EParseError as e:
|
||||
if e.msg != "":
|
||||
result = e.msg
|
||||
|
||||
suite "RST parsing":
|
||||
test "option list has priority over definition list":
|
||||
@@ -326,6 +328,28 @@ suite "RST escaping":
|
||||
""")
|
||||
|
||||
suite "RST inline markup":
|
||||
test "* and ** surrounded by spaces are not inline markup":
|
||||
check("a * b * c ** d ** e".toAst == dedent"""
|
||||
rnInner
|
||||
rnLeaf 'a'
|
||||
rnLeaf ' '
|
||||
rnLeaf '*'
|
||||
rnLeaf ' '
|
||||
rnLeaf 'b'
|
||||
rnLeaf ' '
|
||||
rnLeaf '*'
|
||||
rnLeaf ' '
|
||||
rnLeaf 'c'
|
||||
rnLeaf ' '
|
||||
rnLeaf '**'
|
||||
rnLeaf ' '
|
||||
rnLeaf 'd'
|
||||
rnLeaf ' '
|
||||
rnLeaf '**'
|
||||
rnLeaf ' '
|
||||
rnLeaf 'e'
|
||||
""")
|
||||
|
||||
test "end-string has repeating symbols":
|
||||
check("*emphasis content****".toAst == dedent"""
|
||||
rnEmphasis
|
||||
@@ -420,6 +444,37 @@ suite "RST inline markup":
|
||||
rnLeaf 'proc `+`'
|
||||
""")
|
||||
|
||||
check("""`\\`""".toAst ==
|
||||
dedent"""
|
||||
rnInlineCode
|
||||
rnDirArg
|
||||
rnLeaf 'nim'
|
||||
[nil]
|
||||
rnLiteralBlock
|
||||
rnLeaf '\\'
|
||||
""")
|
||||
|
||||
test "Markdown-style code/backtick":
|
||||
# no whitespace is required before `
|
||||
check("`try`...`except`".toAst ==
|
||||
dedent"""
|
||||
rnInner
|
||||
rnInlineCode
|
||||
rnDirArg
|
||||
rnLeaf 'nim'
|
||||
[nil]
|
||||
rnLiteralBlock
|
||||
rnLeaf 'try'
|
||||
rnLeaf '...'
|
||||
rnInlineCode
|
||||
rnDirArg
|
||||
rnLeaf 'nim'
|
||||
[nil]
|
||||
rnLiteralBlock
|
||||
rnLeaf 'except'
|
||||
""")
|
||||
|
||||
|
||||
test """inline literals can contain \ anywhere""":
|
||||
check("""``\``""".toAst == dedent"""
|
||||
rnInlineLiteral
|
||||
|
||||
@@ -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>"
|
||||
|
||||
Reference in New Issue
Block a user