summaryrefslogtreecommitdiff
path: root/commonmark.rb
diff options
context:
space:
mode:
Diffstat (limited to 'commonmark.rb')
-rwxr-xr-xcommonmark.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/commonmark.rb b/commonmark.rb
index dca7a3c..b41b8fe 100755
--- a/commonmark.rb
+++ b/commonmark.rb
@@ -335,10 +335,22 @@ class HtmlRenderer < Renderer
end
doc = Node.parse_file(ARGF)
+
+# Walk tree and print URLs for links
doc.walk do |node|
if node.type == :link
printf("URL = %s\n", node.url)
- printf("parent is %s\n", node.parent.type)
+ end
+end
+
+# Walk tree and transform links to regular text
+doc.walk do |node|
+ if node.type == :link
+ parent = node.parent
+ index = parent.children.index(node)
+ len = parent.children.length
+ parent.children.replace(parent.children.slice(0,index) + node.children +
+ parent.children.slice(index + 1, len))
end
end