# All files / src/lib/markdown-it/patches/custom-component customComponentPlugin.js

50% Statements 4/8
100% Branches 0/0
0% Functions 0/2
50% Lines 4/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47

    7x

    7x
    7x

    7x

     /*
     * https://github.com/vuepress/vuepress-next/tree/main/packages/%40vuepress/markdown/src/plugins/customComponentPlugin
     *
     * The files in this folder, custom-component, are adapted from the above link to fit MarkBind's needs.
     *
     * It helps us to define Vue custom components (or unknown components) as block or inline elements
     * elements during markdown-it parsing. It also helps us to define special tags to ignore such as
     * <include>, <script>, <style>.
     */

    const markdownIt = require('../../index');

    const initCustomComponentHtmlBlockRule = require('./htmlBlockRule');
    const htmlInlineRule = require('./htmlInlineRule');

    /*
     * MODIFIED (MarkBind): tweaked customComponentPlugin function and added injectTags function
     * to accomodate ignoring special tags capability
     */

    /**
     * Replacing the default htmlBlock rule to allow using custom components in markdown
     */
    function customComponentPlugin(md, tagsToIgnore) {
      const customComponentHtmlBlockRule = initCustomComponentHtmlBlockRule(tagsToIgnore);

      // override default html block ruler
      md.block.ruler.at('html_block', customComponentHtmlBlockRule, {
        alt: ['paragraph', 'reference', 'blockquote'],
      });

      // override default html inline ruler
      md.inline.ruler.at('html_inline', htmlInlineRule);
    };

    /**
     * Sets up the plugin with the provided tag names to ignore.
     * Replaces any previously injected tags.
     */
    function injectTags(tagsToIgnore) {
      markdownIt.use(customComponentPlugin, tagsToIgnore);
    }

    module.exports = {
      injectTags,
    };