@blankdotpage/cake 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cake/core/runtime.d.ts +4 -1
- package/dist/cake/core/runtime.d.ts.map +1 -1
- package/dist/cake/core/runtime.js +114 -76
- package/dist/cake/extensions/index.d.ts +2 -1
- package/dist/cake/extensions/index.d.ts.map +1 -1
- package/dist/cake/extensions/index.js +3 -1
- package/dist/cake/extensions/underline/index.d.ts +2 -0
- package/dist/cake/extensions/underline/index.d.ts.map +1 -0
- package/dist/cake/extensions/underline/index.js +1 -0
- package/dist/cake/extensions/underline/underline.d.ts +2 -0
- package/dist/cake/extensions/underline/underline.d.ts.map +1 -0
- package/dist/cake/extensions/underline/underline.js +71 -0
- package/package.json +1 -1
|
@@ -115,7 +115,10 @@ export type CakeExtension = {
|
|
|
115
115
|
*/
|
|
116
116
|
toggleInline?: {
|
|
117
117
|
kind: string;
|
|
118
|
-
markers: string
|
|
118
|
+
markers: Array<string | {
|
|
119
|
+
open: string;
|
|
120
|
+
close: string;
|
|
121
|
+
}>;
|
|
119
122
|
};
|
|
120
123
|
parseBlock?: (source: string, start: number, context: ExtensionContext) => ParseBlockResult;
|
|
121
124
|
parseInline?: (source: string, start: number, end: number, context: ExtensionContext) => ParseInlineResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/cake/core/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,KAAK,EAAE,GAAG,EAAE,MAAM,EAAkB,SAAS,EAAE,MAAM,SAAS,CAAC;AACvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,6BAA6B,CAAC;AAErC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,MAAM,uBAAuB,GAAG;IAC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CAAC;IACrB,GAAG,EAAE,eAAe,CAAC;IACrB,GAAG,EAAE,GAAG,CAAC;IACT,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC;IAC3B,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,eAAe,CAAA;KAAE,CAAC;IAC9D,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC;IACjE,eAAe,CACb,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,KAAK,GAAG,UAAU,GAAG,cAAc,CAAA;KAAE,GACvD,YAAY,CAAC;IAChB,kBAAkB,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAAC;IACtE,wBAAwB,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAAC;IAC5E,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,GAAG,YAAY,CAAC;CACpE,CAAC;AAIF,wBAAgB,aAAa,CAAC,UAAU,EAAE,aAAa,EAAE,GAAG,OAAO,CAmlElE"}
|
|
@@ -38,14 +38,17 @@ export function defineExtension(extension) {
|
|
|
38
38
|
}
|
|
39
39
|
const defaultSelection = { start: 0, end: 0, affinity: "forward" };
|
|
40
40
|
export function createRuntime(extensions) {
|
|
41
|
-
const
|
|
41
|
+
const toggleMarkerToSpec = new Map();
|
|
42
42
|
for (const extension of extensions) {
|
|
43
43
|
const toggle = extension.toggleInline;
|
|
44
44
|
if (!toggle) {
|
|
45
45
|
continue;
|
|
46
46
|
}
|
|
47
47
|
for (const marker of toggle.markers) {
|
|
48
|
-
|
|
48
|
+
const spec = typeof marker === "string"
|
|
49
|
+
? { kind: toggle.kind, open: marker, close: marker }
|
|
50
|
+
: { kind: toggle.kind, open: marker.open, close: marker.close };
|
|
51
|
+
toggleMarkerToSpec.set(spec.open, spec);
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
const inclusiveAtEndByKind = new Map();
|
|
@@ -1213,53 +1216,56 @@ export function createRuntime(extensions) {
|
|
|
1213
1216
|
const selection = normalizeSelection(state.selection);
|
|
1214
1217
|
const source = state.source;
|
|
1215
1218
|
const map = state.map;
|
|
1219
|
+
const markerSpec = toggleMarkerToSpec.get(marker);
|
|
1220
|
+
if (!markerSpec) {
|
|
1221
|
+
return state;
|
|
1222
|
+
}
|
|
1223
|
+
const { kind: markerKind, open: openMarker, close: closeMarker } = markerSpec;
|
|
1224
|
+
const openLen = openMarker.length;
|
|
1225
|
+
const closeLen = closeMarker.length;
|
|
1216
1226
|
if (selection.start === selection.end) {
|
|
1217
1227
|
const caret = selection.start;
|
|
1218
|
-
const markerLen = marker.length;
|
|
1219
1228
|
// When the caret is at the end boundary of an inline wrapper, toggling the
|
|
1220
1229
|
// wrapper should "exit" it (so the next character types outside). This is
|
|
1221
1230
|
// best expressed in cursor space by flipping affinity to "forward" when we
|
|
1222
1231
|
// are leaving a wrapper of the requested kind.
|
|
1223
|
-
const
|
|
1224
|
-
if (
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
const
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
},
|
|
1251
|
-
};
|
|
1252
|
-
}
|
|
1232
|
+
const around = marksAroundCursor(state.doc, caret);
|
|
1233
|
+
if (isMarksPrefix(around.right, around.left) &&
|
|
1234
|
+
around.left.length > around.right.length) {
|
|
1235
|
+
const exiting = around.left.slice(around.right.length);
|
|
1236
|
+
if (exiting.some((mark) => mark.kind === markerKind)) {
|
|
1237
|
+
if (exiting.length > 1) {
|
|
1238
|
+
const placeholder = "\u200B";
|
|
1239
|
+
const insertAtForward = map.cursorToSource(caret, "forward");
|
|
1240
|
+
const insertAtBackward = map.cursorToSource(caret, "backward");
|
|
1241
|
+
const between = source.slice(insertAtBackward, insertAtForward);
|
|
1242
|
+
const markerIndex = between.indexOf(closeMarker);
|
|
1243
|
+
if (markerIndex !== -1) {
|
|
1244
|
+
const insertAt = insertAtBackward + markerIndex + closeLen;
|
|
1245
|
+
const nextSource = source.slice(0, insertAt) +
|
|
1246
|
+
placeholder +
|
|
1247
|
+
source.slice(insertAt);
|
|
1248
|
+
const next = createState(nextSource);
|
|
1249
|
+
const placeholderStart = insertAt;
|
|
1250
|
+
const startCursor = next.map.sourceToCursor(placeholderStart, "forward");
|
|
1251
|
+
return {
|
|
1252
|
+
...next,
|
|
1253
|
+
selection: {
|
|
1254
|
+
start: startCursor.cursorOffset,
|
|
1255
|
+
end: startCursor.cursorOffset,
|
|
1256
|
+
affinity: "forward",
|
|
1257
|
+
},
|
|
1258
|
+
};
|
|
1253
1259
|
}
|
|
1254
|
-
return {
|
|
1255
|
-
...state,
|
|
1256
|
-
selection: {
|
|
1257
|
-
start: caret,
|
|
1258
|
-
end: caret,
|
|
1259
|
-
affinity: "forward",
|
|
1260
|
-
},
|
|
1261
|
-
};
|
|
1262
1260
|
}
|
|
1261
|
+
return {
|
|
1262
|
+
...state,
|
|
1263
|
+
selection: {
|
|
1264
|
+
start: caret,
|
|
1265
|
+
end: caret,
|
|
1266
|
+
affinity: "forward",
|
|
1267
|
+
},
|
|
1268
|
+
};
|
|
1263
1269
|
}
|
|
1264
1270
|
}
|
|
1265
1271
|
// Otherwise, insert an empty marker pair with a zero-width placeholder
|
|
@@ -1287,17 +1293,17 @@ export function createRuntime(extensions) {
|
|
|
1287
1293
|
map.cursorToSource(caret, selection.affinity ?? "forward");
|
|
1288
1294
|
const nextSource = placeholderPos !== null
|
|
1289
1295
|
? source.slice(0, insertAt) +
|
|
1290
|
-
|
|
1296
|
+
openMarker +
|
|
1291
1297
|
placeholder +
|
|
1292
|
-
|
|
1298
|
+
closeMarker +
|
|
1293
1299
|
source.slice(insertAt + placeholder.length)
|
|
1294
1300
|
: source.slice(0, insertAt) +
|
|
1295
|
-
|
|
1301
|
+
openMarker +
|
|
1296
1302
|
placeholder +
|
|
1297
|
-
|
|
1303
|
+
closeMarker +
|
|
1298
1304
|
source.slice(insertAt);
|
|
1299
1305
|
const next = createState(nextSource);
|
|
1300
|
-
const placeholderStart = insertAt +
|
|
1306
|
+
const placeholderStart = insertAt + openLen;
|
|
1301
1307
|
const startCursor = next.map.sourceToCursor(placeholderStart, "forward");
|
|
1302
1308
|
return {
|
|
1303
1309
|
...next,
|
|
@@ -1313,18 +1319,13 @@ export function createRuntime(extensions) {
|
|
|
1313
1319
|
const from = map.cursorToSource(cursorStart, "forward");
|
|
1314
1320
|
const to = map.cursorToSource(cursorEnd, "backward");
|
|
1315
1321
|
const selectedText = source.slice(from, to);
|
|
1316
|
-
const markerLen = marker.length;
|
|
1317
|
-
const markerKind = toggleMarkerToKind.get(marker) ?? null;
|
|
1318
1322
|
const linesForSelection = flattenDocToLines(state.doc);
|
|
1319
|
-
const commonMarks =
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
const hasCommonMark = markerKind !== null && commonMarks.some((mark) => mark.kind === markerKind);
|
|
1323
|
-
const canUnwrap = markerKind ? hasCommonMark : true;
|
|
1323
|
+
const commonMarks = commonMarksAcrossSelection(linesForSelection, cursorStart, cursorEnd, state.doc);
|
|
1324
|
+
const hasCommonMark = commonMarks.some((mark) => mark.kind === markerKind);
|
|
1325
|
+
const canUnwrap = hasCommonMark;
|
|
1324
1326
|
const startLoc = resolveCursorToLine(linesForSelection, cursorStart);
|
|
1325
1327
|
const endLoc = resolveCursorToLine(linesForSelection, cursorEnd);
|
|
1326
|
-
if (
|
|
1327
|
-
(startLoc.lineIndex !== endLoc.lineIndex || selectedText.includes("\n"))) {
|
|
1328
|
+
if (startLoc.lineIndex !== endLoc.lineIndex || selectedText.includes("\n")) {
|
|
1328
1329
|
const edits = [];
|
|
1329
1330
|
const segments = (() => {
|
|
1330
1331
|
if (!selectedText.includes("\n")) {
|
|
@@ -1375,25 +1376,25 @@ export function createRuntime(extensions) {
|
|
|
1375
1376
|
const segmentFrom = segment.from;
|
|
1376
1377
|
const segmentTo = segment.to;
|
|
1377
1378
|
if (canUnwrap) {
|
|
1378
|
-
if (segmentFrom >=
|
|
1379
|
-
source.slice(segmentFrom -
|
|
1379
|
+
if (segmentFrom >= openLen &&
|
|
1380
|
+
source.slice(segmentFrom - openLen, segmentFrom) === openMarker) {
|
|
1380
1381
|
edits.push({
|
|
1381
|
-
from: segmentFrom -
|
|
1382
|
+
from: segmentFrom - openLen,
|
|
1382
1383
|
to: segmentFrom,
|
|
1383
1384
|
insert: "",
|
|
1384
1385
|
});
|
|
1385
1386
|
}
|
|
1386
|
-
if (source.slice(segmentTo, segmentTo +
|
|
1387
|
+
if (source.slice(segmentTo, segmentTo + closeLen) === closeMarker) {
|
|
1387
1388
|
edits.push({
|
|
1388
1389
|
from: segmentTo,
|
|
1389
|
-
to: segmentTo +
|
|
1390
|
+
to: segmentTo + closeLen,
|
|
1390
1391
|
insert: "",
|
|
1391
1392
|
});
|
|
1392
1393
|
}
|
|
1393
1394
|
}
|
|
1394
1395
|
else {
|
|
1395
|
-
edits.push({ from: segmentFrom, to: segmentFrom, insert:
|
|
1396
|
-
edits.push({ from: segmentTo, to: segmentTo, insert:
|
|
1396
|
+
edits.push({ from: segmentFrom, to: segmentFrom, insert: openMarker });
|
|
1397
|
+
edits.push({ from: segmentTo, to: segmentTo, insert: closeMarker });
|
|
1397
1398
|
}
|
|
1398
1399
|
}
|
|
1399
1400
|
if (edits.length === 0) {
|
|
@@ -1417,33 +1418,70 @@ export function createRuntime(extensions) {
|
|
|
1417
1418
|
},
|
|
1418
1419
|
};
|
|
1419
1420
|
}
|
|
1420
|
-
const isSelectionWrappedByAdjacentMarkers =
|
|
1421
|
-
from
|
|
1422
|
-
source.slice(
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
selectedText.
|
|
1426
|
-
selectedText.length >= markerLen * 2;
|
|
1421
|
+
const isSelectionWrappedByAdjacentMarkers = from >= openLen &&
|
|
1422
|
+
source.slice(from - openLen, from) === openMarker &&
|
|
1423
|
+
source.slice(to, to + closeLen) === closeMarker;
|
|
1424
|
+
const isWrappedBySelectionText = selectedText.startsWith(openMarker) &&
|
|
1425
|
+
selectedText.endsWith(closeMarker) &&
|
|
1426
|
+
selectedText.length >= openLen + closeLen;
|
|
1427
1427
|
const isWrapped = canUnwrap &&
|
|
1428
|
-
(isSelectionWrappedByAdjacentMarkers ||
|
|
1429
|
-
(markerKind ? isWrappedBySelectionText : isWrappedBySelectionText));
|
|
1428
|
+
(isSelectionWrappedByAdjacentMarkers || isWrappedBySelectionText);
|
|
1430
1429
|
let newSource;
|
|
1431
|
-
if (isWrapped) {
|
|
1430
|
+
if (canUnwrap && !isWrapped) {
|
|
1431
|
+
const edits = [];
|
|
1432
|
+
const startBackward = map.cursorToSource(cursorStart, "backward");
|
|
1433
|
+
const startForward = map.cursorToSource(cursorStart, "forward");
|
|
1434
|
+
const endBackward = map.cursorToSource(cursorEnd, "backward");
|
|
1435
|
+
const endForward = map.cursorToSource(cursorEnd, "forward");
|
|
1436
|
+
const startGap = source.slice(startBackward, startForward);
|
|
1437
|
+
const openIndex = startGap.lastIndexOf(openMarker);
|
|
1438
|
+
if (openIndex !== -1) {
|
|
1439
|
+
edits.push({
|
|
1440
|
+
from: startBackward + openIndex,
|
|
1441
|
+
to: startBackward + openIndex + openLen,
|
|
1442
|
+
insert: "",
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
else {
|
|
1446
|
+
edits.push({ from: startBackward, to: startBackward, insert: closeMarker });
|
|
1447
|
+
}
|
|
1448
|
+
const endGap = source.slice(endBackward, endForward);
|
|
1449
|
+
const closeIndex = endGap.indexOf(closeMarker);
|
|
1450
|
+
if (closeIndex !== -1) {
|
|
1451
|
+
edits.push({
|
|
1452
|
+
from: endBackward + closeIndex,
|
|
1453
|
+
to: endBackward + closeIndex + closeLen,
|
|
1454
|
+
insert: "",
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
else {
|
|
1458
|
+
edits.push({ from: endForward, to: endForward, insert: openMarker });
|
|
1459
|
+
}
|
|
1460
|
+
edits.sort((a, b) => b.from - a.from);
|
|
1461
|
+
newSource = source;
|
|
1462
|
+
for (const edit of edits) {
|
|
1463
|
+
newSource =
|
|
1464
|
+
newSource.slice(0, edit.from) +
|
|
1465
|
+
edit.insert +
|
|
1466
|
+
newSource.slice(edit.to);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
else if (isWrapped) {
|
|
1432
1470
|
// Unwrap
|
|
1433
1471
|
if (isSelectionWrappedByAdjacentMarkers) {
|
|
1434
1472
|
newSource =
|
|
1435
|
-
source.slice(0, from -
|
|
1473
|
+
source.slice(0, from - openLen) +
|
|
1436
1474
|
selectedText +
|
|
1437
|
-
source.slice(to +
|
|
1475
|
+
source.slice(to + closeLen);
|
|
1438
1476
|
}
|
|
1439
1477
|
else {
|
|
1440
|
-
const unwrapped = selectedText.slice(
|
|
1478
|
+
const unwrapped = selectedText.slice(openLen, -closeLen);
|
|
1441
1479
|
newSource = source.slice(0, from) + unwrapped + source.slice(to);
|
|
1442
1480
|
}
|
|
1443
1481
|
}
|
|
1444
1482
|
else {
|
|
1445
1483
|
// Wrap
|
|
1446
|
-
const wrapped =
|
|
1484
|
+
const wrapped = openMarker + selectedText + closeMarker;
|
|
1447
1485
|
newSource = source.slice(0, from) + wrapped + source.slice(to);
|
|
1448
1486
|
}
|
|
1449
1487
|
const next = createState(newSource);
|
|
@@ -8,7 +8,8 @@ import { imageExtension } from "./image/image";
|
|
|
8
8
|
import { plainTextListExtension } from "./list/list";
|
|
9
9
|
import { scrollbarExtension } from "./scrollbar";
|
|
10
10
|
import { strikethroughExtension } from "./strikethrough/strikethrough";
|
|
11
|
-
|
|
11
|
+
import { underlineExtension } from "./underline/underline";
|
|
12
|
+
export { boldExtension, combinedEmphasisExtension, linkExtension, blockquoteExtension, italicExtension, headingExtension, imageExtension, plainTextListExtension, scrollbarExtension, strikethroughExtension, underlineExtension, };
|
|
12
13
|
export declare const bundledExtensionsWithoutImage: import("../..").CakeExtension[];
|
|
13
14
|
export declare const bundledExtensions: import("../..").CakeExtension[];
|
|
14
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cake/extensions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cake/extensions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EACL,aAAa,EACb,yBAAyB,EACzB,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,GACnB,CAAC;AAEF,eAAO,MAAM,6BAA6B,iCAUzC,CAAC;AAEF,eAAO,MAAM,iBAAiB,iCAG7B,CAAC"}
|
|
@@ -8,7 +8,8 @@ import { imageExtension } from "./image/image";
|
|
|
8
8
|
import { plainTextListExtension } from "./list/list";
|
|
9
9
|
import { scrollbarExtension } from "./scrollbar";
|
|
10
10
|
import { strikethroughExtension } from "./strikethrough/strikethrough";
|
|
11
|
-
|
|
11
|
+
import { underlineExtension } from "./underline/underline";
|
|
12
|
+
export { boldExtension, combinedEmphasisExtension, linkExtension, blockquoteExtension, italicExtension, headingExtension, imageExtension, plainTextListExtension, scrollbarExtension, strikethroughExtension, underlineExtension, };
|
|
12
13
|
export const bundledExtensionsWithoutImage = [
|
|
13
14
|
blockquoteExtension,
|
|
14
15
|
headingExtension,
|
|
@@ -17,6 +18,7 @@ export const bundledExtensionsWithoutImage = [
|
|
|
17
18
|
boldExtension,
|
|
18
19
|
italicExtension,
|
|
19
20
|
strikethroughExtension,
|
|
21
|
+
underlineExtension,
|
|
20
22
|
linkExtension,
|
|
21
23
|
];
|
|
22
24
|
export const bundledExtensions = [
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/underline/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./underline";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"underline.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/underline/underline.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,kBAAkB,kCAyE7B,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { defineExtension, } from "../../core/runtime";
|
|
2
|
+
import { CursorSourceBuilder } from "../../core/mapping/cursor-source-map";
|
|
3
|
+
const UNDERLINE_KIND = "underline";
|
|
4
|
+
export const underlineExtension = defineExtension({
|
|
5
|
+
name: "underline",
|
|
6
|
+
toggleInline: { kind: UNDERLINE_KIND, markers: [{ open: "<u>", close: "</u>" }] },
|
|
7
|
+
keybindings: [
|
|
8
|
+
{ key: "u", meta: true, shift: false, command: { type: "toggle-underline" } },
|
|
9
|
+
{ key: "u", ctrl: true, shift: false, command: { type: "toggle-underline" } },
|
|
10
|
+
],
|
|
11
|
+
inlineWrapperAffinity: [{ kind: UNDERLINE_KIND, inclusive: true }],
|
|
12
|
+
onEdit(command) {
|
|
13
|
+
if (command.type === "toggle-underline") {
|
|
14
|
+
return { type: "toggle-inline", marker: "<u>" };
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
},
|
|
18
|
+
parseInline(source, start, end, context) {
|
|
19
|
+
if (source.slice(start, start + 3) !== "<u>") {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const close = source.indexOf("</u>", start + 3);
|
|
23
|
+
if (close === -1 || close >= end) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const children = context.parseInline(source, start + 3, close);
|
|
27
|
+
return {
|
|
28
|
+
inline: {
|
|
29
|
+
type: "inline-wrapper",
|
|
30
|
+
kind: UNDERLINE_KIND,
|
|
31
|
+
children,
|
|
32
|
+
},
|
|
33
|
+
nextPos: close + 4,
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
serializeInline(inline, context) {
|
|
37
|
+
if (inline.type !== "inline-wrapper" || inline.kind !== UNDERLINE_KIND) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const builder = new CursorSourceBuilder();
|
|
41
|
+
builder.appendSourceOnly("<u>");
|
|
42
|
+
for (const child of inline.children) {
|
|
43
|
+
const serialized = context.serializeInline(child);
|
|
44
|
+
builder.appendSerialized(serialized);
|
|
45
|
+
}
|
|
46
|
+
builder.appendSourceOnly("</u>");
|
|
47
|
+
return builder.build();
|
|
48
|
+
},
|
|
49
|
+
normalizeInline(inline) {
|
|
50
|
+
if (inline.type !== "inline-wrapper" || inline.kind !== UNDERLINE_KIND) {
|
|
51
|
+
return inline;
|
|
52
|
+
}
|
|
53
|
+
if (inline.children.length === 0) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return inline;
|
|
57
|
+
},
|
|
58
|
+
renderInline(inline, context) {
|
|
59
|
+
if (inline.type !== "inline-wrapper" || inline.kind !== UNDERLINE_KIND) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const element = document.createElement("u");
|
|
63
|
+
element.className = "cake-underline";
|
|
64
|
+
for (const child of inline.children) {
|
|
65
|
+
for (const node of context.renderInline(child)) {
|
|
66
|
+
element.append(node);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return element;
|
|
70
|
+
},
|
|
71
|
+
});
|