update: codeblock alias

This commit is contained in:
yanmao 2022-01-06 15:54:28 +08:00
parent 9eb31b8302
commit 6f2a68d0b0
2 changed files with 11 additions and 6 deletions

View File

@ -88,10 +88,11 @@ export default class<
markdown(event: KeyboardEvent) {
if (!isEngine(this.editor) || this.options.markdown === false) return;
const { change, node, command } = this.editor;
const blockApi = this.editor.block;
const range = change.range.get();
if (!range.collapsed || change.isComposing() || !this.markdown) return;
const blockApi = this.editor.block;
const block = blockApi.closest(range.startNode);
if (!node.isRootBlock(block)) {
@ -249,12 +250,13 @@ export default class<
const { card } = this.editor;
let newText = '';
const nameMaps: { [key: string]: string } = {};
const nameMaps = {};
CodeBlockComponent.getModes().forEach((item) => {
nameMaps[item.value] = item.name;
});
const langs = Object.keys(nameMaps)
.concat(Object.keys(MODE_ALIAS))
.concat(Object.keys(this.options.alias || {}))
.sort((a, b) => (a.length > b.length ? -1 : 1));
const createCodeblock = (
@ -304,7 +306,8 @@ export default class<
match[1].indexOf(mode) === 0
? match[1].substr(mode.length + 1)
: match[1];
mode = MODE_ALIAS[mode] || mode;
const alias = { ...(this.options.alias || {}), ...MODE_ALIAS };
mode = alias[mode] || mode;
nodes.push(code);
} else if (isCode) {
nodes.push(row);
@ -322,7 +325,7 @@ export default class<
if (isServer) return;
root.find(
`[${CARD_KEY}="${CodeBlockComponent.cardName}"],[${READY_CARD_KEY}="${CodeBlockComponent.cardName}]"`,
`[${CARD_KEY}="${CodeBlockComponent.cardName}"],[${READY_CARD_KEY}="${CodeBlockComponent.cardName}"]`,
).each((cardNode) => {
const node = $(cardNode);
const card = this.editor.card.find(
@ -331,7 +334,7 @@ export default class<
const value =
card?.getValue() ||
decodeCardValue(node.attributes(CARD_VALUE_KEY));
if (value && value.code) {
if (value) {
node.empty();
const synatxMap: { [key: string]: string } = {};
CodeBlockComponent.getModes().forEach((item) => {

View File

@ -256,6 +256,7 @@ export default class<
});
const langs = Object.keys(nameMaps)
.concat(Object.keys(MODE_ALIAS))
.concat(Object.keys(this.options.alias || {}))
.sort((a, b) => (a.length > b.length ? -1 : 1));
const createCodeblock = (
@ -305,7 +306,8 @@ export default class<
match[1].indexOf(mode) === 0
? match[1].substr(mode.length + 1)
: match[1];
mode = MODE_ALIAS[mode] || mode;
const alias = { ...(this.options.alias || {}), ...MODE_ALIAS };
mode = alias[mode] || mode;
nodes.push(code);
} else if (isCode) {
nodes.push(row);