mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 11:06:25 +08:00
feat(code): enhance markdown parse code
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import {
|
||||
BaseView,
|
||||
CreateView,
|
||||
AsyncBlock,
|
||||
HTML2BlockResult,
|
||||
BlockEditor,
|
||||
} from '@toeverything/framework/virgo';
|
||||
import { Protocol } from '@toeverything/datasource/db-service';
|
||||
import { TextView } from './TextView';
|
||||
import {
|
||||
AsyncBlock,
|
||||
BaseView,
|
||||
BlockEditor,
|
||||
CreateView,
|
||||
HTML2BlockResult,
|
||||
} from '@toeverything/framework/virgo';
|
||||
import {
|
||||
Block2HtmlProps,
|
||||
commonBlock2HtmlContent,
|
||||
commonHTML2block,
|
||||
} from '../../utils/commonBlockClip';
|
||||
import { TextView } from './TextView';
|
||||
|
||||
export class TextBlock extends BaseView {
|
||||
type = Protocol.Block.Type.text;
|
||||
@@ -41,12 +41,12 @@ export class TextBlock extends BaseView {
|
||||
tagName: [
|
||||
'DIV',
|
||||
'P',
|
||||
'PRE',
|
||||
// 'PRE',
|
||||
'B',
|
||||
'A',
|
||||
'EM',
|
||||
'U',
|
||||
'CODE',
|
||||
// 'CODE',
|
||||
'S',
|
||||
'DEL',
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user