Simplest way to suppress paragraph <p> at the start of a block when writing an extension
I am trying to write a Link extension which will pull in content from an external file. I've based my code on the ext-media-tags extension so far.
My use-case is ultimately to be able to write markdown something like this:
!§[image gallery](/assets/gallery/gallery.html)
Which would pull in all the HTML from the specified file and render it as-is. But right now it is always wrapped in <p>, breaking the layout.
What I think I need to be writing is a Block extension, as I want to surpress the default creation of the wrapping <p>...</p> tags.
Is it possible to combine a Block and a Link extension?
Is there a simple way of writing a CustomBlockProcessor to surpress the creation of the <p>...</p> tags? I've got very lost trying to understand the block processors in the ext-aside and ext-definition examples, as they are doing a lot more than I think I need.
I'm currently using Flexmark 0.42.0.
@v79, you should use a custom block parser instead of a link extension. Link extension creates inline elements. Suppressing <p> tags is not a solution for your use case because link extension will allow inserting these elements in text.
The parsing consists of phases. Blocks are parsed first, afterwards the block content is parsed for inline elements. There is no way to combine the two operations. However, a custom block can eliminate inline parsing if it does not contain inline elements, for example fenced code, html blocks, etc.
It seems what you are trying to accomplish is not a link extension but an include function. You are using it for image gallery but the functionality will insert any content therefore you should think of at it as generic include.
You should probably look at the flexmark-ext-jekyll-tag extension which has include tag which will include arbitrary content.
Thank you. After I wrote the link extension I had the feeling I had gone down the wrong path. I will take a look at ext-jekyll.
Closing as ext-jekyll provided the template for the solution.