From 1d8a77ea514b30a721e17ebfb74a910a471e457b Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 26 Apr 2024 18:21:56 +0200 Subject: [PATCH] Added a markdown renderer demo project. --- .../CustomMarkdownRenderer.gd | 23 ++ misc/markdown_renderer/CustomRenderer.gd | 14 + misc/markdown_renderer/Main.tscn | 31 ++ misc/markdown_renderer/NormalRenderer.gd | 13 + misc/markdown_renderer/TEST.md | 336 ++++++++++++++++++ misc/markdown_renderer/default_env.tres | 7 + misc/markdown_renderer/icon.png | Bin 0 -> 3238 bytes misc/markdown_renderer/icon.png.import | 35 ++ misc/markdown_renderer/project.pandemonium | 35 ++ 9 files changed, 494 insertions(+) create mode 100644 misc/markdown_renderer/CustomMarkdownRenderer.gd create mode 100644 misc/markdown_renderer/CustomRenderer.gd create mode 100644 misc/markdown_renderer/Main.tscn create mode 100644 misc/markdown_renderer/NormalRenderer.gd create mode 100644 misc/markdown_renderer/TEST.md create mode 100644 misc/markdown_renderer/default_env.tres create mode 100644 misc/markdown_renderer/icon.png create mode 100644 misc/markdown_renderer/icon.png.import create mode 100644 misc/markdown_renderer/project.pandemonium diff --git a/misc/markdown_renderer/CustomMarkdownRenderer.gd b/misc/markdown_renderer/CustomMarkdownRenderer.gd new file mode 100644 index 0000000..f95b9f5 --- /dev/null +++ b/misc/markdown_renderer/CustomMarkdownRenderer.gd @@ -0,0 +1,23 @@ +extends MarkdownRenderer +class_name CustomMarkdownRenderer + +var count : int = 0 + +func _renderer_callback(data: MarkdownRendererCustomRendererCallback) -> void: + data.result = str(count) + "\n" + data.result += "callback_type:" + str(data.callback_type) + "\n" + data.result += "text:" + data.text + "\n" + data.result += "content:" + data.content + "\n" + data.result += "level:" + str(data.level) + "\n" + data.result += "list_flags:" + str(data.list_flags) + "\n" + data.result += "table_flags:" + str(data.table_flags) + "\n" + data.result += "link:" + data.link + "\n" + data.result += "auto_link_type:" + str(data.auto_link_type) + "\n" + data.result += "title:" + data.title + "\n" + data.result += "alt:" + data.alt + "\n" + data.result += "num:" + str(data.num) + "\n" + data.result += "display_mode:" + str(data.display_mode) + "\n" + data.result += "inline_render:" + str(data.inline_render) + "\n" + data.result += "\n\n" + + count += 1 diff --git a/misc/markdown_renderer/CustomRenderer.gd b/misc/markdown_renderer/CustomRenderer.gd new file mode 100644 index 0000000..33a6a59 --- /dev/null +++ b/misc/markdown_renderer/CustomRenderer.gd @@ -0,0 +1,14 @@ +extends TextEdit + + +func _ready(): + var f : File = File.new() + + var mdr : CustomMarkdownRenderer = CustomMarkdownRenderer.new() + mdr.render_type = MarkdownRenderer.RENDERER_TYPE_CUSTOM + + f.open("res://TEST.md", File.READ) + + text = mdr.render(f.get_as_text()) + + f.close() diff --git a/misc/markdown_renderer/Main.tscn b/misc/markdown_renderer/Main.tscn new file mode 100644 index 0000000..96110c1 --- /dev/null +++ b/misc/markdown_renderer/Main.tscn @@ -0,0 +1,31 @@ +[gd_scene load_steps=3 format=3] + +[ext_resource path="res://CustomRenderer.gd" type="Script" id=1] +[ext_resource path="res://NormalRenderer.gd" type="Script" id=2] + +[node name="PanelContainer" type="PanelContainer"] +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="Main" type="HBoxContainer" parent="."] +margin_left = 7.0 +margin_top = 7.0 +margin_right = 1017.0 +margin_bottom = 593.0 + +[node name="NormalRenderer" type="TextEdit" parent="Main"] +margin_right = 503.0 +margin_bottom = 586.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +wrap_enabled = true +script = ExtResource( 2 ) + +[node name="CustomRenderer" type="TextEdit" parent="Main"] +margin_left = 507.0 +margin_right = 1010.0 +margin_bottom = 586.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +wrap_enabled = true +script = ExtResource( 1 ) diff --git a/misc/markdown_renderer/NormalRenderer.gd b/misc/markdown_renderer/NormalRenderer.gd new file mode 100644 index 0000000..beab795 --- /dev/null +++ b/misc/markdown_renderer/NormalRenderer.gd @@ -0,0 +1,13 @@ +extends TextEdit + + +func _ready(): + var f : File = File.new() + + var mdr : MarkdownRenderer = MarkdownRenderer.new() + + f.open("res://TEST.md", File.READ) + + text = mdr.render(f.get_as_text()) + + f.close() diff --git a/misc/markdown_renderer/TEST.md b/misc/markdown_renderer/TEST.md new file mode 100644 index 0000000..8a31d3c --- /dev/null +++ b/misc/markdown_renderer/TEST.md @@ -0,0 +1,336 @@ +# File + +This is a test file from https://github.com/mxstbr/markdown-test-file/blob/master/TEST.md + +MIT License + +Copyright (c) 2017 Max Stoiber + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +# Markdown: Syntax + +* [Overview](#overview) + * [Philosophy](#philosophy) + * [Inline HTML](#html) + * [Automatic Escaping for Special Characters](#autoescape) +* [Block Elements](#block) + * [Paragraphs and Line Breaks](#p) + * [Headers](#header) + * [Blockquotes](#blockquote) + * [Lists](#list) + * [Code Blocks](#precode) + * [Horizontal Rules](#hr) +* [Span Elements](#span) + * [Links](#link) + * [Emphasis](#em) + * [Code](#code) + * [Images](#img) +* [Miscellaneous](#misc) + * [Backslash Escapes](#backslash) + * [Automatic Links](#autolink) + + +**Note:** This document is itself written using Markdown; you +can [see the source for it by adding '.text' to the URL](/projects/markdown/syntax.text). + +---- + +## Overview + +### Philosophy + +Markdown is intended to be as easy-to-read and easy-to-write as is feasible. + +Readability, however, is emphasized above all else. A Markdown-formatted +document should be publishable as-is, as plain text, without looking +like it's been marked up with tags or formatting instructions. While +Markdown's syntax has been influenced by several existing text-to-HTML +filters -- including [Setext](http://docutils.sourceforge.net/mirror/setext.html), [atx](http://www.aaronsw.com/2002/atx/), [Textile](http://textism.com/tools/textile/), [reStructuredText](http://docutils.sourceforge.net/rst.html), +[Grutatext](http://www.triptico.com/software/grutatxt.html), and [EtText](http://ettext.taint.org/doc/) -- the single biggest source of +inspiration for Markdown's syntax is the format of plain text email. + +## Block Elements + +### Paragraphs and Line Breaks + +A paragraph is simply one or more consecutive lines of text, separated +by one or more blank lines. (A blank line is any line that looks like a +blank line -- a line containing nothing but spaces or tabs is considered +blank.) Normal paragraphs should not be indented with spaces or tabs. + +The implication of the "one or more consecutive lines of text" rule is +that Markdown supports "hard-wrapped" text paragraphs. This differs +significantly from most other text-to-HTML formatters (including Movable +Type's "Convert Line Breaks" option) which translate every line break +character in a paragraph into a `
` tag. + +When you *do* want to insert a `
` break tag using Markdown, you +end a line with two or more spaces, then type return. + +### Headers + +Markdown supports two styles of headers, [Setext] [1] and [atx] [2]. + +Optionally, you may "close" atx-style headers. This is purely +cosmetic -- you can use this if you think it looks better. The +closing hashes don't even need to match the number of hashes +used to open the header. (The number of opening hashes +determines the header level.) + + +### Blockquotes + +Markdown uses email-style `>` characters for blockquoting. If you're +familiar with quoting passages of text in an email message, then you +know how to create a blockquote in Markdown. It looks best if you hard +wrap the text and put a `>` before every line: + +> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, +> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. +> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. +> +> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse +> id sem consectetuer libero luctus adipiscing. + +Markdown allows you to be lazy and only put the `>` before the first +line of a hard-wrapped paragraph: + +> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, +consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. +Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. + +> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse +id sem consectetuer libero luctus adipiscing. + +Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by +adding additional levels of `>`: + +> This is the first level of quoting. +> +> > This is nested blockquote. +> +> Back to the first level. + +Blockquotes can contain other Markdown elements, including headers, lists, +and code blocks: + +> ## This is a header. +> +> 1. This is the first list item. +> 2. This is the second list item. +> +> Here's some example code: +> +> return shell_exec("echo $input | $markdown_script"); + +Any decent text editor should make email-style quoting easy. For +example, with BBEdit, you can make a selection and choose Increase +Quote Level from the Text menu. + + +### Lists + +Markdown supports ordered (numbered) and unordered (bulleted) lists. + +Unordered lists use asterisks, pluses, and hyphens -- interchangably +-- as list markers: + +* Red +* Green +* Blue + +is equivalent to: + ++ Red ++ Green ++ Blue + +and: + +- Red +- Green +- Blue + +Ordered lists use numbers followed by periods: + +1. Bird +2. McHale +3. Parish + +It's important to note that the actual numbers you use to mark the +list have no effect on the HTML output Markdown produces. The HTML +Markdown produces from the above list is: + +If you instead wrote the list in Markdown like this: + +1. Bird +1. McHale +1. Parish + +or even: + +3. Bird +1. McHale +8. Parish + +you'd get the exact same HTML output. The point is, if you want to, +you can use ordinal numbers in your ordered Markdown lists, so that +the numbers in your source match the numbers in your published HTML. +But if you want to be lazy, you don't have to. + +To make lists look nice, you can wrap items with hanging indents: + +* Lorem ipsum dolor sit amet, consectetuer adipiscing elit. + Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, + viverra nec, fringilla in, laoreet vitae, risus. +* Donec sit amet nisl. Aliquam semper ipsum sit amet velit. + Suspendisse id sem consectetuer libero luctus adipiscing. + +But if you want to be lazy, you don't have to: + +* Lorem ipsum dolor sit amet, consectetuer adipiscing elit. +Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, +viverra nec, fringilla in, laoreet vitae, risus. +* Donec sit amet nisl. Aliquam semper ipsum sit amet velit. +Suspendisse id sem consectetuer libero luctus adipiscing. + +List items may consist of multiple paragraphs. Each subsequent +paragraph in a list item must be indented by either 4 spaces +or one tab: + +1. This is a list item with two paragraphs. Lorem ipsum dolor + sit amet, consectetuer adipiscing elit. Aliquam hendrerit + mi posuere lectus. + + Vestibulum enim wisi, viverra nec, fringilla in, laoreet + vitae, risus. Donec sit amet nisl. Aliquam semper ipsum + sit amet velit. + +2. Suspendisse id sem consectetuer libero luctus adipiscing. + +It looks nice if you indent every line of the subsequent +paragraphs, but here again, Markdown will allow you to be +lazy: + +* This is a list item with two paragraphs. + + This is the second paragraph in the list item. You're +only required to indent the first line. Lorem ipsum dolor +sit amet, consectetuer adipiscing elit. + +* Another item in the same list. + +To put a blockquote within a list item, the blockquote's `>` +delimiters need to be indented: + +* A list item with a blockquote: + + > This is a blockquote + > inside a list item. + +To put a code block within a list item, the code block needs +to be indented *twice* -- 8 spaces or two tabs: + +* A list item with a code block: + + + +### Code Blocks + +Pre-formatted code blocks are used for writing about programming or +markup source code. Rather than forming normal paragraphs, the lines +of a code block are interpreted literally. Markdown wraps a code block +in both `
` and `` tags.
+
+To produce a code block in Markdown, simply indent every line of the
+block by at least 4 spaces or 1 tab.
+
+This is a normal paragraph:
+
+    This is a code block.
+
+Here is an example of AppleScript:
+
+    tell application "Foo"
+        beep
+    end tell
+
+A code block continues until it reaches a line that is not indented
+(or the end of the article).
+
+Within a code block, ampersands (`&`) and angle brackets (`<` and `>`)
+are automatically converted into HTML entities. This makes it very
+easy to include example HTML source code using Markdown -- just paste
+it and indent it, and Markdown will handle the hassle of encoding the
+ampersands and angle brackets. For example, this:
+
+    
+
+Regular Markdown syntax is not processed within code blocks. E.g.,
+asterisks are just literal asterisks within a code block. This means
+it's also easy to use Markdown to write about Markdown's own syntax.
+
+```
+tell application "Foo"
+    beep
+end tell
+```
+
+## Span Elements
+
+### Links
+
+Markdown supports two style of links: *inline* and *reference*.
+
+In both styles, the link text is delimited by [square brackets].
+
+To create an inline link, use a set of regular parentheses immediately
+after the link text's closing square bracket. Inside the parentheses,
+put the URL where you want the link to point, along with an *optional*
+title for the link, surrounded in quotes. For example:
+
+This is [an example](http://example.com/) inline link.
+
+[This link](http://example.net/) has no title attribute.
+
+### Emphasis
+
+Markdown treats asterisks (`*`) and underscores (`_`) as indicators of
+emphasis. Text wrapped with one `*` or `_` will be wrapped with an
+HTML `` tag; double `*`'s or `_`'s will be wrapped with an HTML
+`` tag. E.g., this input:
+
+*single asterisks*
+
+_single underscores_
+
+**double asterisks**
+
+__double underscores__
+
+### Code
+
+To indicate a span of code, wrap it with backtick quotes (`` ` ``).
+Unlike a pre-formatted code block, a code span indicates code within a
+normal paragraph. For example:
+
+Use the `printf()` function.
diff --git a/misc/markdown_renderer/default_env.tres b/misc/markdown_renderer/default_env.tres
new file mode 100644
index 0000000..8419635
--- /dev/null
+++ b/misc/markdown_renderer/default_env.tres
@@ -0,0 +1,7 @@
+[gd_resource type="Environment3D" load_steps=2 format=3]
+
+[sub_resource type="ProceduralSky" id=1]
+
+[resource]
+background_mode = 2
+background_sky = SubResource( 1 )
diff --git a/misc/markdown_renderer/icon.png b/misc/markdown_renderer/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..5eaa3d1ad38ef8667b54c5ae78ec23c708023ae7
GIT binary patch
literal 3238
zcmV;X3|aGuP)Px>U`a$lRCt`-n|pBF*Hyvm$tcH&MlOwxf#49O%W
zO`rif1P5@ZO$wy#5N4SE1!>Y^lBQuW$+(Y%QYbYLAc4j$xFNOku;YhfS;n$0*?PaV
zTJ7#{f4_VAVLTzyN*zgi-rs7Pc41^>WQH!LKZL_!fZYPVE`(Tq^;Ny{P)bc8#FHrXH-ke%
zz?1>P;V=UB3n6x1Qw^^Ylu|!Z@adtUAw(z?LesR*X+r$fd`8nW@!K|a5m4K#cl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