summary refs log tree commit diff stats
path: root/packages
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-05-09 08:45:20 +0200
committerAraq <rumpf_a@web.de>2012-05-09 08:45:20 +0200
commit338b3cc683e0277cbe82112860ed106b59871188 (patch)
treeebb3e7a748258b0bc116889f21bbda61145e56b5 /packages
parentf7e5f9a36aec47963c77d912106801bfc50890c0 (diff)
downloadNim-338b3cc683e0277cbe82112860ed106b59871188.tar.gz
implemented markdown styled code-blocks
Diffstat (limited to 'packages')
-rwxr-xr-xpackages/docutils/rst.nim37
1 files changed, 35 insertions, 2 deletions
diff --git a/packages/docutils/rst.nim b/packages/docutils/rst.nim
index fe23d6135..351aa6d12 100755
--- a/packages/docutils/rst.nim
+++ b/packages/docutils/rst.nim
@@ -696,6 +696,36 @@ proc parseUntil(p: var TRstParser, father: PRstNode, postfix: string,
       add(father, newRstNode(rnLeaf, " "))
       inc(p.idx)
     else: rstMessage(p, meExpected, postfix)
+
+proc parseMarkdownCodeblock(p: var TRstParser): PRstNode =
+  var args = newRstNode(rnDirArg)
+  if p.tok[p.idx].kind == tkWord:
+    add(args, newLeaf(p))
+    inc(p.idx)
+  else:
+    args = nil
+  var n = newRstNode(rnLeaf, "")
+  while true:
+    case p.tok[p.idx].kind
+    of tkEof:
+      rstMessage(p, meExpected, "```")
+      break
+    of tkPunct:
+      if isInlineMarkupEnd(p, "```"):
+        inc(p.idx)
+        break
+      else:
+        add(n.text, p.tok[p.idx].symbol)
+        inc(p.idx)
+    else:
+      add(n.text, p.tok[p.idx].symbol)
+      inc(p.idx)
+  var lb = newRstNode(rnLiteralBlock)
+  add(lb, n)
+  result = newRstNode(rnCodeBlock)
+  add(result, args)
+  add(result, nil)
+  add(result, lb)  
   
 proc parseInline(p: var TRstParser, father: PRstNode) = 
   case p.tok[p.idx].kind
@@ -715,7 +745,10 @@ proc parseInline(p: var TRstParser, father: PRstNode) =
       var n = newRstNode(rnEmphasis)
       parseUntil(p, n, "*", true)
       add(father, n)
-    elif isInlineMarkupStart(p, "``"): 
+    elif roSupportMarkdown in p.s.options and isInlineMarkupStart(p, "```"):
+      inc(p.idx)
+      add(father, parseMarkdownCodeblock(p))
+    elif isInlineMarkupStart(p, "``"):
       inc(p.idx)
       var n = newRstNode(rnInlineLiteral)
       parseUntil(p, n, "``", false)
@@ -744,7 +777,7 @@ proc parseInline(p: var TRstParser, father: PRstNode) =
       if n != nil:
         add(father, n)
         return
-    parseURL(p, father)
+    parseUrl(p, father)
   of tkAdornment, tkOther, tkWhite: 
     if roSupportSmilies in p.s.options:
       let n = parseSmiley(p)