Javascript Not Parsing Nested Bbcode

后端 未结 1 1597
清酒与你
清酒与你 2021-01-24 15:40

I have coded a Javascript bbcode similar to the one I\'m using to write this message. It also incorporates a live preview box like the one I see below. The only problem I\'m fac

相关标签:
1条回答
  • 2021-01-24 16:27

    Three solutions:

    1. Write a parser. This will produce the best solution but takes a non-trivial amount of effort.

    2. Find a BBCode parsing library. Probably as good as #1 in quality and substantially easier.

    3. Add a negative lookahead to the inside of each tag regex and continuously apply until no match. E.g.:

      \[quote\]((?:[^](?!\[quote\]))*?)\[\/quote\]
      

      This will capture the inner quote, then once its replaced, the outer one. Not nearly as clean as the other two but probably the quickest fix.

    0 讨论(0)
提交回复
热议问题