51 lines
1.3 KiB
GDScript
51 lines
1.3 KiB
GDScript
extends XMLParser
|
|
class_name HTMLParser
|
|
|
|
func get_cssclass(cssclass):
|
|
while read() == 0:
|
|
if get_named_attribute_value_safe("class").split(" ",false).has(cssclass):
|
|
print_debug("found class ",cssclass," at ",get_node_offset())
|
|
break
|
|
|
|
|
|
func get_cssid(cssid) -> bool:
|
|
var loop = true
|
|
while read() == 0:
|
|
if get_named_attribute_value_safe("id") == cssid:
|
|
loop = false
|
|
return true
|
|
return false
|
|
|
|
|
|
func get_html_element(element:String):
|
|
while read() == 0:
|
|
if get_node_type() == NODE_ELEMENT and get_node_name() == element:
|
|
return true
|
|
return false
|
|
|
|
|
|
func read_inner_text():
|
|
var desc = ""
|
|
var nname = get_node_name()
|
|
while read() == 0:
|
|
if (get_node_type() == NODE_ELEMENT_END and get_node_name() == nname):
|
|
break
|
|
elif get_node_type() == NODE_TEXT:
|
|
desc += get_node_data()
|
|
return desc.dedent()
|
|
|
|
|
|
func read_inner_text_bbcode() -> String:
|
|
var desc = ""
|
|
var nname = get_node_name()
|
|
while not (get_node_type() == NODE_ELEMENT_END and get_node_name() == nname):
|
|
read()
|
|
if get_node_type() == NODE_TEXT:
|
|
desc += get_node_data().replace(" ","")
|
|
elif get_node_name() == "br":
|
|
desc += "\n"
|
|
elif get_node_name() == "a" and get_node_type() == NODE_ELEMENT:
|
|
desc += "[url="+get_named_attribute_value_safe("href")+"]"
|
|
elif get_node_name() == "a" and get_node_type() == NODE_ELEMENT_END:
|
|
desc += "[/url]"
|
|
return desc.dedent()
|