class Markdown
package texter.general.markdown
The Markdown
class provides tools to handle markdown texts in a cross-framework fashion.
In its base resides the interpret()
function.
Everything in this class is based around the interpreter. everything from the markdown rules,
to the patterns & visualization methods. The interpreter uses a pre-parser & lots of regex
s
(Regular Expresions) to parse the markdown text. after parsing, it returns the text witout all
of the "ugly" markdown syntax, and an array of the effects that are needed to be appied, with
startIndex
and endIndex
. You don't have to utilize all of the information the interpreter
gives you - it doesnt enforce anything - it just gives you the data you need to start working
interpret()
is mostly used internally to get information about the markdown text for visualization methods,
but you can also use it yourself to make your own markdown styling
Static variables
staticinlineread onlypatterns:MarkdownPatterns> = MarkdownPatterns
The patterns
field contains all of the patterns used to parse markdown text.
If you want to access them individually, you can do it using this field
staticinlineread onlysyntaxBlocks:MarkdownBlocks> = MarkdownBlocks
syntaxBlocks
is a field representing a class that contains many syntax coloring
methods for codeblocks.
staticinlineread onlyvisualizer:MarkdownVisualizer> = MarkdownVisualizer
If you want to modify certain visual aspects of the markdown text, you can
gain access to those via the visualizer
field.
Static methods
staticinterpret(markdownText:String, onComplete:(String, Array<MarkdownEffect>) ‑> Void):Void
Mostly for internal use, but can also be useful for creating your own Markdown styling.
This function takes in a string formatted in Markdown, and each time it encounteres a Markdown "special effect" (headings, charts, points, etc.), it pushes a style corresponding to the found effect.
for some effects, it also includes a built-in visual effect: - Unordered Lists - Emojis - Tables (coming soon)
after finding the effects, it calls:
onComplete:
The onComplete()
will get called after the text has been processed:
- First Argument - The Actual Text: to keep the text clean, after proccessing the text, a markdown-
free version of the text is returned (altho some marks do remain, such as the list items and hrules)
- Second Argument - The Effects - this array contains lots of ADTs (algebric data types). Those
contain the actual data - most of them contain the start & end index of the effect, and some contain more
data (things like list numbers, indentation...)
Things to notice:
- The markdown text contains zero-width spaces (\u200B) in the text in order to keep track of effect positions.
- The effect's range is from startIndex up to, but not including endIndex.
- certine effects will already be rendered by the interpreter, so no need to mess with those.
- The interpreter doesnt support everything markdown has to offer (yet). supported markups:
- Headings: #, ##, ###, ####, #####, ######, ####### - Lists (also nested): -, , +, 1., 2. - CodeBlocks:, ~~~~~~, four spaces - Inline Code:
- Italics: _, - Bolds: , __ - StrikeThrough: ~~~~ - Links:
[]()
- Math: $$ - Emojis: :emojiNameHere: - HRules: ---, , ___, ===, +++ - HRuledHeadings: H1 - title\n===,+++,, H2 - title\n---,___ - Paragraph Gaps** (two or more newlines) -
NewLines \ or double-whitespace at the end of the line
There are also some extra additions:
- Alignment:
, , , -> - Tabs: \t
- Alignment:
Parameters:
markdownText | Just a plain string with markdown formatting. If you want to make sure
the formatting is correct, just write the markdown text in a |
---|
staticinlinevisualizeMarkdown(textField:TextField):TextField
staticinlinevisualizeMarkdown(textField:TextFieldRTL):TextFieldRTL
Generates the default visual theme from the markdown interpreter's information.
If you want to edit the default visual theme, you can go to
Markdown.visualizer.markdownTextFormat
/MarkdownVisualizer.markdownTextFormat
and change things there.
examples (with/without static extension):
var visuals = new TextField();
visuals.text = "# hey everyone\n this is *so cool*"
Markdown.visualizeMarkdown(visuals);
//OR
visuals.visualizeMarkdown();