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