Bloodcinder
Well-known member
Let's say I want to create something similar to a custom BbCode that uses a different kind of syntax, specifically not based on bracketed tags, in order to markup post text. Note that this question is not about how to do BbCode callbacks. I know how to do those.
Suppose I want to devise markup whose syntax is a set of curly braces with an optional opening symbol, a phrase, a colon, and then a number.
And I want it to be parsed and display in the post (technically cached as with a normal BbCode) as follows where the symbol or absence thereof selects a predefined color.
Note that I already have a set of existing custom BbCodes on my forum that works that way (which is where I got the screenshot), but it requires a more cumbersome tag-based BbCode syntax. Also note that this question is not about how to design a regular expression to match the markup. I know how to do those.
Given that I'm not using the standard [tag] and [/tag] BbCode syntax with square brackets, what's the appropriate strategy to use here for arbitrary regex replacement? Is there a way to use a standard BbCode callback that somehow uses a different syntax, or do I need to use a different replacement technique?
It looks to me like the BbCode parser script is hard-coded to use square brackets, so I'm guessing I have to work outside that system. A reasonable solution would be something that converts the shorter custom syntax into the corresponding preexisting BbCodes at post/edit time, so that the BbCode system can handle the rest. Future edits to the post would show the BbCodes instead of the shorter codes, so this would not be ideal.
TL/DR: Suppose I want to run an arbitrary regex replacement in a post similar in almost every way to a BbCode except with a custom non-bracketed syntax. What's the right way?
Suppose I want to devise markup whose syntax is a set of curly braces with an optional opening symbol, a phrase, a colon, and then a number.
Code:
The arrow struck its target {+Attack Roll:20} but barely missed the vitals {!Critical Threat:6} {Damage:4}.
And I want it to be parsed and display in the post (technically cached as with a normal BbCode) as follows where the symbol or absence thereof selects a predefined color.
Note that I already have a set of existing custom BbCodes on my forum that works that way (which is where I got the screenshot), but it requires a more cumbersome tag-based BbCode syntax. Also note that this question is not about how to design a regular expression to match the markup. I know how to do those.
Given that I'm not using the standard [tag] and [/tag] BbCode syntax with square brackets, what's the appropriate strategy to use here for arbitrary regex replacement? Is there a way to use a standard BbCode callback that somehow uses a different syntax, or do I need to use a different replacement technique?
It looks to me like the BbCode parser script is hard-coded to use square brackets, so I'm guessing I have to work outside that system. A reasonable solution would be something that converts the shorter custom syntax into the corresponding preexisting BbCodes at post/edit time, so that the BbCode system can handle the rest. Future edits to the post would show the BbCodes instead of the shorter codes, so this would not be ideal.
TL/DR: Suppose I want to run an arbitrary regex replacement in a post similar in almost every way to a BbCode except with a custom non-bracketed syntax. What's the right way?
Last edited: