TiddlyWiki / TiddlyWiki5

A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.
https://tiddlywiki.com/
Other
8.07k stars 1.19k forks source link

[IDEA] Officially reserve WikiText delimiters for '(= formula =)' and '{% external template %}' #8139

Closed PotOfCoffee2Go closed 3 months ago

PotOfCoffee2Go commented 7 months ago

The 'mushroom' (= =) delimiters is used by the formula-plugin

The 'curly percent' {% %} delimiters allow delimiter based 3rd party parser and template engines to inject custom content into tiddlers.

Do not believe any code changes would be required.

joshuafontany commented 7 months ago

Would love to get Formulas another pass and into the parser more directly..... Hooks?

Jermolene commented 7 months ago

Hi @PotOfCoffee2Go I think this is a good idea.

I think all we would need to do is add some tests that attempt to parse various combinations of these character sequences, and verifies that it only gets back a single text node. Something like:

{% something %}
(= something =)
Prefix-{%
Prefix-(=
  {%
  (=
etc.
PotOfCoffee2Go commented 4 months ago

I think all we would need to do is add some tests that attempt to parse various combinations of these character sequences

I dug around in the tests but have not been able to get my head wrapped around where in the test to start. This would be a good project for me as would provide a gateway into figuring out how all the tests are organized.

In which 'test' .js would I begin to add the tests?

Jermolene commented 4 months ago

Hi @PotOfCoffee2Go there are two different types of testcases in TiddlyWiki:

WikIText tests are preferred where possible for new tests. This is because the compatibility with the testcase widget means that testcases can double as documentation examples.

For this test, we need to check that the parse tree for parsing a few simple strings such as those above, and check that the JSON representation of the parse tree is as expected.

Something like this:

title: ReservedWikiText
description: Verify that reserved wikitext constructions are not parsed
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]

title: Narrative

Verifies that certain wikitext constructions that are reserved for use by other tools are not parsed by TiddlyWiki.
+
title: TestTiddler

{% something %}
(= something =)
Prefix-{%
Prefix-(=
  {%
  (=
+
title: Output

<$wikify name="parsetree" text={{TestTiddler}} output="parsetree">
<$text text={{{ [<parsetree>jsonget[0],[children],[0],[text]] }}}/>
</$wikify>
+
title: ExpectedResult

<p>
{% something %}
(= something =)
Prefix-{%
Prefix-(=
  {%
  (=
</p>
PotOfCoffee2Go commented 4 months ago

Hi @Jermolene

Thanks for the help - I realize you basically built the test - your explanation really helped - I totally missed the 'data' directory, if had drilled down into that probably would have been able to build it. Is an impressive system.

Added combinations which would not be valid constructs - but none-the-less should still not be parsed. And they pass. Will submit a PR unless there is something else is needed.

reservedwikitext

Jermolene commented 4 months ago

Thanks @PotOfCoffee2Go that looks good, and a PR would be welcome.

PotOfCoffee2Go commented 3 months ago

Merge of PR #8384 closes this issue.