VIP
- Joined
- Apr 23, 2018
- Messages
- 1,071
Wrote this to help me diagnose the issue. While it would be sort of nice to have it fixed (tbh, even I don't expect this feature, though I do utilize implicit closing for other tags), this was mostly just to help me understand the process so I could reproduce it in my post preview userscript (link near the bottom of my MD profile).
Img (and url) tags are implicitly closed on EOF regardless of their validity or of any nesting they had. I expect
1) Them to be closed with their parent like other tags (when nested)
2) Them to be invalidated (not considered to be bbcode, but normal text) when they do not conform to the html generator's specifications (eg. html generator rejects empty tags, but whatever is implicitly closing img tags doesn't)
Seems like processing of bbcode occurs in multiple stages. Whatever step does implicit closing of img/url tags probably just needs a regex that matches the html generation stage better.
Also curious why only img/url fails with implicit closing, is it handled separately from some bbcode package, or is it a small typo in a custom grammar?
While looking at actual code would be ideal, my outside analysis leads me to believe the html generator step looks for urls in a format similar to:
Code:
\[img\][a-zA-Z0-9\-]+://\S*\.\S*(<CLOSING_TAG_FOR_THIS_OR_ANY_PARENT_CONTEXT>|\s*$)
Making the following valid
EOF (with or without trailing whitespace):
Code:
[[s][/s]img]-://.
Code:
[ul[s][/s]][[s][/s]img]-://.[[s][/s]/ul]
Space:
Code:
[ul[s][/s]][[s][/s]img]-://. [[s][/s]/ul]
Code:
[[s][/s]img]-://.
a
Code:
[[s][/s]img]
Alternatively, white space itself could implicitly close it. Though the regex(I am assuming) change is still kind of needed...
Also, while Implicit closing of tags makes sense, it is kind of odd that it is done in a textual manner, rather than in an ast. Though I guess that really depends on what your using to parse and generate it.
Example:
Nested with space invalidation (this is what I actualy typed below):
Code:
[ul[s][/s]][img[s][/s]]https://mangadex.org/images/avatars/36341.png [/ul[s][/s]]