TiddlyWiki / TiddlyWiki5

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

[BUG] Filtered transclusion that is, much later, followed by curly brace #7701

Open twMat opened 1 year ago

twMat commented 1 year ago

Describe the bug

Typing in the following on tiddlywiki.com or any other TW

{{{ [[any filter]] }}} 

this string disappeas and the succeeding curly brace becomes wikified, or maybe it is a brace from the filtered transclusion above

}

...outputs this:

image

If the last brace is removed, the output seems correct.

To my surprise I get the faulty behavious regardless of TW version. (How has this possibly passed????)

I discovered it in a more subtle context, with a totally natural and syntactically correct succeeding brace:

{{{ [[any filter]] }}} 

disappears

<style>
.foo { color:red }
</style>

output

image

TiddlyWiki Configuration

Tested on both Chrome and FF

and on TW latest and several older versions

pmario commented 1 year ago

That's interesting. IMO we'll need to do some experiments. I do not know, where it comes from atm. But it seems to be a bug

twMat commented 1 year ago

For a solution, my spontaneous thought is to require that the triple braces are directly next to one another without any characters in between.

I think the following image shows that when the filtered transclusion is a block (example 2) then first } just to the right of xxx is treated as content inside the filtered transclusion. But in the third case below, when inline, the filtered trans works as expected and the very last } is treated as outside.

image
CodaCodr commented 1 year ago

In my testing, it seems a space at the end of the first line after the transclusion "invites" all the problems that follow

image

Note the space end of first line.

Output:

image

Remove the space...

image

Output:

image

twMat commented 1 year ago

@CodaCodr this also causes fautly output tho, IMO:

{{{ [[any filter]] }}
xxx
}
pmario commented 1 year ago

I think there is something wrong with the parser regexp. I'll have a closer look when I have time.

pmario commented 10 months ago

According to the core js code "Filtered Transclusions" should work like this:

Wiki text rule for block-level filtered transclusion. For example:

{{{ [tag[docs]] }}}
{{{ [tag[docs]] |tooltip}}}
{{{ [tag[docs]] ||TemplateTitle}}}
{{{ [tag[docs]] |tooltip||TemplateTitle}}}
{{{ [tag[docs]] }}width:40;height:50;}.class.class

The title: $:/core/modules/parsers/wikiparser/rules/filteredtranscludeblock.js regexp is as follows:

https://github.com/Jermolene/TiddlyWiki5/blob/c185e373c5f269baac0d88b33896f59b509c6864/core/modules/parsers/wikiparser/rules/filteredtranscludeblock.js#L29

There are 2 test for filtered transclusions that only cover the first possibility.

https://github.com/Jermolene/TiddlyWiki5/blob/c185e373c5f269baac0d88b33896f59b509c6864/editions/test/tiddlers/tests/test-wikitext-parser.js#L194-L205

and it seems to have a problem in "caption group 1" already, because match[1] is [[any filter]] } -- See the trailing } which should not be there.

more tests will follow

pmario commented 10 months ago

PR is on the way.

pmario commented 10 months ago

PR is on the way.

I have been to enthusiastic. :/

@Jermolene ... The problem is caused by the trailing whitespace character after the closing braces }}} in the OP. Any other "trailing" character has the same effect. eg: {{{ [[any filter]] }}}a

The reason is, that with a trailing character the last 2 braces }} and the following text match group 4 -- The first closing brace } will be added to match group 1


From a pragmatic point of view a trailing character makes the whole text block an inline filtered transclusion. .. BUT since the block-rule creates some valid matches it does not switch to the inline parser.

I do have some ideas, but all of them are only partial solutions.

pmario commented 10 months ago

@Jermolene -- This one is ready for review now.

pmario commented 9 months ago

related to: [Bug] Pipe characters ruin triple brace evaluation #4462