General > General Technical Chat
Escaping left and right brackets in forum posts
(1/1)
ledtester:
Just sharing a method I learned to "escape" left and right square brackets in BBcode (the markup language used here on the forum) - that is, to insert BBcode tags into your post without having them interpreted as tags.
Most of the time you can use the [code] tag, e.g.:
--- Quote ---To insert a link use the url tag, for example:
--- Code: ---[url=https://cnn.com]This is CNN[/url]
--- End code ---
will produce the link: This is CNN
--- End quote ---
But what if you want to show how to use the [code] tag? Using:
--- Quote ---[code]
To format code in a post, use a [code] ... [/code] block.
[/code]
--- End quote ---
doesn't work because code blocks do not nest - the first end code tag will terminate the outer code block.
Or what if you want the tags to appear inline, e.g.
--- Quote ---using [s]some text[/s] will make "some text" appear with a line through it, e.g. some text
--- End quote ---
The trick is to use a style tag to break-up the tag you want to insert literally, e.g. to insert [TAG] use:
--- Code: ---[color=black][TAG[/color][color=black]][/color]
--- End code ---
Besides the [color] tag other style tags will also work for this purpose, e.g. [b], [i], [u], [s], [tt], [font], [size]. Of course, whatever style tag you use will affect the enclosed text.
magic:
Interesting question.
Not sure if there is any "official" solution, but I came up with a simpler version of your hack:
--- Code: ---[[b][/b]code]
--- End code ---
[code]
tooki:
--- Quote from: magic on May 23, 2024, 03:44:55 pm ---Interesting question.
Not sure if there is any "official" solution, but I came up with a simpler version of your hack:
--- Code: ---[[b][/b]code]
--- End code ---
[code]
--- End quote ---
Yep. I also use this exact trick to break up unwanted smileys, like 8) (which otherwise becomes 8) — this has to be the most poorly thought-out smiley shortcut ever conceived).
Brumby:
Yeah, I've used this trick for years, usually with the colour - but you don't have to do it to the trailing bracket
[color=black][TAG[/color]] = [TAG]
tom66:
You can also use similar characters, though they won't copy-and-paste correctly.
For instance, this is an example using с (Cyrillic 'Es'), which is not c (Latin 'c').
[сode]Testing[/сode]
This has security implications for creating similar-appearing text that has different binary signatures, think web URLs. Imagine: paypal.com vs рayрal.com. These are different, but only in Unicode land. Thankfully, there are steps taken to reduce the chance of this being a practical attack in the real world.
Navigation
[0] Message Index
Go to full version