diff --git a/lib/packages/docutils/rst.nim b/lib/packages/docutils/rst.nim
index 6e4e3f5dd..26222d951 100644
--- a/lib/packages/docutils/rst.nim
+++ b/lib/packages/docutils/rst.nim
@@ -115,8 +115,8 @@ const
type
TokType = enum
tkEof, tkIndent, tkWhite, tkWord, tkAdornment, tkPunct, tkOther
- Token = object # a RST token
- kind*: TokType # the type of the token
+ Token = object # a RST token
+ kind*: TokType # the type of the token
ival*: int # the indentation or parsed integer value
symbol*: string # the parsed symbol as string
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)
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 =
var pos = start
# 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
of '\x0D', '\x0A':
getIndent(L, tok)
- of '!', '\"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.',
- '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{',
- '|', '}', '~':
+ of '!', '\"', '#', '$', '%', '&', '\'', '*', '+', ',', '-', '.',
+ '/', ':', ';', '<', '=', '>', '?', '@', '\\', '^', '_', '`',
+ '|', '~':
getAdornment(L, tok)
if len(tok.symbol) <= 3: tok.kind = tkPunct
+ of '(', ')', '[', ']', '{', '}':
+ getBracket(L, tok)
else:
tok.line = L.line
tok.col = L.col
@@ -837,7 +847,8 @@ proc parseInline(p: var RstParser, father: PRstNode) =
var n = newRstNode(rnSubstitutionReferences)
parseUntil(p, n, "|", false)
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):
discard "parseMarkdownLink already processed it"
else:
diff --git a/tests/stdlib/trstgen.nim b/tests/stdlib/trstgen.nim
index fd89f68af..8fdbf3911 100644
--- a/tests/stdlib/trstgen.nim
+++ b/tests/stdlib/trstgen.nim
@@ -5,6 +5,7 @@ outputsub: ""
# tests for rstgen module.
import ../../lib/packages/docutils/rstgen
+import ../../lib/packages/docutils/rst
import unittest
suite "YAML syntax highlighting":
@@ -141,3 +142,14 @@ suite "YAML syntax highlighting":
-4
example.com/not/a#comment:
?not a map key"""
+
+
+ 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 == """(( Nim ))"""
+ assert b == """((Nim))"""
+ assert c == """[Nim]"""