mirror of
https://github.com/danbulant/Nertivia-Client
synced 2026-07-05 19:10:52 +00:00
removed inline fence
This commit is contained in:
parent
73d7742854
commit
26d1c3f11b
2 changed files with 28 additions and 69 deletions
|
|
@ -1,44 +0,0 @@
|
||||||
function parseInlineFence(state, silent) {
|
|
||||||
let pos = state.pos
|
|
||||||
let max = state.posMax
|
|
||||||
let src = state.src.slice(pos, max)
|
|
||||||
|
|
||||||
if(pos + 6 > max || state.src.charCodeAt(pos) !== 0x60) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(!src.startsWith('```') || !src.endsWith('```')) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
pos += 3
|
|
||||||
|
|
||||||
const marker = state.src.slice(state.pos, pos);
|
|
||||||
|
|
||||||
let matchEnd = pos
|
|
||||||
let matchStart = pos
|
|
||||||
while ((matchStart = state.src.indexOf('```', matchEnd)) !== -1) {
|
|
||||||
console.log(matchStart, state)
|
|
||||||
matchEnd = matchStart + 1
|
|
||||||
|
|
||||||
if(!silent) {
|
|
||||||
const token = state.push('fence', 'code', 0)
|
|
||||||
token.markup = marker
|
|
||||||
token.content = state.src.slice(pos, matchStart)
|
|
||||||
.replace(/\n/g, ' ')
|
|
||||||
.replace(/^ (.+) $/, '$1');
|
|
||||||
}
|
|
||||||
state.pos = matchEnd + 2
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!silent) {
|
|
||||||
state.pending += marker
|
|
||||||
}
|
|
||||||
state.pos += 3
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
export default function inlineFence(md, opts) {
|
|
||||||
md.inline.ruler.before('backticks', 'inline_fence', parseInlineFence)
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +1,48 @@
|
||||||
import twemoji from 'twemoji'
|
import twemoji from "twemoji";
|
||||||
import emojiParser from '@/utils/emojiParser';
|
import emojiParser from "@/utils/emojiParser";
|
||||||
import config from "@/config.js";
|
import config from "@/config.js";
|
||||||
|
|
||||||
import customEmoji from './markdown-it-plugins/customEmoji'
|
import customEmoji from "./markdown-it-plugins/customEmoji";
|
||||||
import formatLink from './markdown-it-plugins/formatLink'
|
import formatLink from "./markdown-it-plugins/formatLink";
|
||||||
import formatCode from './markdown-it-plugins/formatCode'
|
import formatCode from "./markdown-it-plugins/formatCode";
|
||||||
import normalizeFence from './markdown-it-plugins/normalizeFence'
|
import normalizeFence from "./markdown-it-plugins/normalizeFence";
|
||||||
import inlineFence from './markdown-it-plugins/inlineFence'
|
|
||||||
|
|
||||||
import hljs from 'highlight.js'
|
import hljs from "highlight.js";
|
||||||
|
|
||||||
import MarkdownIt from 'markdown-it'
|
import MarkdownIt from "markdown-it";
|
||||||
import chatPlugin from 'markdown-it-chat-formatter/dist-src/plugin'
|
import chatPlugin from "markdown-it-chat-formatter/dist-src/plugin";
|
||||||
|
|
||||||
const markdown = new MarkdownIt({
|
const markdown = new MarkdownIt({
|
||||||
highlight: function (str, lang) {
|
highlight: function(str, lang) {
|
||||||
if (lang && hljs.getLanguage(lang)) {
|
if (lang && hljs.getLanguage(lang)) {
|
||||||
try {
|
try {
|
||||||
return '<div class="codeblock"><code>' +
|
return (
|
||||||
hljs.highlight(lang, str, true).value +
|
'<div class="codeblock"><code>' +
|
||||||
'</code></div>';
|
hljs.highlight(lang, str, true).value +
|
||||||
|
"</code></div>"
|
||||||
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return '<div class="codeblock"><code>' + markdown.utils.escapeHtml(str) + '</code></div>';
|
return (
|
||||||
|
'<div class="codeblock"><code>' +
|
||||||
|
markdown.utils.escapeHtml(str) +
|
||||||
|
"</code></div>"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.use(normalizeFence)
|
.use(normalizeFence)
|
||||||
.use(chatPlugin)
|
.use(chatPlugin)
|
||||||
.use(customEmoji)
|
.use(customEmoji)
|
||||||
.use(formatLink)
|
.use(formatLink)
|
||||||
.use(formatCode)
|
.use(formatCode);
|
||||||
.use(inlineFence)
|
|
||||||
|
|
||||||
export default (message) => {
|
export default message => {
|
||||||
|
message = markdown.render(message).trim();
|
||||||
|
|
||||||
message = markdown.render(message).trim();
|
message = emojiParser.replaceEmojis(message);
|
||||||
|
|
||||||
message = emojiParser.replaceEmojis(message);
|
return message;
|
||||||
|
};
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue