Repository navigation
Basic Usage
theblackswitch edited this page Aug 12, 2026
·
8 revisions

Welcome to the introduction page!
To start using YAMP you only need to familiarize yourself with 2 methods:
YAMP.parse();The parse method is used to parse a markdown formatted input and return both the parsed html and a char map which maps each visible text charcter in the html back to their original markdown character.
Arguments:
- input: string (The markdown input that should be parsed)
Returns:
-
object
- html: string (the resulting html. Sanatize this!)
-
char_map: object
- absolute_map: array (holds the exact position of each character in the markdown input)
- width_map: array (holds the width of each character: 0 is a width of 1, 1 of 2 until 254. 255 means a width of 0)
YAMP.set_options();This method is used to modify the global options. Once called, it will keep those options set until it's called again. It's not recommended to set this method every time you parse. Instead set your prefered configuration once or only when changes are needed.
Arguments
- options: object (The options used to determine YAMP's behaviour)
Available Options:
import * as YAMP from "https://cdn.jsdelivr.net/npm/@theblackswitch/yamp@latest/dist/main.js"
import DOMPurify from 'https://cdn.jsdelivr.net/npm/dompurify/+esm';
let text_input = document.getElementById("text_input");
let formatted_output = document.getElementById("Formatted output");
YAMP.set_options({
"enabled_features": [
YAMP.Header,
YAMP.BlockQuote,
YAMP.Emphasis,
YAMP.Strikethrough,
YAMP.List,
YAMP.Code,
YAMP.Link,
YAMP.EscapeIncompleteHtml
],
"disable_paragraph_elements": false,
"enable_trailing_linebreaks": true,
"literal_mid_word_underscores": false,
"add_zero_width_space_for_cursor_positions": true,
"finalize_spaces": false
});
text_input.addEventListener('input', () => {
let result = YAMP.parse(text_input.value);
formatted_output.innerHtml = DOMPurify.sanitize(result.html);
});~ wiki by theblackswitch
{ "enabled_features": [ // Specify features here to enable them YAMP.Header, // yes indeed you have to pass the class as a whole here YAMP.AlternateHeader, YAMP.BlockQuote, YAMP.Emphasis, YAMP.UnderscoreEmphasis, YAMP.Strikethrough, YAMP.List, YAMP.Code, YAMP.CodeBlock, YAMP.Link, YAMP.Image, YAMP.HorizontalRule, YAMP.Table, YAMP.EscapeIncompleteHtml ], "disable_paragraph_elements": false, // Whether to disable the generation of paragraph elements "enable_trailing_linebreaks": true, // Put a linebreak at the end of each line "literal_mid_word_underscores": true, // Stop parsing underscores in the middle of a word (only used for UnderscoreEmphasis) "add_zero_width_space_for_cursor_positions": true, // Place a zero width space for example on new lines so you're able to detect a cursor position "finalize_spaces": true, // Replace any spaces with "debug": false // Enable debug logging in the console }