How to view tiddlers with unknown type as pre-formatted code

107 views
Skip to first unread message

bimlas

unread,
Oct 19, 2020, 4:27:45 AM10/19/20
to TiddlyWiki
When you open a Javascript or CSS tiddler, it displays it as pre-formatted code. If my research is accurate, this behavior is determined by the transclude widget, but I couldn’t investigate the condition.

How can it be solved that e.g. display Markdown tiddlers (type: text/x-markdown) as code (so I don't have to install the Markdown plugin and still make my notes easy to read)?

bimlas

unread,
Oct 19, 2020, 4:35:09 AM10/19/20
to TiddlyWiki
To make the question more accurate: my goal is to keep tiddlers of different formats distinguishable by type type (Markdown, Asciidoc, reStructuredText, LaTeX, etc.), but if that type is unknown to TiddlyWiki, then I can view them as I do in a text editor.

Eric Shulman

unread,
Oct 19, 2020, 5:15:51 AM10/19/20
to tiddl...@googlegroups.com
On Monday, October 19, 2020 at 1:35:09 AM UTC-7, bimlas wrote:
To make the question more accurate: my goal is to keep tiddlers of different formats distinguishable by type type (Markdown, Asciidoc, reStructuredText, LaTeX, etc.), but if that type is unknown to TiddlyWiki, then I can view them as I do in a text editor.

Create a tiddler "ShowUnknownTiddlerTypeAsText", tagged with $:/tags/ViewTemplate, containing:
\define hidebody() <style> [data-tiddler-title="$(currentTiddler)$"] .tc-tiddler-body { display:none; } </style>

<$list filter="[<currentTiddler>get[type]addprefix[$:/language/Docs/Types/]!is[shadow]!is[tiddler]]" variable="unknown_type">
   <<hidebody>><pre><$text text={{!!text}}/
></pre>
</$list>

Notes:
1) The hidebody() macro uses CSS to suppress the display of the tiddler body for the current tiddler
2) $list checks to see if a non-blank type field in the current tiddler is unknown to the system (i.e., doesn't have a corresponding $:/language/Docs/Types/... definition as either a shadow or regular system tiddler)

-e

Saq Imtiaz

unread,
Oct 19, 2020, 5:19:09 AM10/19/20
to TiddlyWiki
Hi Bimlas,

From what I recall this behaviour is determined by the appropriate parser for the tiddler type. See wiki.parseText which defaults to vnd.tiddlywiki for unknown types.

For CSS/JavaScript the text parser is used which wraps everything in a codeblock.
See: core/modules/parsers/textparser.js

Unknown tiddler types I believe are handled as text/vnd.tiddlywiki, so you would need to change that default for unknown types. Alternatively you could pre-define all the types you might need to use the text parser.

Hope this helps.
Saq

bimlas

unread,
Oct 19, 2020, 7:13:12 AM10/19/20
to TiddlyWiki
Thank you for your answers!

Although I don't like to overwrite Javascript tiddlers, Saq's solution is perfect for me.

Because syntax highlighting also works thanks to the Highlight.js plugin, it is good to display text files as code.

bimlas

unread,
Oct 19, 2020, 7:32:06 AM10/19/20
to TiddlyWiki
Note for other users: if syntax highlighting doesn't work, set the appropriate types in the Highlight.js plugin! From the documentation:

You can also specify the language as a MIME content type (eg text/html or text/css). The mapping is accomplished via mapping tiddlers whose titles start with $:/config/HighlightPlugin/TypeMappings/.

TW Tones

unread,
Oct 19, 2020, 9:14:32 PM10/19/20
to TiddlyWiki
Bimlas,

Forgive my ignorance, but I have rarely if ever seen any syntax highlighting anywhere, in css etc... as well as surprised we do not have a highlighter for wikitext and widgets.

I just installed the core plugin but still cant see anything. A little Guidance would be appreciated.

FYI joshuas JSON mangler also includes CSV as a valid type, but when I drop an Excel generated CSV it gains another type. 

Regards
Tones

bimlas

unread,
Oct 20, 2020, 1:32:00 AM10/20/20
to TiddlyWiki
TW Tones,

Forgive my ignorance, but I have rarely if ever seen any syntax highlighting anywhere, in css etc...
Or am I misunderstood and you mean edit mode? In this case, Codemirror and the corresponding Codemirror "add-ons" (CodeMirror Mode CSS for example) must be installed. Besides, I don't know of any other syntax highlighting method.

we do not have a highlighter for wikitext and widgets.

That's right. I'm using the following Codemirror "extension", which gives a very nice syntax highlight in edit mode:

Reply all
Reply to author
Forward
0 new messages