我在使用 libarymarkdown-it
和 parse markdown-it 时遇到问题。我希望我的 formatText\\my_text\\
可以更改为斜体。基于 markdown-it 当文本想要更改斜体时使用*italicized text*
。\\my_text\\
使用库markdown-it或解析其他多种格式的文本时,如何更改文本的格式我的意思是解析为斜体
//my code markdown-it , use mixin vue
const MarkdownIt = require('markdown-it')
const md = new MarkdownIt({
html: true,
linkify: true,
typographer: true
});
export default {
methods: {
marked(payload: string): string {
if (payload) return this.parse(md.render(payload));
return "";
},
parse(payload: string, type: any = "") {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(payload, "text/html");
const links = htmlDoc.querySelectorAll("a");
links.forEach(link => {
link.setAttribute("target", "_blank");
link.classList.add(
"hover:underline",
"hover:text-orange",
"text-indigo-200"
);
});
if (type === "commentTask") {
const divs = htmlDoc.querySelectorAll(
".phabricator-remarkup-embed-layout-link"
);
divs.forEach(div => {
const url = div.attributes.item(0)?.value;
div.classList.add("border", "border-red-300", "p-2", "w-72", "mt-2");
const spans = div.querySelectorAll(
".phabricator-remarkup-embed-layout-name"
);
spans.forEach(span => {
const newA = htmlDoc.createElement("a");
newA.classList.add("hover:text-orange", "mr-1", "pr-1");
newA.innerHTML = span.innerHTML;
newA.setAttribute("href", url as string);
newA.setAttribute("target", "_blank");
span.innerHTML = "";
span.appendChild(newA);
});
const as = div.querySelectorAll(
".phabricator-remarkup-embed-layout-download"
);
as.forEach(a => {
a.classList.add("ml-2");
a.removeAttribute("target");
});
});
}
return htmlDoc.documentElement.innerHTML;
}
}
};
<!-- my code use vueJS, Vuejs mixins-->
<div
id="vue-html"
class="text-sm p-4 overflow-y-auto text-black border-2 mt-3"
style="max-height: 30rem"
v-html="marked(data)"
/>