I would like to allow only paragraphs and lists.
Actually i want to use the input to create a document in Open Document format. So I replace the tag <p> with the correct tag in ODF. But first, I’m trying to learn how to transform the markdown format into something I can use.
I could use the output of MarkdownPHP and replace tags in html to ODF tags, however i want to use only the paragraphs and lists. The Markdown generates much more than i need. If i miss any html tag the ODF document will break because it don’t understand html tags.
I believe it is possible to use a simple RegExp. But I don’t know how!
example:
My first line.
* My first item.
* My second item.
More text...
output:
<p>My first line.</p>
<ul>
<li>My first item.</li>
<li>My second item.</li>
</ul>
<p>More text...</p>
You can use the
strip_tags()function to remove all tags other than the ones you want. Their contents will remain, but the tags themselves will be removed.Try this:
From there, you can just use
str_replace()to change the remaining tags into their ODF counterparts. (If the tag format isn’t consistent coming out of your Markdown parser, then you can just usepreg_replace()to handle the differences depending on the specific output).