rexrainbow / phaser3-rex-notes

Notes of phaser3 engine
MIT License
1.18k stars 260 forks source link

Add [id=][/id] tags to BBCode text #388

Closed dtturcotte closed 7 months ago

dtturcotte commented 9 months ago

Let's say I have text string

"[area=hello]hello[/area] [area=world]world[/area]. [area=hello]hello[/area]".

I want to remove [area=hello]hello[/area] from the string. Instead of trying to use regex to replace [area=hello]hello[/area] explicitly, it would be more helpful if there were hidden wrapper tags I could wrap each word in, such as

"[id=1][area=hello]hello[/area][/id] [id=2][area=world]world[/area][/id]. [id=3][area=hello]hello[/area][/id]".

It doesn't have to be "id" exactly, but I need wrapper tags that aren't displayed to the user, but that I can use for text manipulation in code. In the instance above, I cannot simply target [area=hello], because I need a specific instance of that "hello" substring. With [id=1], I can target anything between [id=1] and [/id] tags.

Thank you!

rexrainbow commented 9 months ago

BBCodeText has escape tag : Tags between [esc] ... [/esc] or [raw] ... [/raw] will be treated as content.

Demo

Does it meet your needs?

dtturcotte commented 8 months ago

Hi, not exactly. I need something I can uniquely identify an enclosed string with, without revealing the tag itself.

Something like [id=1] [area=x]X[/area] [area=y]Y[/area] [/id], where [id=1][/id] tags are not visible on screen. This way I can script something like find all text between[id=1] ... [/id]and add / remove it. I cannot usearea` tags for this because I have multiple area tags that belong to a single thing (thing with ID 1).

rexrainbow commented 8 months ago

Add [id=name]...[/id] tag. Do nothing, just a marker in content string. Please see this demo, line 12, 13. NPM package will upgrade at end of this month.

dtturcotte commented 8 months ago

Wait, has this always existed or did you just add it? Thanks so much!

rexrainbow commented 8 months ago

Added at latest commit. So it does not include in npm package yet.