markdownlabel update
This commit is contained in:
parent
707b1b808f
commit
05b8d6496b
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
A custom [Godot](https://godotengine.org/) node that extends [RichTextLabel](https://docs.godotengine.org/en/stable/classes/class_richtextlabel.html) to use Markdown instead of BBCode.
|
||||
|
||||
Compatible with **Godot 4.2+**. Contains uid files for Godot 4.4+.
|
||||
|
||||
### Contents
|
||||
|
||||
- [Disclaimer](#disclaimer)
|
||||
|
|
@ -24,7 +26,7 @@ A custom [Godot](https://godotengine.org/) node that extends [RichTextLabel](htt
|
|||
|
||||
## Disclaimer
|
||||
|
||||
**This is a work in progress**. I created this for my own use and figured out someone else might as well have some use for it. Obviously using BBCode will be better performance-wise since it's natively integrated in Godot. But using Markdown is much easier to write and read, so it can save development time in many cases.
|
||||
I created this for my own use and figured out someone else might as well have some use for it. Obviously using BBCode will be better performance-wise since it's natively integrated in Godot. But using Markdown is much easier to write and read, so it can save development time in many cases.
|
||||
|
||||
I coded this quickly and without previous knowledge of how to parse Markdown properly, so there might be some inefficiencies and bugs. Please report any unexpected behavior.
|
||||
|
||||
|
|
@ -38,10 +40,19 @@ My initial use case that lead me to do this was to directly include text from fi
|
|||
|
||||
## Installation
|
||||
|
||||
1. Download the `addons` folder of this repository.
|
||||
2. Place it in your project's root folder.
|
||||
3. Go to `Project > Project Settings... > Plugins` and enable the MarkdownLabel plugin.
|
||||
4. Reload the project.
|
||||
**From Github:**
|
||||
|
||||
1. Download the `addons` folder of this repository
|
||||
2. Place it in your project's root folder (merge it if you already have an 'addons' folder)
|
||||
3. Go to `Project > Project Settings... > Plugins` and enable the MarkdownLabel plugin
|
||||
|
||||
**From Godot:**
|
||||
|
||||
1. Go to the AssetLib tab and search for MarkdownLabel
|
||||
2. Click "Download" and then "Install"
|
||||
3. Go to `Project > Project Settings... > Plugins` and enable the MarkdownLabel plugin
|
||||
|
||||
You might need to reload the project.
|
||||
|
||||
## Usage
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dimrj7bdc6wup"
|
||||
uid="uid://b4hykd2j47kin"
|
||||
path="res://.godot/imported/screenshot.png-0915907174479379b0fc8bba6785d7c8.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
|
|
@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/screenshot.png-0915907174479379b0fc8bba6785d7
|
|||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
|
|
@ -25,6 +27,10 @@ mipmaps/generate=false
|
|||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
uid://bb8axtfudcwuv
|
||||
uid://bm7huuxd3k4yu
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
[gd_scene load_steps=15 format=3 uid="uid://bka0d50qmnb8y"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bb8axtfudcwuv" path="res://addons/markdownlabel/example.gd" id="1_7b8dd"]
|
||||
[ext_resource type="Script" uid="uid://dr7xhgd53cvmf" path="res://addons/markdownlabel/markdownlabel.gd" id="2_opcio"]
|
||||
[ext_resource type="Script" uid="uid://2nt1uho85s8f" path="res://addons/markdownlabel/header_formats/h1_format.gd" id="3_kbjha"]
|
||||
[ext_resource type="Script" uid="uid://c0sorgri1jvgp" path="res://addons/markdownlabel/header_formats/h2_format.gd" id="4_tqhuu"]
|
||||
[ext_resource type="Script" uid="uid://bxp6pmnguqayg" path="res://addons/markdownlabel/header_formats/h3_format.gd" id="5_us0p7"]
|
||||
[ext_resource type="Script" uid="uid://cevgeq5lemi6u" path="res://addons/markdownlabel/header_formats/h4_format.gd" id="6_8ublj"]
|
||||
[ext_resource type="Script" uid="uid://be2s7l2uixmfl" path="res://addons/markdownlabel/header_formats/h5_format.gd" id="7_42de6"]
|
||||
[ext_resource type="Script" uid="uid://ladew4bsypon" path="res://addons/markdownlabel/header_formats/h6_format.gd" id="8_y8fds"]
|
||||
[ext_resource type="Script" uid="uid://bm7huuxd3k4yu" path="res://addons/markdownlabel/example.gd" id="1_7b8dd"]
|
||||
[ext_resource type="Script" uid="uid://dbap0gqox0ty1" path="res://addons/markdownlabel/markdownlabel.gd" id="2_opcio"]
|
||||
[ext_resource type="Script" uid="uid://dcx7crs23nf4" path="res://addons/markdownlabel/header_formats/h1_format.gd" id="3_kbjha"]
|
||||
[ext_resource type="Script" uid="uid://d0sin64i4v3op" path="res://addons/markdownlabel/header_formats/h2_format.gd" id="4_tqhuu"]
|
||||
[ext_resource type="Script" uid="uid://dlok0dv1tq2bf" path="res://addons/markdownlabel/header_formats/h3_format.gd" id="5_us0p7"]
|
||||
[ext_resource type="Script" uid="uid://bayuh2vafablg" path="res://addons/markdownlabel/header_formats/h4_format.gd" id="6_8ublj"]
|
||||
[ext_resource type="Script" uid="uid://dfr1w7u3jgni3" path="res://addons/markdownlabel/header_formats/h5_format.gd" id="7_42de6"]
|
||||
[ext_resource type="Script" uid="uid://bsi6dexoofpe6" path="res://addons/markdownlabel/header_formats/h6_format.gd" id="8_y8fds"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_r7ev3"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("3_kbjha")
|
||||
font_size = 2.285
|
||||
is_bold = false
|
||||
|
|
@ -19,6 +20,7 @@ override_font_color = false
|
|||
font_color = Color(1, 1, 1, 1)
|
||||
|
||||
[sub_resource type="Resource" id="Resource_qh6ic"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("4_tqhuu")
|
||||
font_size = 1.714
|
||||
is_bold = false
|
||||
|
|
@ -28,6 +30,7 @@ override_font_color = false
|
|||
font_color = Color(1, 1, 1, 1)
|
||||
|
||||
[sub_resource type="Resource" id="Resource_qx73p"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("5_us0p7")
|
||||
font_size = 1.428
|
||||
is_bold = false
|
||||
|
|
@ -37,6 +40,7 @@ override_font_color = false
|
|||
font_color = Color(1, 1, 1, 1)
|
||||
|
||||
[sub_resource type="Resource" id="Resource_yx0wh"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("6_8ublj")
|
||||
font_size = 1.142
|
||||
is_bold = false
|
||||
|
|
@ -46,6 +50,7 @@ override_font_color = false
|
|||
font_color = Color(1, 1, 1, 1)
|
||||
|
||||
[sub_resource type="Resource" id="Resource_1ovcl"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("7_42de6")
|
||||
font_size = 1.0
|
||||
is_bold = false
|
||||
|
|
@ -55,6 +60,7 @@ override_font_color = false
|
|||
font_color = Color(1, 1, 1, 1)
|
||||
|
||||
[sub_resource type="Resource" id="Resource_fj0e0"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("8_y8fds")
|
||||
font_size = 0.857
|
||||
is_bold = false
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
@tool
|
||||
class_name H1Format
|
||||
extends Resource
|
||||
|
||||
|
|
@ -14,31 +15,29 @@ extends Resource
|
|||
## Custom font color to apply to this header level. Ignored if [code]override_font_color[/code] is disabled.
|
||||
@export var font_color: Color = Color.WHITE : set = _set_font_color
|
||||
|
||||
signal _updated
|
||||
|
||||
func _init() -> void:
|
||||
resource_local_to_scene = true
|
||||
|
||||
func _set_font_size(new_font_size: float) -> void:
|
||||
font_size = new_font_size
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_override_font_color(enabled: bool) -> void:
|
||||
override_font_color = enabled
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_font_color(new_font_color: Color) -> void:
|
||||
font_color = new_font_color
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_bold(new_is_bold: bool) -> void:
|
||||
is_bold = new_is_bold
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_italic(new_is_italic: bool) -> void:
|
||||
is_italic = new_is_italic
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_underlined(new_is_underlined: bool) -> void:
|
||||
is_underlined = new_is_underlined
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
uid://2nt1uho85s8f
|
||||
uid://dcx7crs23nf4
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
@tool
|
||||
class_name H2Format
|
||||
extends Resource
|
||||
|
||||
|
|
@ -14,31 +15,29 @@ extends Resource
|
|||
## Custom font color to apply to this header level. Ignored if [code]override_font_color[/code] is disabled.
|
||||
@export var font_color: Color = Color.WHITE : set = _set_font_color
|
||||
|
||||
signal _updated
|
||||
|
||||
func _init() -> void:
|
||||
resource_local_to_scene = true
|
||||
|
||||
func _set_font_size(new_font_size: float) -> void:
|
||||
font_size = new_font_size
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_override_font_color(enabled: bool) -> void:
|
||||
override_font_color = enabled
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_font_color(new_font_color: Color) -> void:
|
||||
font_color = new_font_color
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_bold(new_is_bold: bool) -> void:
|
||||
is_bold = new_is_bold
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_italic(new_is_italic: bool) -> void:
|
||||
is_italic = new_is_italic
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_underlined(new_is_underlined: bool) -> void:
|
||||
is_underlined = new_is_underlined
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
uid://c0sorgri1jvgp
|
||||
uid://d0sin64i4v3op
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
@tool
|
||||
class_name H3Format
|
||||
extends Resource
|
||||
|
||||
|
|
@ -14,31 +15,29 @@ extends Resource
|
|||
## Custom font color to apply to this header level. Ignored if [code]override_font_color[/code] is disabled.
|
||||
@export var font_color: Color = Color.WHITE : set = _set_font_color
|
||||
|
||||
signal _updated
|
||||
|
||||
func _init() -> void:
|
||||
resource_local_to_scene = true
|
||||
|
||||
func _set_font_size(new_font_size: float) -> void:
|
||||
font_size = new_font_size
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_override_font_color(enabled: bool) -> void:
|
||||
override_font_color = enabled
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_font_color(new_font_color: Color) -> void:
|
||||
font_color = new_font_color
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_bold(new_is_bold: bool) -> void:
|
||||
is_bold = new_is_bold
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_italic(new_is_italic: bool) -> void:
|
||||
is_italic = new_is_italic
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_underlined(new_is_underlined: bool) -> void:
|
||||
is_underlined = new_is_underlined
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
uid://bxp6pmnguqayg
|
||||
uid://dlok0dv1tq2bf
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
@tool
|
||||
class_name H4Format
|
||||
extends Resource
|
||||
|
||||
|
|
@ -14,31 +15,29 @@ extends Resource
|
|||
## Custom font color to apply to this header level. Ignored if [code]override_font_color[/code] is disabled.
|
||||
@export var font_color: Color = Color.WHITE : set = _set_font_color
|
||||
|
||||
signal _updated
|
||||
|
||||
func _init() -> void:
|
||||
resource_local_to_scene = true
|
||||
|
||||
func _set_font_size(new_font_size: float) -> void:
|
||||
font_size = new_font_size
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_override_font_color(enabled: bool) -> void:
|
||||
override_font_color = enabled
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_font_color(new_font_color: Color) -> void:
|
||||
font_color = new_font_color
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_bold(new_is_bold: bool) -> void:
|
||||
is_bold = new_is_bold
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_italic(new_is_italic: bool) -> void:
|
||||
is_italic = new_is_italic
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_underlined(new_is_underlined: bool) -> void:
|
||||
is_underlined = new_is_underlined
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
uid://cevgeq5lemi6u
|
||||
uid://bayuh2vafablg
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
@tool
|
||||
class_name H5Format
|
||||
extends Resource
|
||||
|
||||
|
|
@ -14,31 +15,29 @@ extends Resource
|
|||
## Custom font color to apply to this header level. Ignored if [code]override_font_color[/code] is disabled.
|
||||
@export var font_color: Color = Color.WHITE : set = _set_font_color
|
||||
|
||||
signal _updated
|
||||
|
||||
func _init() -> void:
|
||||
resource_local_to_scene = true
|
||||
|
||||
func _set_font_size(new_font_size: float) -> void:
|
||||
font_size = new_font_size
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_override_font_color(enabled: bool) -> void:
|
||||
override_font_color = enabled
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_font_color(new_font_color: Color) -> void:
|
||||
font_color = new_font_color
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_bold(new_is_bold: bool) -> void:
|
||||
is_bold = new_is_bold
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_italic(new_is_italic: bool) -> void:
|
||||
is_italic = new_is_italic
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_underlined(new_is_underlined: bool) -> void:
|
||||
is_underlined = new_is_underlined
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
uid://be2s7l2uixmfl
|
||||
uid://dfr1w7u3jgni3
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
@tool
|
||||
class_name H6Format
|
||||
extends Resource
|
||||
|
||||
|
|
@ -14,31 +15,29 @@ extends Resource
|
|||
## Custom font color to apply to this header level. Ignored if [code]override_font_color[/code] is disabled.
|
||||
@export var font_color: Color = Color.WHITE : set = _set_font_color
|
||||
|
||||
signal _updated
|
||||
|
||||
func _init() -> void:
|
||||
resource_local_to_scene = true
|
||||
|
||||
func _set_font_size(new_font_size: float) -> void:
|
||||
font_size = new_font_size
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_override_font_color(enabled: bool) -> void:
|
||||
override_font_color = enabled
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_font_color(new_font_color: Color) -> void:
|
||||
font_color = new_font_color
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_bold(new_is_bold: bool) -> void:
|
||||
is_bold = new_is_bold
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_italic(new_is_italic: bool) -> void:
|
||||
is_italic = new_is_italic
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
||||
func _set_is_underlined(new_is_underlined: bool) -> void:
|
||||
is_underlined = new_is_underlined
|
||||
_updated.emit()
|
||||
emit_changed()
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
uid://ladew4bsypon
|
||||
uid://bsi6dexoofpe6
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cy1fanmsiigs1"
|
||||
uid="uid://b0v0sg3imhib3"
|
||||
path="res://.godot/imported/icon.svg-159f39e2b062b4de1e0ce4f170ca2380.ctex"
|
||||
metadata={
|
||||
"has_editor_variant": true,
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
|
|
@ -18,6 +19,8 @@ dest_files=["res://.godot/imported/icon.svg-159f39e2b062b4de1e0ce4f170ca2380.cte
|
|||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
|
|
@ -25,6 +28,10 @@ mipmaps/generate=false
|
|||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
|
|
@ -33,5 +40,5 @@ process/hdr_clamp_exposure=false
|
|||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/scale_with_editor_scale=true
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
|
|
|
|||
|
|
@ -96,18 +96,12 @@ func _init(markdown_text: String = "") -> void:
|
|||
meta_clicked.connect(_on_meta_clicked)
|
||||
|
||||
func _ready() -> void:
|
||||
h1.connect("_updated",_update)
|
||||
h1.connect("changed",_update)
|
||||
h2.connect("_updated",_update)
|
||||
h2.connect("changed",_update)
|
||||
h3.connect("_updated",_update)
|
||||
h3.connect("changed",_update)
|
||||
h4.connect("_updated",_update)
|
||||
h4.connect("changed",_update)
|
||||
h5.connect("_updated",_update)
|
||||
h5.connect("changed",_update)
|
||||
h6.connect("_updated",_update)
|
||||
h6.connect("changed",_update)
|
||||
h1.changed.connect(_update)
|
||||
h2.changed.connect(_update)
|
||||
h3.changed.connect(_update)
|
||||
h4.changed.connect(_update)
|
||||
h5.changed.connect(_update)
|
||||
h6.changed.connect(_update)
|
||||
if Engine.is_editor_hint():
|
||||
bbcode_enabled = true
|
||||
#else:
|
||||
|
|
@ -146,6 +140,10 @@ func _validate_property(property: Dictionary) -> void:
|
|||
if property.name in ["bbcode_enabled", "text"]:
|
||||
property.usage = PROPERTY_USAGE_NO_EDITOR
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_TRANSLATION_CHANGED:
|
||||
_update()
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods:
|
||||
|
|
@ -156,7 +154,7 @@ func display_file(file_path: String) -> void:
|
|||
|
||||
#region Private methods:
|
||||
func _update() -> void:
|
||||
text = _convert_markdown(TranslationServer.translate(markdown_text))
|
||||
text = _convert_markdown( TranslationServer.translate(markdown_text) if can_auto_translate() else markdown_text)
|
||||
queue_redraw()
|
||||
|
||||
func _set_markdown_text(new_text: String) -> void:
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
uid://dr7xhgd53cvmf
|
||||
uid://dbap0gqox0ty1
|
||||
|
|
|
|||
|
|
@ -3,5 +3,5 @@
|
|||
name="MarkdownLabel"
|
||||
description="A custom node that extends RichTextLabel to use Markdown instead of BBCode."
|
||||
author="Daenvil"
|
||||
version="1.2.0"
|
||||
version="1.3.0"
|
||||
script="plugin.gd"
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
uid://cw21k8ouuq0o3
|
||||
uid://bm24cqp3w4jp3
|
||||
|
|
|
|||
Loading…
Reference in New Issue