markdown对标签的处理问题(回车会渲染br标签,表格属性缺失)
redshade opened this issue · comments
haolei commented
示例项目:
GreatZP commented
关于表格样式的配置,可以参考xss配置的demo放开对应样式即可
<template>
<d-editor-md v-model="content" :custom-renderer-rules="customRendererRules" :custom-xss-rules="customRenderRules"></d-editor-md>
</template>
<script>
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const content = ref('[link](#test)\n<kbd>kbd 标签渲染</kbd>');
// 关于自定义XSS规则的处理
const customRenderRules = ref([
{
key: 'kbd',
value: [], // 为空表示过滤所有属性,放开属性则添加对应项,如['id', 'style']
},
])
const customRendererRules = ref([
{
key: 'link_open',
value: function (tokens, idx, opts, env, self) {
const defaultRender = function (nTokens, index, options, ev, that) {
return that.renderToken(nTokens, index, options);
};
const token = tokens[idx];
const attrs = token.attrs;
const hrefIndex = token.attrIndex('href');
const href = attrs[hrefIndex][1];
if (typeof window !== 'undefined') {
attrs[hrefIndex][1] = location.href + href;
}
token.attrPush(['target', '_blank']);
token.attrPush(['id', href]);
return defaultRender(tokens, idx, opts, env, self);
},
},
]);
return { content, customRendererRules, customRenderRules };
},
});
</script>
GreatZP commented
关于场景一,可以设置组件breaks参数为false(默认值为true)即可:
<template>
<d-editor-md v-model="content" :breaks="false"></d-editor-md>
</template>