parent
2608bc369e
commit
1494d88fa2
2 changed files with 29 additions and 6 deletions
|
|
@ -115,8 +115,8 @@ const
|
||||||
type
|
type
|
||||||
TokType = enum
|
TokType = enum
|
||||||
tkEof, tkIndent, tkWhite, tkWord, tkAdornment, tkPunct, tkOther
|
tkEof, tkIndent, tkWhite, tkWord, tkAdornment, tkPunct, tkOther
|
||||||
Token = object # a RST token
|
Token = object # a RST token
|
||||||
kind*: TokType # the type of the token
|
kind*: TokType # the type of the token
|
||||||
ival*: int # the indentation or parsed integer value
|
ival*: int # the indentation or parsed integer value
|
||||||
symbol*: string # the parsed symbol as string
|
symbol*: string # the parsed symbol as string
|
||||||
line*, col*: int # line and column of the token
|
line*, col*: int # line and column of the token
|
||||||
|
|
@ -153,6 +153,14 @@ proc getAdornment(L: var Lexer, tok: var Token) =
|
||||||
inc(L.col, pos - L.bufpos)
|
inc(L.col, pos - L.bufpos)
|
||||||
L.bufpos = pos
|
L.bufpos = pos
|
||||||
|
|
||||||
|
proc getBracket(L: var Lexer, tok: var Token) =
|
||||||
|
tok.kind = tkPunct
|
||||||
|
tok.line = L.line
|
||||||
|
tok.col = L.col
|
||||||
|
add(tok.symbol, L.buf[L.bufpos])
|
||||||
|
inc L.col
|
||||||
|
inc L.bufpos
|
||||||
|
|
||||||
proc getIndentAux(L: var Lexer, start: int): int =
|
proc getIndentAux(L: var Lexer, start: int): int =
|
||||||
var pos = start
|
var pos = start
|
||||||
# skip the newline (but include it in the token!)
|
# skip the newline (but include it in the token!)
|
||||||
|
|
@ -205,11 +213,13 @@ proc rawGetTok(L: var Lexer, tok: var Token) =
|
||||||
rawGetTok(L, tok) # ignore spaces before \n
|
rawGetTok(L, tok) # ignore spaces before \n
|
||||||
of '\x0D', '\x0A':
|
of '\x0D', '\x0A':
|
||||||
getIndent(L, tok)
|
getIndent(L, tok)
|
||||||
of '!', '\"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.',
|
of '!', '\"', '#', '$', '%', '&', '\'', '*', '+', ',', '-', '.',
|
||||||
'/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{',
|
'/', ':', ';', '<', '=', '>', '?', '@', '\\', '^', '_', '`',
|
||||||
'|', '}', '~':
|
'|', '~':
|
||||||
getAdornment(L, tok)
|
getAdornment(L, tok)
|
||||||
if len(tok.symbol) <= 3: tok.kind = tkPunct
|
if len(tok.symbol) <= 3: tok.kind = tkPunct
|
||||||
|
of '(', ')', '[', ']', '{', '}':
|
||||||
|
getBracket(L, tok)
|
||||||
else:
|
else:
|
||||||
tok.line = L.line
|
tok.line = L.line
|
||||||
tok.col = L.col
|
tok.col = L.col
|
||||||
|
|
@ -837,7 +847,8 @@ proc parseInline(p: var RstParser, father: PRstNode) =
|
||||||
var n = newRstNode(rnSubstitutionReferences)
|
var n = newRstNode(rnSubstitutionReferences)
|
||||||
parseUntil(p, n, "|", false)
|
parseUntil(p, n, "|", false)
|
||||||
add(father, n)
|
add(father, n)
|
||||||
elif roSupportMarkdown in p.s.options and p.tok[p.idx].symbol == "[" and
|
elif roSupportMarkdown in p.s.options and
|
||||||
|
p.tok[p.idx].symbol == "[" and p.tok[p.idx+1].symbol != "[" and
|
||||||
parseMarkdownLink(p, father):
|
parseMarkdownLink(p, father):
|
||||||
discard "parseMarkdownLink already processed it"
|
discard "parseMarkdownLink already processed it"
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ outputsub: ""
|
||||||
# tests for rstgen module.
|
# tests for rstgen module.
|
||||||
|
|
||||||
import ../../lib/packages/docutils/rstgen
|
import ../../lib/packages/docutils/rstgen
|
||||||
|
import ../../lib/packages/docutils/rst
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
suite "YAML syntax highlighting":
|
suite "YAML syntax highlighting":
|
||||||
|
|
@ -141,3 +142,14 @@ suite "YAML syntax highlighting":
|
||||||
<span class="DecNumber">-4</span>
|
<span class="DecNumber">-4</span>
|
||||||
<span class="StringLit">example.com/not/a#comment</span><span class="Punctuation">:</span>
|
<span class="StringLit">example.com/not/a#comment</span><span class="Punctuation">:</span>
|
||||||
<span class="StringLit">?not a map key</span></pre>"""
|
<span class="StringLit">?not a map key</span></pre>"""
|
||||||
|
|
||||||
|
|
||||||
|
test "Markdown links":
|
||||||
|
let
|
||||||
|
a = rstToHtml("(( [Nim](https://nim-lang.org/) ))", {roSupportMarkdown}, defaultConfig())
|
||||||
|
b = rstToHtml("(([Nim](https://nim-lang.org/)))", {roSupportMarkdown}, defaultConfig())
|
||||||
|
c = rstToHtml("[[Nim](https://nim-lang.org/)]", {roSupportMarkdown}, defaultConfig())
|
||||||
|
|
||||||
|
assert a == """(( <a class="reference external" href="https://nim-lang.org/">Nim</a> ))"""
|
||||||
|
assert b == """((<a class="reference external" href="https://nim-lang.org/">Nim</a>))"""
|
||||||
|
assert c == """[<a class="reference external" href="https://nim-lang.org/">Nim</a>]"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue