refactor: add prettier and format

This commit is contained in:
Hufe921
2023-07-18 20:33:59 +08:00
parent 9c2bd33b7a
commit d464c50435
158 changed files with 3749 additions and 2265 deletions
+6 -3
View File
@@ -2,10 +2,13 @@
import Editor from '../../editor'
export interface ICopyWithCopyrightOption {
copyrightText: string;
copyrightText: string
}
export function copyWithCopyrightPlugin(editor: Editor, options?: ICopyWithCopyrightOption) {
export function copyWithCopyrightPlugin(
editor: Editor,
options?: ICopyWithCopyrightOption
) {
const copy = editor.command.executeCopy
editor.command.executeCopy = () => {
@@ -24,4 +27,4 @@ export function copyWithCopyrightPlugin(editor: Editor, options?: ICopyWithCopyr
copy()
}
}
}
}
+29 -15
View File
@@ -1,8 +1,14 @@
// 简化版markdown转IElement插件示例,代码仅为参考
import Editor, { Command, ElementType, IElement, ListType, TitleLevel } from '../../editor'
import Editor, {
Command,
ElementType,
IElement,
ListType,
TitleLevel
} from '../../editor'
export type CommandWithMarkdown = Command & {
executeInsertMarkdown(markdown: string): void;
executeInsertMarkdown(markdown: string): void
}
export const titleNodeNameMapping: Record<string, TitleLevel> = {
@@ -25,36 +31,44 @@ function convertMarkdownToElement(markdown: string): IElement[] {
type: ElementType.TITLE,
level: titleNodeNameMapping[level],
value: '',
valueList: [{
value: line.slice(level + 1)
}]
valueList: [
{
value: line.slice(level + 1)
}
]
})
} else if (line.startsWith('- ')) {
elementList.push({
type: ElementType.LIST,
listType: ListType.UL,
value: '',
valueList: [{
value: line.slice(2)
}]
valueList: [
{
value: line.slice(2)
}
]
})
} else if (/^\d+\.\s/.test(line)) {
elementList.push({
type: ElementType.LIST,
listType: ListType.OL,
value: '',
valueList: [{
value: line.replace(/^\d+\.\s/, '')
}]
valueList: [
{
value: line.replace(/^\d+\.\s/, '')
}
]
})
} else if (/^\[.*?\]\(.*?\)$/.test(line)) {
const match = line.match(/^\[(.*?)\]\((.*?)\)$/)
elementList.push({
type: ElementType.HYPERLINK,
value: '',
valueList: [{
value: match![1]
}],
valueList: [
{
value: match![1]
}
],
url: match![2]
})
} else if (/^\*\*(.*?)\*\*$/.test(line)) {
@@ -101,4 +115,4 @@ export function markdownPlugin(editor: Editor) {
const elementList = convertMarkdownToElement(markdown)
command.executeInsertElementList(elementList)
}
}
}