obsidian#MarkdownPostProcessor TypeScript Examples

The following examples show how to use obsidian#MarkdownPostProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: definitionListPostProcessor.ts    From obsidian-emoji-shortcodes with MIT License 6 votes vote down vote up
// See: https://www.markdownguide.org/extended-syntax#definition-lists for reference

    static definitionListProcessor: MarkdownPostProcessor = (el: HTMLElement) => {
        let dlists: DList[] = [];
        let i = -1;

        // See: https://regex101.com/r/zLRZpC/1
        el.innerText.match(/^.+\n(?::\s.+(?:\n|$))+/gm)?.forEach((def) => {
            let lines = def.split('\n');
            lines.forEach((line, idx) => {
                if (!line.startsWith(': ')) {
                    i++
                    dlists.push({
                        title: line,
                        defs: [],
                    });
                } else if (idx !== lines.length - 1) {
                    dlists[i].defs.push(line.substring(2));
                }
            });
        });
        if(dlists.length !== 0) {
            el.empty();
            let dl =  new HTMLDListElement();
            dlists.forEach(dlist => {
                dl.appendChild(createEl('dt', {text: dlist.title}));
                dlist.defs.forEach(def => dl.appendChild(createEl('dd', {text: def})));
            });
            el.appendChild(dl);
        }
    }
Example #2
Source File: emojiPostProcessor.ts    From obsidian-emoji-shortcodes with MIT License 5 votes vote down vote up
static emojiProcessor: MarkdownPostProcessor = (el: HTMLElement) => {
		el.innerText.match(/[:][^\s:][^ \n:]*[:]/g)?.forEach((e: keyof typeof emoji) => EmojiMarkdownPostProcessor.emojiReplace(e, el)); 
	}
Example #3
Source File: main.ts    From obsidian-admonition with MIT License 5 votes vote down vote up
postprocessors: Map<string, MarkdownPostProcessor> = new Map();