When I add an OL or UL using the Writer field, it automatically adds
tags in between the
<ul>
<li><p>Listitem</p></li>
<li><p>Listitem</p></li>
</ul>
When I add an OL or UL using the Writer field, it automatically adds
tags in between the
<ul>
<li><p>Listitem</p></li>
<li><p>Listitem</p></li>
</ul>
This is a known Prosemirror issue: Bug: list items contain <p> tags in writer field · Issue #3506 · getkirby/kirby · GitHub
If you want to get rid of the p tags, you would have to filter them out at render time.
How do I do this just for a list-item?
Replace the patterns <li><p> with <li> and </p></li> with </li>
Is this one still unsolved? At least to me it’s a big issue because it brings wrong semantics.
Looks like it
It’s a feature, not a bug!
The intended behaviour for lists, in John Gruber’s original Markdown syntax:
“If list items are separated by blank lines, Markdown will wrap the items in
<p>tags in the HTML output”
— from John Gruber’s original docs (Daring Fireball: Markdown Syntax Documentation)
So, to prevent unwanted <p> tags, you just need to avoid blank lines between list items in your markup.
As far as I know this behaviour is adhered-to in Commonmark, GitHub-flavoured Markdown, ProseMirror (used I think in Kirby’s Writer field), and Parsedown (used in Kirby’s original Markdown field). The latter responds to a single blank line in the list markup, but ProseMirror seems to require a blank line between every list item.
I accidentally discovered this feature months after first using Markdown, and it still seems surprisingly little known, or used. But it’s a terrific feature that enables us to target lists in Markdown with two completely separate stylings.
I’ve written enthusiastically about this in my personal blog at: A sample post with everything in it, at brianliddell.com , including examples of how it can be used.
I hope this answers your question, and that I’ve not made any mistakes!
So, to prevent unwanted
<p>tags, you just need to avoid blank lines between list items in your markup.
Well, that’s not the behaviour I see in the Writer field/Prosemirror. <p> tags are added inside each and every <li> even when no blank lines are added. You can test this with a single list item.
Meanwhile this field method does the job for me:
Kirby::plugin('foxacid/unPList', [
'fieldMethods' => [
'unPList' => function ($field) {
$unP = str_replace(
['<li><p>', '</p></li>'],
['<li>', '</li>'],
$field->value
);
return $unP;
}
]
]);
This is a known issue, see link to issue above. Unless Prosemirror fixes it, there’s nothing we can do about it.
Yeah, I know. I was just replying to the post above claiming that the issue stems from blank lines..