Changing the Rendering of Html?

55 views
Skip to first unread message

A X.

unread,
Oct 6, 2017, 10:09:46 PM10/6/17
to tiddly...@googlegroups.com
I think I posted it in the wrong section:

I want to change the way h? tags are rendered. Logic: If H? tag, then add element after.  Do I have to write a widget or is there a much more simple way to do this?

Possible place: $:/core/modules/widgets/element.js

BJ

unread,
Oct 7, 2017, 5:02:21 AM10/7/17
to TiddlyWikiDev
I don't know of any rules about where to post question

I think that question involving overriding core functionality provided by javascript can be answered here.

Firstly do you wish the extra markup to be applied globally, that is including the tiddlywiki UI or just to some tiddlers?

There are a number of ways of achiving this,

1) prepass the wikitext and add in the extra markup
2) override the parser rules
3) the parser produces a AST, apply changes to the AST before the rendering
4) override the element widget.

I feel that 3 is the least hacky approch.

if you want non-global effect then 1 is simplest as the solution already exits.

If you want global effect 4 is the easiest

I would Monkey patch the tw5 parser (global effect) option 3:

The parses are loaded in the startup module $:/core/modules/startup/load-modules.js
by calling $tw.wiki.initParsers() which populates the array $tw.Wiki.parsers[].

the parser refrenced by $tw.Wiki.parsers["text/vnd.tddlywiki"] needs to be replaced with the new parser.
This is best achieved by including an extra startup module that runs after $:/core/modules/startup/load-modules.js
with the simple code to replace this item in the array.

you can see an example of changing the AST in the markdown plugin: $:/plugins/tiddlywiki/markdown/wrapper.js, you
can follow this pattern to produce the new parser.

all the best

BJ
Reply all
Reply to author
Forward
0 new messages