All,
I am trying to create an extension (to extend AbstractBlockParser, I believe) which will find an opening tag, move the lines following into a block, and then stop when a closing tag is found (on its own on a last line).
While looking at the examples provided, it is extremely hard to work out how they build a block composed of multiple lines, e.g. using a code fence, and the documentation does not cover this scenario.
The list parser code seems to show ListItems being added to a ListBlock, but how does it know when to stop?
Example Markdown
{{ Object ID
Any markdown goes here.
Some more
* List 1
* List 2
}}
And the output might be:
<div class="object">
<span>Object ID</span>
<p>Any markdown goes here.
Some more</p>
<ul>
<li>List 1</li>
<li>List 2</li>
</ul>
</div>
The trick is that your Block should have the
canContain()
andmatchesNextLine()
methods alwaysreturn true;
- these will ensure that subsequent lines always get added as child blocks. (Take a look at theFencedCode
andListBlock
implementations.)Here's some code which should work:
ObjectBlock.php:
ObjectParser.php:
ObjectRenderer:
Disclaimer: Although I am the author of this library, the particular logic (containers, tips, and block-closing) was mostly forked as-is from the JS version and I only understand about 75% of it - just enough to keep my fork working and figure out approaches that work :)