group inline text tags, new tag - span

This commit is contained in:
Face
2025-07-22 21:15:57 +03:00
parent 1f73a7070f
commit 441c921029
26 changed files with 86 additions and 193 deletions

View File

@@ -10,14 +10,9 @@ var loading_tween: Tween
const P = preload("res://Scenes/Tags/p.tscn")
const IMG = preload("res://Scenes/Tags/img.tscn")
const SEPARATOR = preload("res://Scenes/Tags/separator.tscn")
const BOLD = preload("res://Scenes/Tags/bold.tscn")
const ITALIC = preload("res://Scenes/Tags/italic.tscn")
const UNDERLINE = preload("res://Scenes/Tags/underline.tscn")
const SMALL = preload("res://Scenes/Tags/small.tscn")
const MARK = preload("res://Scenes/Tags/mark.tscn")
const CODE = preload("res://Scenes/Tags/code.tscn")
const PRE = preload("res://Scenes/Tags/pre.tscn")
const BR = preload("res://Scenes/Tags/br.tscn")
const SPAN = preload("res://Scenes/Tags/span.tscn")
func render():
# Clear existing content
@@ -26,7 +21,7 @@ func render():
var html_bytes = "<head>
<title>My cool web</title>
<icon src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Google_%22G%22_logo.svg/768px-Google_%22G%22_logo.svg.png\"> <!--This image will be the page's icon-->
<icon src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Google_%22G%22_logo.svg/768px-Google_%22G%22_logo.svg.png\">
<meta name=\"theme-color\" content=\"#000000\">
<meta name=\"description\" content=\"My cool web\">
@@ -38,11 +33,11 @@ func render():
<body>
<p>Hey there! this is a test</p>
<b>This is bold</b>
<i>This is italic</i>
<i>This is italic <mark>actually, and it's pretty <u>cool</u></mark></i>
<u>This is underline</u>
<small>this is small</small>
<mark>this is marked</mark>
<code>this is code</code>
<code>this is code<span> THIS IS A SPAN AND SHOULDNT BE ANY DIFFERENT</span></code>
<pre>
Text in a pre element
@@ -78,7 +73,26 @@ line breaks
stop_loading_icon()
var body = parser.find_first("body")
for element: HTMLParser.HTMLElement in body.children:
var i = 0
while i < body.children.size():
var element: HTMLParser.HTMLElement = body.children[i]
if element.is_inline_element():
# Collect consecutive inline elements and flatten nested ones
var inline_elements: Array[HTMLParser.HTMLElement] = []
while i < body.children.size() and body.children[i].is_inline_element():
inline_elements.append(body.children[i])
i += 1
var inline_container = P.instantiate()
var temp_parent = HTMLParser.HTMLElement.new()
temp_parent.tag_name = "p"
temp_parent.children = inline_elements
inline_container.init(temp_parent)
website_container.add_child(inline_container)
continue
match element.tag_name:
"p":
var p = P.instantiate()
@@ -92,10 +106,6 @@ line breaks
var br = BR.instantiate()
br.init(element)
website_container.add_child(br)
"b":
var bold = BOLD.instantiate()
bold.init(element)
website_container.add_child(bold)
"img":
var img = IMG.instantiate()
img.init(element)
@@ -104,28 +114,14 @@ line breaks
var separator = SEPARATOR.instantiate()
separator.init(element)
website_container.add_child(separator)
"i":
var italic = ITALIC.instantiate()
italic.init(element)
website_container.add_child(italic)
"u":
var underline = UNDERLINE.instantiate()
underline.init(element)
website_container.add_child(underline)
"small":
var small = SMALL.instantiate()
small.init(element)
website_container.add_child(small)
"mark":
var mark = MARK.instantiate()
mark.init(element)
website_container.add_child(mark)
"code":
var code = CODE.instantiate()
code.init(element)
website_container.add_child(code)
"span":
var span = SPAN.instantiate()
span.init(element)
website_container.add_child(span)
_:
print("Couldn't parse unsupported HTML tag \"%s\"" % element.tag_name)
i += 1
func set_loading_icon(tab: Tab) -> void:
tab.set_icon(LOADER_CIRCLE)