CORE/mkdown.gd

41 lines
1.6 KiB
GDScript3
Raw Normal View History

######################################
# THE CORE FRAMEWORK #
# MADE BY THE STAROPENSOURCE PROJECT #
# AND CONTRIBUTERS (THANK YOU!) #
# #
# COPYRIGHT 2023 THE STAROPENSOURCE #
# PROJECT AND CONTRIBUTERS #
# #
# LICENSED UNDER THE GNU GENERAL #
# PUBLIC LICENSE VERSION 3 (ONLY) #
######################################
extends Node
# CORE modules
var core: Node = null
var logger: Node = null
# Font sizes
var fsizes: Dictionary = {"text":"16","h1":"29","h2":"24","h3":"19","h4":"14","h5":"9","h6":"4"}
func parse(content:String) -> String:
var parse_text: String = ""
for line in content.split("\n",false):
var line_mod: String = line
if line_mod.begins_with("######"):
line_mod = line_mod.replace("######","[font_size=" + fsizes["h6"] + "]") + "[/font_size]"
elif line_mod.begins_with("#####"):
line_mod = line_mod.replace("#####","[font_size=" + fsizes["h5"] + "]") + "[/font_size]"
elif line_mod.begins_with("####"):
line_mod = line_mod.replace("####","[font_size=" + fsizes["h4"] + "]") + "[/font_size]"
elif line_mod.begins_with("###"):
line_mod = line_mod.replace("###","[font_size=" + fsizes["h3"] + "]") + "[/font_size]"
elif line_mod.begins_with("##"):
line_mod = line_mod.replace("##","[font_size=" + fsizes["h2"] + "]") + "[/font_size]"
elif line_mod.begins_with("#"):
line_mod = line_mod.replace("#","[font_size=" + fsizes["h1"] + "]") + "[/font_size]"
else:
line_mod = "[font_size=" + fsizes["text"] + "]" + line_mod + "[/font_size]"
parse_text = parse_text + line_mod + "\n"
return parse_text