showdownjs / showdown

A bidirectional Markdown to HTML to Markdown converter written in Javascript
http://www.showdownjs.com/
MIT License
14.26k stars 1.56k forks source link

Expose blockTags in subParser 'hashHTMLBlock' #871

Open TheBorgel opened 2 years ago

TheBorgel commented 2 years ago

I am trying to force showdown to ignore my custom HTML tags for my text editor. The block tags is a list of tags that will be ignored during parsing, and adding my custom tag names to this list achieves the desired result: i.e. the text inside the tags are not parsed.

For now I achieved my desired result by adding a div tag around my custom tags like so:

type: 'lang',
regex: /<TagName(.*?)<\/TagName>/gs,
replace: '<div><TagName$1<\/TagName></div>'
tivie commented 2 years ago

In a way, the innards of hashHTMLBlock subparser is already exposed.

You can hook to the event makehtml.hashHTMLBlocks.before with a listener extension and replicate the functionality of the HashHTMLBlock parser yourself.

TheBorgel commented 2 years ago

True, but I would say that the extra effort for the user and the untidy end result is a bit unnecessary.

Would there not be a fairly common use case for being able to add or remove tags from the list to let the user customize the parser in a clean way?