nuxt-modules / mdc

MDC supercharges regular Markdown to write documents interacting deeply with any Vue component.
MIT License
195 stars 22 forks source link

How to disable some markdown syntax? Indented Code Blocks #181

Open soylomass opened 6 months ago

soylomass commented 6 months ago

Is there any way to disable specific markdown syntax? In my case, I need to disable indented code blocks, leaving only fenced code blocks. Is it possible?

soylomass commented 6 months ago
function disableIndentedCode() {
    const data = this.data();
    add("micromarkExtensions", {
      disable: { null: ["codeIndented"] },
    });

    /**
     * @param {string} field
     * @param {unknown} value
     */
    function add(field, value) {
      const list /** @type {Array<unknown>} */ =
        // Other extensions
        /* c8 ignore next 2 */
        data[field] ? data[field] : (data[field] = []);

      list.push(value);
    }
  }

  const parserOptions = {
    remark: {
      plugins: {
        ["disable-indented-code"]: {
          instance: disableIndentedCode,
        },
      },
    },
  };

    <MDC
      :value="element.text"
      class="markdown-body"
      :parser-options="parserOptions"
    />

Tried with this solution, but it breaks the rendering of the strings where said syntax is included (the whole string is not rendered). Strings without said syntax are rendered normally.

farnabaz commented 6 months ago

Disabling core markdown features is out of the module's scope. I suggest creating a discussion in micromark since it is related to micromark. I'm not sure that you can disable indented code blocks.