Repository navigation
Basic Usage

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.)
Eg:[0, 1, 2, 6, 7, 8] -
width_map: Array<Array> (holds the width of each character: 0 is a width of 1, 1 of 2 until 254. 255 means a width of 0.)
Eg[[0, 0, 0, 255, 255, 255, 0], [0, 0]] -
line_map: Array<Array> (similar to the absolute map but split accross their corresponding lines.)
Eg[[0, 1, 2, 6], [7, 8]]
-
absolute_map: Array (holds the exact position of each character in the markdown input.)
Tip
line_map is available since v0.1.3
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:
In this example we display the markdown formatted equivalent of a text input directly to an ouput div. We've configured the options to only allow the specific syntax we like.
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';
// Find our input and output element
const text_input = document.getElementById("text_input");
const output_elem = document.getElementById("output_elem");
// Set our options
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
});
// Detect any changes from the input element and update the output render
text_input.addEventListener('input', () => {
let result = YAMP.parse(text_input.value);
// Don't forget to sanitize the output for security
output_elem.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 }