Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

markdown-it渲染规则配置失效 #305

Closed
BlueflameLi opened this issue Jun 20, 2023 · 4 comments
Closed

markdown-it渲染规则配置失效 #305

BlueflameLi opened this issue Jun 20, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@BlueflameLi
Copy link

描述这个Bug

我使用了markdown-it的自定义渲染规则来实现一些自定义的语法,但从4.0.3开始的版本就失效了,并且我使用的是nuxt3,在服务端渲染的时候还会出现许多水合错误,而这在4.0.2版本及以前都没有问题的
Snipaste_2023-06-20_20-55-45
Snipaste_2023-06-20_21-03-20

版本号

4.0.3及以上

问题重现链接

No response

@imzbf
Copy link
Owner

imzbf commented Jun 20, 2023

这边在这个示例中尝试好像没有类似的提示。

方便的提供一下你的扩展代码,和一个还原你问题的环境

@BlueflameLi
Copy link
Author

我这边是重定义了blockquote_open和blockquote_close的规则,我刚刚测试了一下,似乎是4.0.3版本之后我自定义的blockquote_open规则被覆盖了,而blockquote_close没被覆盖,nuxt的水合错误应该是重定义的blockquote_close规则替换了</blockquote>标签,而blockquote_open因为失效没成功替换<blockquote>,标签不匹配导致的,可以先忽略nuxt的问题

修改示例中app.vue的代码如下可以复现

<template>
    <MdPreview :model-value="text" />
</template>

<script setup>
import { ref } from 'vue';
import { MdPreview, config } from 'md-editor-v3';
import 'md-editor-v3/lib/style.css';

const text = ref('> test');
config({
    markdownItConfig(mdit) {
        mdit.renderer.rules.blockquote_open = (tokens, idx) => {
            console.log("blockquote_open")
            return '<blockquote>'
        }

        mdit.renderer.rules.blockquote_close = (tokens, idx) => {
            console.log("blockquote_close")
            console.log(tokens)
            return '</blockquote>'
        }
    },
})
</script>

Snipaste_2023-06-20_23-26-00
上图为最新版的输出,下图为4.0.2版本时的输出
Snipaste_2023-06-20_23-27-36

@imzbf imzbf added the bug Something isn't working label Jun 25, 2023
@imzbf imzbf self-assigned this Jun 25, 2023
@imzbf
Copy link
Owner

imzbf commented Jun 25, 2023

我在beta中修复了这个问题,现在可以通过一下方式尝试

yarn add md-editor-v3@beta

正式版会在其它问题修复后一起更新。

@BlueflameLi
Copy link
Author

非常感谢,测试版中没问题了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants