The MarkdownVisualizer class is a containing all framework-specific markdown visualization methods.

For now, visualization is only supported for these frameworks:

If you'd like for more frameworks to be added you can do a couple of things:

  1. Take an existing visualization method and make it work for your framework. If it works as intended, contact me and i'll add it.
  2. If you cant make existing solutions work well, add a new visualization method. again - if it works as intended, contact me and i'll add it.
  3. contact me and ask me to make a visualization method. this one will take the longest since ill need to download and learn how to make things with that framework.

How To Implement

If you want to make markdown visualization work for your framework, its actually pretty easy. The interpreter already sends all of the data and even does some nice modifictaions, so its as easy as can be:

First, make a function, containing Markdown.interpret that recives a text field and retruns it
Dont forget to reset the text's "styling" each time to avoid artifacts!


	function displayMarkdown(textField:Text):Text {
		textField.textStyle = defaultTextStyle;
		Markdown.interpret(textField.text, function(markdownText:String, effects:Array<MarkdownEffect>) {
			
		});
		return textField;
	}

Second, in the body of the anonymus function, you implement this giant switch-case to handle all of the effects you want to handle, as well as make your text "markdown-artifact-free". - start contains the starting index of the effect. - end contains the ending index of the effect, but not included! - any extra argument this is for effects that require extra information to be rendered correctly - language for codeblocks, level for headings...

	function displayMarkdown(textField:Text):Text {
		textField.textStyle = defaultTextStyle;
		Markdown.interpret(textField.text, function(markdownText:String, effects:Array<MarkdownEffect>) {
			field.text = markdownText;
				for (e in effects)
				{
					switch e
					{
						case Emoji(type, start, end): 
						case Bold(start, end): 
						case Italic(start, end): 
						case Code(start, end): 
						case Math(start, end): 
						case Link(link, start, end): 
						case Heading(level, start, end): 
						case UnorderedListItem(nestingLevel, start, end): 
						case OrderedListItem(number, nestingLevel, start, end): 
						case HorizontalRule(type, start, end): 
						case CodeBlock(language, start, end): 
						case StrikeThrough(start, end): 
						case Image(altText, imageSource, start, end): 
						case ParagraphGap(start, end):

						default: continue;
					}
				}
			});
			return field;
	}

And Finally, you can add your desired effect in each of the cases.

case Bold: textField.setBold(start, end);
case Italic: textField.setItalic(start, end);
case Math: textField.setFont("path/to/mathFont.ttf", start, end); //ETC.

For a working example you can look at this file's source code.

contact info (for submitting a visualization method): - ShaharMS#8195 (discord) - https://github.com/ShaharMS/texter (this haxelib's repo to make pull requests)

Static variables

staticread onlymarkdownTextFormat:TextFormat

When visualizing a given Markdown string, this TextFormat will be used. You can modify the TextFormat to change the style of the text via visualConfig;

@:value(@:privateAccess new VisualConfig())staticvisualConfig:VisualConfig = @:privateAccess new VisualConfig()

visualConfig is a "dictionary" containing all of the configuration options for the visualizer. NOTE - because its a cross-framework field, and not every framework supports the same options, You cant exect everything to work in every framework.

Static methods

staticinlinegenerateVisuals(field:TextField):TextField

staticinlinegenerateVisuals(field:TextFieldRTL):TextFieldRTL

Generates the default visual theme from the markdown interpreter's information.

examples (with/without static extension):

var visuals = new TextField();
visuals.text = "# hey everyone\n this is *so cool*"
MarkdownVisualizer.generateTextFieldVisuals(visuals);
//OR
visuals.generateVisuals();