How to transform HTML nodes to tiddler's tree?

63 views
Skip to first unread message

bimlas

unread,
Aug 16, 2018, 6:27:04 PM8/16/18
to TiddlyWikiDev
I'm working on a parser plugin to render Asciidoctor formated text.

The plugin is using Asciidoctor.js (https://github.com/asciidoctor/asciidoctor.js) and basically works, but the content of the tiddler is the HTML code itself instead of the correctly rendered text. For example if I creating a new tiddler with the content

  *bold* _italic_

then it's transforming to

  <div class="paragraph"> <p><strong>bold</strong> <em>italic</em></p> </div>

when I save the tiddler. (screenshot: https://i.imgur.com/aHtHneJ.png)

As I looked in to the Markdown parser plugin, it seems that the Markdown.js returns a HTML tree (thanks to JsonML). I assume my plugin should do the same, but there is no option for this in Asciidoctor.js. How can I achieve this? Is there a builtin method to transform HTML nodes to HTML tree or should I use JsonML?

To try out:

* Clone https://github.com/bimlas/tiddlyWiki5/ and check out `asciidoctor-plugin` branch, or simply download https://github.com/bimlas/TiddlyWiki5/archive/asciidoctor-plugin.zip
* Run `bin/serve.sh editions/full`
* Press the second Markdown icon in the right panel (move the mouse over it, the tooltip should be related to Asciidoctor)
* Write `*bold* _italic_` in it and save the tiddler

Jeremy Ruston

unread,
Aug 17, 2018, 12:25:34 PM8/17/18
to tiddly...@googlegroups.com
Hi Bimlas

I'm working on a parser plugin to render Asciidoctor formated text.

Great!

The plugin is using Asciidoctor.js (https://github.com/asciidoctor/asciidoctor.js) and basically works, but the content of the tiddler is the HTML code itself instead of the correctly rendered text. For example if I creating a new tiddler with the content

  *bold* _italic_

then it's transforming to

  <div class="paragraph"> <p><strong>bold</strong> <em>italic</em></p> </div>

when I save the tiddler. (screenshot: https://i.imgur.com/aHtHneJ.png)

As I looked in to the Markdown parser plugin, it seems that the Markdown.js returns a HTML tree (thanks to JsonML). I assume my plugin should do the same, but there is no option for this in Asciidoctor.js. How can I achieve this? Is there a builtin method to transform HTML nodes to HTML tree or should I use JsonML?

Your parser can return raw HTML by returning an object like this:

{type: "raw", html: <string>}

The downside of returning raw HTML is that it makes it harder to support features like native TW links.

Best wishes

Jeremy


To try out:

* Clone https://github.com/bimlas/tiddlyWiki5/ and check out `asciidoctor-plugin` branch, or simply download https://github.com/bimlas/TiddlyWiki5/archive/asciidoctor-plugin.zip
* Run `bin/serve.sh editions/full`
* Press the second Markdown icon in the right panel (move the mouse over it, the tooltip should be related to Asciidoctor)
* Write `*bold* _italic_` in it and save the tiddler


--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/e223b36a-353e-43c2-aaef-72b72de34d92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bimlas

unread,
Aug 18, 2018, 4:34:18 PM8/18/18
to TiddlyWikiDev
Thanks for the advice. I just found a way to transform HTML to node tree (?), now the plugin works nicely (screenshot: https://i.imgur.com/VMyePPW.png). I'll have to do some makeup, but basically everything seems to be OK. How should I do a pull request: using the plugins/tiddlywiki/asciidoctor is right or should I move under my own "namespace" (plugins/bimlas/asciidoctor)? Should I keep on my own repo without sending a PR, will you merge by yourself if you like the plugin?
Reply all
Reply to author
Forward
0 new messages