obsidian#MarkdownPreviewRenderer TypeScript Examples

The following examples show how to use obsidian#MarkdownPreviewRenderer. 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: main.ts    From obsidian-admonition with MIT License 6 votes vote down vote up
registerType(type: string) {
        /** Turn on CodeMirror syntax highlighting for this "language" */
        if (this.data.syntaxHighlight) {
            this.turnOnSyntaxHighlighting([type]);
        }

        /** Register an admonition code-block post processor for legacy support. */
        if (this.postprocessors.has(type)) {
            MarkdownPreviewRenderer.unregisterCodeBlockPostProcessor(
                `ad-${type}`
            );
        }
        this.postprocessors.set(
            type,
            this.registerMarkdownCodeBlockProcessor(
                `ad-${type}`,
                (src, el, ctx) => this.postprocessor(type, src, el, ctx)
            )
        );
        const admonition = this.admonitions[type];
        if (admonition.command) {
            this.registerCommandsFor(admonition);
        }
    }
Example #2
Source File: main.ts    From obsidian-admonition with MIT License 6 votes vote down vote up
unregisterType(admonition: Admonition) {
        if (this.data.syntaxHighlight) {
            this.turnOffSyntaxHighlighting([admonition.type]);
        }

        if (admonition.command) {
            this.unregisterCommandsFor(admonition);
        }

        if (this.postprocessors.has(admonition.type)) {
            MarkdownPreviewRenderer.unregisterPostProcessor(
                this.postprocessors.get(admonition.type)
            );
            MarkdownPreviewRenderer.unregisterCodeBlockPostProcessor(
                `ad-${admonition.type}`
            );
            this.postprocessors.delete(admonition.type);
        }
    }
Example #3
Source File: functions.ts    From obsidian-rss with GNU General Public License v3.0 5 votes vote down vote up
export function rssToMd(plugin: RssReaderPlugin, content: string): string {

    let markdown = htmlToMarkdown(content);

    //If dataview is installed
    if ((plugin.app as any).plugins.plugins["dataview"]) {
        //wrap dataview inline code
        const {
            inlineQueryPrefix,
            inlineJsQueryPrefix
        } = (plugin.app as any).plugins.plugins.dataview.api.settings as { [key: string]: string };
            markdown = markdown.replace(RegExp(`\`${escapeRegExp(inlineQueryPrefix)}.*\``, 'g'), "<pre>$&</pre>");
            markdown = markdown.replace(RegExp(`\`${escapeRegExp(inlineJsQueryPrefix)}.*\``, 'g'), "<pre>$&</pre>");
    }

    //If templater is installed
    if ((plugin.app as any).plugins.plugins["templater-obsidian"]) {
        //wrap templater commands
        markdown = markdown.replace(/<%([\s\S]*?)%>/g, "```javascript\n$&\n```");
    }

    //wrap wallabag.xml codeblocks where there is a processor registered.
    //as codeblockProcessors is not exposed publicly(and seems to be only existent after v.13) do a check first
    //@ts-ignore
    if(MarkdownPreviewRenderer.codeBlockPostProcessors) {
        //@ts-ignore
        const codeblockProcessors: string[] = Object.keys(MarkdownPreviewRenderer.codeBlockPostProcessors);
        for (const codeblockProcessor of codeblockProcessors) {
            const regex = RegExp("^```" + codeblockProcessor +"\[\\s\\S\]*?```$", "gm");
            markdown = markdown.replace(regex, "<pre>$&</pre>");
        }
    }else {
        //just remove wallabag.xml codeblocks instead
        markdown = markdown.replace(/^```.*\n([\s\S]*?)```$/gm, "<pre>$&</pre>");
    }

    if(!plugin.settings.displayMedia) {
        //remove any embeds, but keep alias
        markdown = markdown.replace(/!?\[(.*)\]\(.+\)/gm, "$1");
    }
    return markdown;
}