feat(code): enhance markdown parse code

This commit is contained in:
tzhangchi
2022-09-15 17:19:15 +08:00
parent 59ea8b7add
commit d2f2080147
6 changed files with 344 additions and 379 deletions
@@ -5,10 +5,10 @@ import {
BlockEditor,
HTML2BlockResult,
} from '@toeverything/framework/virgo';
import { unescape } from 'html-escaper';
import {
Block2HtmlProps,
commonBlock2HtmlContent,
commonHTML2block,
} from '../../utils/commonBlockClip';
import { CodeView } from './CodeView';
@@ -34,12 +34,29 @@ export class CodeBlock extends BaseView {
element: Element;
editor: BlockEditor;
}): Promise<HTML2BlockResult> {
return commonHTML2block({
element,
editor,
type: this.type,
tagName: 'CODE',
});
// debugger;
if (element.tagName === 'CODE') {
debugger;
return [
{
type: this.type,
properties: {
text: {
value: [
{
text: unescape(
(element as HTMLElement).innerText
),
},
],
},
lang: element.classList[0].substr(9),
},
children: [],
},
];
}
return null;
}
override async block2html(props: Block2HtmlProps) {