patorjk / Extendible-BBCode-Parser

Allows you to parse BBCode and to extend the markup to add your own tags. All major tags are supported and parser reports back any errors it finds.
http://patorjk.com/bbcode-previewer/
MIT License
133 stars 54 forks source link

Single element tags #22

Open alizahid opened 5 years ago

alizahid commented 5 years ago

Tags like [br] or [hr] or even ones that have attributes like [tag=value] or [tag=value attribute=value]. Are these not supported?

EricSTremblay commented 4 years ago

Same for me, this is weird with [br] user has to write [br][/br] to avoid a xbbcode error.

jshaffstall commented 3 years ago

For what it's worth to future folks looking for standalone tag support, I did some pre-processing of the input to automatically add closing tags for any tags I knew were standalone tags. It's not as nice as native support, but for the size of bbcode I'm processing, it worked fine.

I used the following regular expression to process all the standalone tags that are not in [code] blocks:

RegExp('\[code\].\[\/code\]|\[('+'|'.join(tag_list)+')([ =][^\]]?)?\]', 'gmi')

And this code for processing those:

  if tagName:
    return matchStr+"[/" + tagName + "]"

  return matchStr

This is in a platform where most of the code is Python, but you can convert that to Javascript if needed.

Merulast commented 1 year ago

I simply looked for each tags key without an closing function, and made an simple replaceAll for each of them right after ret.html = parse(config was done.