Bug in building a single-file HTML using CLI

51 views
Skip to first unread message

oleghbond

unread,
Jan 10, 2020, 3:22:32 AM1/10/20
to TiddlyWiki
It has almost for sure been established that the TW5 command `rendertiddler` (as well as `render`) generates non-empty content `undefined` in a single-file HTML wiki for `_canonical_uri` tiddlers. (The story is decribed there https://groups.google.com/d/msg/tiddlywiki/s-NO4zkwVwM/Kjc4VruBBwAJ)

For instance, now the HTML-code of a tiddler `my-image.png` looks like:

 <div _canonical_uri="./images/my-image.png" title="my-image.png" type="image/png" revision="0" bag="default">
 
<pre>undefined</pre>
 
</div>

Whereas earlier (at least a couple of weeks ago) it looked like:

 <div _canonical_uri="./images/my-image.png" title="my-image.png" type="image/png" revision="0" bag="default">
 
<pre></pre>
 
</div>

As a result the TW does not reveal the image correctly - it looks like a broken link image.

In order to solve this issue I was forced to temporarily apply the following js-patch (for removing the unwanted token `undefined`):

 let search_token = new RegExp("(<div[^>]+_canonical_uri[^>]+>[\\s\\r\\n]*<pre>)([^<>]+)(</pre>[\\s\\r\\n]*</div>)","gim");
 let replace_token
= "$1$3";
 let s_html_code
= fs.readFileSync(html_index_file,'utf8');
 let s_html_code_patched
= s_html_code.replace(search_token, replace_token);
 fs
.writeFileSync(html_index_file, s_html_code_patched);

The Node.js version used is 5.1.21, OS - Windows 10.

The command-line script used for building a single-file HTML wiki is as follows:

 xcopy /s/i/q %TW_DIR%\*.* %TMP_DIR%

 tiddlywiki
%TMP_DIR% --savetiddlers %IMG_FILTER% %HTML_IMAGES_DIR%
 tiddlywiki
%TMP_DIR% --setfield %IMG_FILTER% _canonical_uri "$:/core/templates/canonical-uri-external-image" text/plain
 tiddlywiki
%TMP_DIR% --setfield %IMG_FILTER% text "" text/plain
 tiddlywiki
%TMP_DIR% --rendertiddler $:/plugins/tiddlywiki/tiddlyweb/save/offline %HTML_INDEX_FILE% text/plain

The newest version of the rendering command gives the similar effect:

 tiddlywiki %TMP_DIR% --render [all[]] %HTML_INDEX_FILE% text/plain $:/core/templates/alltiddlers.template.html

My conclusion - that is a bug. 

I'd be grateful to the TW community for solving this issue.

Sincerely, Olegh

Jeremy Ruston

unread,
Jan 10, 2020, 3:27:51 AM1/10/20
to tiddl...@googlegroups.com
Hi Oleg


The command-line script used for building a single-file HTML wiki is as follows:

 xcopy /s/i/q %TW_DIR%\*.* %TMP_DIR%

 tiddlywiki
%TMP_DIR% --savetiddlers %IMG_FILTER% %HTML_IMAGES_DIR%
 tiddlywiki
%TMP_DIR% --setfield %IMG_FILTER% _canonical_uri "$:/core/templates/canonical-uri-external-image" text/plain
 tiddlywiki
%TMP_DIR% --setfield %IMG_FILTER% text "" text/plain
 tiddlywiki
%TMP_DIR% --rendertiddler $:/plugins/tiddlywiki/tiddlyweb/save/offline %HTML_INDEX_FILE% text/plain


Each of those commands depends on the output of the previous one, so things don't work if you run the commands separately, they need to be run together into a single instantiation of TiddlyWiki:

 tiddlywiki %TMP_DIR% --savetiddlers %IMG_FILTER% %HTML_IMAGES_DIR% --setfield %IMG_FILTER% _canonical_uri "$:/core/templates/canonical-uri-external-image" text/plain --setfield %IMG_FILTER% text "" text/plain --rendertiddler $:/plugins/tiddlywiki/tiddlyweb/save/offline %HTML_INDEX_FILE% text/plain

Best wishes

Jeremy

oleghbond

unread,
Jan 11, 2020, 4:42:08 AM1/11/20
to TiddlyWiki
Thanks Jeremy, I checked - it works.

The issue has been closed.

пʼятниця, 10 січня 2020 р. 10:27:51 UTC+2 користувач Jeremy Ruston написав:
Reply all
Reply to author
Forward
0 new messages