Short version:
The wikitext syntax and the parser contain some inconsistencies, because there are some main goals, which "rule them all"
- Prose text should be without any "formatting markers"
- Wikitext should be human readable, even if _not_ rendered
- Formatting markers should be unintrusive
- eg: ''bold'' //italic// ...
Those main goals cause a lot of "missing" information for computers. ... Our "super computer" (the brain) on the other hand can still make sense of it, because of sheer calculation power (not speed ;).
In comparison, most datacenters are still stupid.
... There is some hope!
Longer version ;)
On Saturday, November 23, 2019 at 7:53:18 PM UTC+1, TiddlyTweeter wrote:
The problem is that the rule is NOT consistent. Works ... & does not
This works, since tw tries to "be nice"
I personally would consider a heading starter !! without 2 new-lines at the end to be a syntax error. But that's only my point of view and there would be many complains, if we would enforce it.
TW is able to detect a heading with a !! start and 1 new-line at the end... since we don't allow multi-line headings.
If we would allow them, the above code wouldn't work.
---------------------------
You are comparing apples with pears here.
The above would need to be as follows to compare the same tings.
This text starts a paragraph
!! This text should start a heading - but it doesn't since the paragraph isn't finished yet.
The same rule is applied to the text below.
The text with 1 new-line indicates a paragraph start. So the TW-parser searches for the end of the paragraph. -> 2 new-lines
Since 2 new-lines are found after the "heading" it includes the "heading text" into the paragraph.
So the heading isn't detected. Same thing is true for your second example.
But this does not ...
Not Working
<<<
Not working
<<<
There are some more inconsistencies in the wikitext creation, which are "caused" by - how the TW parser works. It's a regexp based parser, which is optimized for speed and "code simplicity".
If you write plain wikitext, the content should be human readable, even without rendering. So if users get some "raw text" snippets, they should be able to make sense of the text.
... But this fact, also makes "format detection" harder for programmers, because wikitext should not be "polluted" with markers. So some times we have to "guess" ... which may be wrong.
Basically, there is a "start sequence" and an "end sequence" defined. Some rules start a "block mode" like <<< ..
If a block mode is active, the "content" between start and end is wikified again. This allows us to detect eg: "!! heading" within a blockquote. and so on ...
As long as "block mode" is active other blocks can be "nested".
But as soon as the parser internal state is "inline mode" it only detects formatting like eg: ''bold'' ... That's the reason, why the
transclusion-widget and some others, have a
mode parameter:
block / inline. Which tells the parser, what it should do, because "guessing" may cause the wrong decision.
I hope that makes sense.
have fun!
mario