summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndrey Makarov <ph.makarov@gmail.com>2021-05-17 00:55:14 +0300
committerGitHub <noreply@github.com>2021-05-16 23:55:14 +0200
commit2096490b5974cfb11d0f5d37ff6d3a963ef43713 (patch)
tree6ad64aa60d8eca1f7583f076e0421385625084bb /lib
parentd83b25db1ebe7025d95dbce3978219948f5c49d3 (diff)
downloadNim-2096490b5974cfb11d0f5d37ff6d3a963ef43713.tar.gz
follow-up #17930 - inline syntax highlighting (#18013)
* follow-up #17930 - inline syntax highlighting

* make closure->nimcall
Diffstat (limited to 'lib')
-rw-r--r--lib/packages/docutils/rst.nim25
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/packages/docutils/rst.nim b/lib/packages/docutils/rst.nim
index 9cbc4efb7..da04e9b54 100644
--- a/lib/packages/docutils/rst.nim
+++ b/lib/packages/docutils/rst.nim
@@ -1151,6 +1151,18 @@ proc toOtherRole(n: PRstNode, kind: RstNodeKind, roleName: string): PRstNode =
 proc parsePostfix(p: var RstParser, n: PRstNode): PRstNode =
   var newKind = n.kind
   var newSons = n.sons
+
+  proc finalizeInterpreted(node: PRstNode, newKind: RstNodeKind,
+                           newSons: seq[PRstNode], roleName: string):
+                          PRstNode {.nimcall.} =
+    # fixes interpreted text (`x` or `y`:role:) to proper internal AST format
+    if newKind in {rnUnknownRole, rnCodeFragment}:
+      result = node.toOtherRole(newKind, roleName)
+    elif newKind == rnInlineCode:
+      result = node.toInlineCode(language=roleName)
+    else:
+      result = newRstNode(newKind, newSons)
+
   if isInlineMarkupEnd(p, "_", exact=true) or
       isInlineMarkupEnd(p, "__", exact=true):
     inc p.idx
@@ -1175,19 +1187,10 @@ proc parsePostfix(p: var RstParser, n: PRstNode): PRstNode =
     # a role:
     let (roleName, lastIdx) = getRefname(p, p.idx+1)
     newKind = whichRole(p, roleName)
-    if newKind in {rnUnknownRole, rnCodeFragment}:
-      result = n.toOtherRole(newKind, roleName)
-    elif newKind == rnInlineCode:
-      result = n.toInlineCode(language=roleName)
-    else:
-      result = newRstNode(newKind, newSons)
+    result = n.finalizeInterpreted(newKind, newSons, roleName)
     p.idx = lastIdx + 2
   else:
-    if p.s.currRoleKind == rnInlineCode:
-      result = n.toInlineCode(language=p.s.currRole)
-    else:
-      newKind = p.s.currRoleKind
-      result = newRstNode(newKind, newSons)
+    result = n.finalizeInterpreted(p.s.currRoleKind, newSons, p.s.currRole)
 
 proc matchVerbatim(p: RstParser, start: int, expr: string): int =
   result = start