upmark
Converts talk markup to an array of objects. For safe and consistent virtual DOM mapping. Lets you have a component, with local state, in place of an interlink, url, quote, code, spoiler or heading.
Example
Install with npm i -S upmark
, then run:
const Up = ;const up = "example.net"; // Own domain, for interlinks. up;
Parses your input and returns an AST:
children: ">>" "" "123" type: 1 0 children: "https://example.net/" "thread-id" "123" type: 1 0 0 children: "Quoted spoiler: " children: children: "https://uk.wikipedia.org/wiki/Тест" type: 4 type: 5 type: 2 0 0 children: "Heading" type: 6 0 0 children: "Monospaced text," 0 "such as code." type: 3 ;
Map over this structure, and render your React Native or browser components in place of nodes, differentiating by type:
UpCode = 3;UpHeading = 6;UpLink = 1; // Interlink. Contains prefix, thread id and post id.UpNewline = 0; // Not a node object, just the number.UpQuote = 2;UpSpoiler = 5;UpUrl = 4;
License
MIT