<a> tag, make icon & html concurrent
This commit is contained in:
@@ -4,4 +4,8 @@ TODO:
|
||||
3. **Select-all CTRL+A shortcut**
|
||||
4. **Scrolling** in the website container
|
||||
5. **Store** tab containers so switching tabs won't erase previous tab.
|
||||
6. **GIF** support
|
||||
6. **GIF** support
|
||||
7. **Video** support via [GDE GoZen](https://github.com/VoylinsGamedevJourney/gde_gozen)
|
||||
|
||||
Issues:
|
||||
1. **< br />** counts as 1 element in **WebsiteContainer**, therefore despite being (0,0) in size, it counts as double in spacing.
|
||||
@@ -17,5 +17,6 @@ mouse_default_cursor_shape = 1
|
||||
theme = ExtResource("2_1glvj")
|
||||
theme_override_colors/default_color = Color(0, 0, 0, 1)
|
||||
bbcode_enabled = true
|
||||
text = "Placeholder"
|
||||
fit_content = true
|
||||
selection_enabled = true
|
||||
|
||||
@@ -196,6 +196,9 @@ layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/separation = 22
|
||||
|
||||
[node name="Control" type="Control" parent="VBoxContainer/WebsiteContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="WebsiteBackground" type="Panel" parent="."]
|
||||
z_index = -1
|
||||
layout_mode = 1
|
||||
|
||||
@@ -59,6 +59,12 @@ class HTMLElement:
|
||||
child_content = "[font_size=20][code]" + child.get_bbcode_formatted_text() + "[/code][/font_size]"
|
||||
"span":
|
||||
child_content = child.get_bbcode_formatted_text()
|
||||
"a":
|
||||
var href = child.get_attribute("href")
|
||||
if href.length() > 0:
|
||||
child_content = "[color=#1a0dab][url=%s]%s[/url][/color]" % [href, child.get_bbcode_formatted_text()]
|
||||
else:
|
||||
child_content = child.get_bbcode_formatted_text()
|
||||
_:
|
||||
child_content = child.get_bbcode_formatted_text()
|
||||
|
||||
@@ -73,7 +79,7 @@ class HTMLElement:
|
||||
return result
|
||||
|
||||
func is_inline_element() -> bool:
|
||||
return tag_name in ["b", "i", "u", "small", "mark", "code", "span"]
|
||||
return tag_name in ["b", "i", "u", "small", "mark", "code", "span", "a"]
|
||||
|
||||
class ParseResult:
|
||||
var root: HTMLElement
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
extends Control
|
||||
|
||||
func init(element: HTMLParser.HTMLElement) -> void:
|
||||
custom_minimum_size.y = 24
|
||||
pass
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
extends Control
|
||||
|
||||
@onready var rich_text_label: RichTextLabel = $RichTextLabel
|
||||
|
||||
func init(element: HTMLParser.HTMLElement) -> void:
|
||||
var label: RichTextLabel = $RichTextLabel
|
||||
label.text = "[font_size=24]%s[/font_size]" % element.get_bbcode_formatted_text()
|
||||
|
||||
@@ -39,6 +39,10 @@ func render():
|
||||
<mark>this is marked</mark>
|
||||
<code>this is code<span> THIS IS A SPAN AND SHOULDNT BE ANY DIFFERENT</span></code>
|
||||
|
||||
<p>
|
||||
<a href=\"https://youtube.com\">Hello gang</a>
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
Text in a pre element
|
||||
is displayed in a fixed-width
|
||||
@@ -69,8 +73,7 @@ line breaks
|
||||
|
||||
var icon = parser.get_icon()
|
||||
set_loading_icon(tab)
|
||||
tab.set_icon(await Network.fetch_image(icon))
|
||||
stop_loading_icon()
|
||||
call_deferred("update_tab_icon", tab, icon)
|
||||
|
||||
var body = parser.find_first("body")
|
||||
var i = 0
|
||||
@@ -80,8 +83,11 @@ line breaks
|
||||
if element.is_inline_element():
|
||||
# Collect consecutive inline elements and flatten nested ones
|
||||
var inline_elements: Array[HTMLParser.HTMLElement] = []
|
||||
var has_hyperlink = false
|
||||
while i < body.children.size() and body.children[i].is_inline_element():
|
||||
inline_elements.append(body.children[i])
|
||||
if contains_hyperlink(body.children[i]):
|
||||
has_hyperlink = true
|
||||
i += 1
|
||||
|
||||
var inline_container = P.instantiate()
|
||||
@@ -90,7 +96,12 @@ line breaks
|
||||
temp_parent.tag_name = "p"
|
||||
temp_parent.children = inline_elements
|
||||
inline_container.init(temp_parent)
|
||||
|
||||
website_container.add_child(inline_container)
|
||||
|
||||
if has_hyperlink:
|
||||
inline_container.rich_text_label.meta_clicked.connect(func(meta): OS.shell_open(str(meta)))
|
||||
|
||||
continue
|
||||
|
||||
match element.tag_name:
|
||||
@@ -98,6 +109,8 @@ line breaks
|
||||
var p = P.instantiate()
|
||||
p.init(element)
|
||||
website_container.add_child(p)
|
||||
if contains_hyperlink(element):
|
||||
p.rich_text_label.meta_clicked.connect(func(meta): OS.shell_open(str(meta)))
|
||||
"pre":
|
||||
var pre = PRE.instantiate()
|
||||
pre.init(element)
|
||||
@@ -137,3 +150,17 @@ func stop_loading_icon() -> void:
|
||||
if loading_tween:
|
||||
loading_tween.kill()
|
||||
loading_tween = null
|
||||
|
||||
func update_tab_icon(tab: Tab, icon: String) -> void:
|
||||
tab.set_icon(await Network.fetch_image(icon))
|
||||
stop_loading_icon()
|
||||
|
||||
func contains_hyperlink(element: HTMLParser.HTMLElement) -> bool:
|
||||
if element.tag_name == "a":
|
||||
return true
|
||||
|
||||
for child in element.children:
|
||||
if contains_hyperlink(child):
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user