-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a function to erase BBCode from a String, without depending on RichTextLabel #5056
Comments
It should likely strip every |
If the purpose is to strip all bbcode tags then this should do the trick: func strip_bbcode(source:String) -> String:
var regex = RegEx.new()
regex.compile("\\[.+?\\]")
return regex.sub(source, "", true) But I'm not sure I'm following, what do you mean with custom tags? You can use For example: extends Node
func _ready():
var message = "[url={'meta':'json}]JSON[/url] [randomtag a=30 b='hello' c=true]something[/randomtag] My name is [name] and I'm [age] years old"
var stripped_tags = strip_bbcode(message)
print(stripped_tags) # JSON something My name is and I'm years old
var formatted_string = message.format({"name": "John Doe", "age": "30"}, "[_]")
print(formatted_string) # [url={'meta':'json}]JSON[/url] [randomtag a=30 b='hello' c=true]something[/randomtag] My name is John Doe and I'm 30 years old
var formatted_and_stripped = strip_bbcode(formatted_string)
print(formatted_and_stripped) # JSON something My name is John Doe and I'm 30 years old
func strip_bbcode(source:String) -> String:
var regex = RegEx.new()
regex.compile("\\[.+?\\]")
return regex.sub(source, "", true) |
Just ran into this issue myself, the code above does work but a clean built in function to handle it would be nice. |
Actually, there is a way to escape BBCode. Maybe we should add |
Describe the project you are working on
Dialogue boxes with custom tags
Describe the problem or limitation you are having in your project
In order to work properly with custom tags in a String, one needs to remove the BBCode from it first. The only ways to remove BBCode from a String are either giving it to a RichTextLabel and getting its
text
property (which may be slow if you're intending to reassign it right after), or writing a whole new function just to do the work, which is not an easy task.Considering how removing BBCode is done in a certain way by Godot, there should be an easy way to do it without depending on those previous cases.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
String has many built-in functions that somehow modify it.
One function that should be there should be to remove BBCode.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Some function like
String.erase_bbcode()
If this enhancement will not be used often, can it be worked around with a few lines of script?
Yes, but it's something that could just be exposed as a function.
I believe this would be used more often than half of the built-in
String
functions.The workarounds have already been explained above.
Is there a reason why this should be core and not an add-on in the asset library?
It's intended to work directly on a String, therefore an addon would add some unnecessary code when it could be a simple function.
The text was updated successfully, but these errors were encountered: