roosterjs-content-model-plugins 9.9.0 → 9.9.1
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/lib/autoFormat/numbers/transformOrdinals.d.ts +1 -2
- package/lib/autoFormat/numbers/transformOrdinals.js +16 -5
- package/lib/autoFormat/numbers/transformOrdinals.js.map +1 -1
- package/lib/markdown/utils/setFormat.js +14 -4
- package/lib/markdown/utils/setFormat.js.map +1 -1
- package/lib-amd/autoFormat/numbers/transformOrdinals.d.ts +1 -2
- package/lib-amd/autoFormat/numbers/transformOrdinals.js +16 -5
- package/lib-amd/autoFormat/numbers/transformOrdinals.js.map +1 -1
- package/lib-amd/markdown/utils/setFormat.js +14 -4
- package/lib-amd/markdown/utils/setFormat.js.map +1 -1
- package/lib-mjs/autoFormat/numbers/transformOrdinals.d.ts +1 -2
- package/lib-mjs/autoFormat/numbers/transformOrdinals.js +16 -5
- package/lib-mjs/autoFormat/numbers/transformOrdinals.js.map +1 -1
- package/lib-mjs/markdown/utils/setFormat.js +14 -4
- package/lib-mjs/markdown/utils/setFormat.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ContentModelText, FormatContentModelContext, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
|
-
*/
|
|
5
|
-
export declare function transformOrdinals(previousSegment: ContentModelText, paragraph: ShallowMutableContentModelParagraph, context: FormatContentModelContext): boolean;
|
|
4
|
+
*/ export declare function transformOrdinals(previousSegment: ContentModelText, paragraph: ShallowMutableContentModelParagraph, context: FormatContentModelContext): boolean;
|
|
@@ -11,15 +11,18 @@ var getOrdinal = function (value) {
|
|
|
11
11
|
return ORDINALS[value] || 'th';
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* The two last characters of ordinal number (st, nd, rd, th)
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
var ORDINAL_LENGTH = 2;
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/ function transformOrdinals(previousSegment, paragraph, context) {
|
|
17
20
|
var _a;
|
|
18
21
|
var value = (_a = previousSegment.text.split(' ').pop()) === null || _a === void 0 ? void 0 : _a.trim();
|
|
19
22
|
if (value) {
|
|
20
|
-
var ordinal = value.substring(value.length -
|
|
21
|
-
var
|
|
22
|
-
if (
|
|
23
|
+
var ordinal = value.substring(value.length - ORDINAL_LENGTH); // This value is equal st, nd, rd, th
|
|
24
|
+
var numericValue = getNumericValue(value); //This is the numeric part. Ex: 10th, numeric value = 10
|
|
25
|
+
if (numericValue && getOrdinal(numericValue) === ordinal) {
|
|
23
26
|
var ordinalSegment = (0, roosterjs_content_model_api_1.splitTextSegment)(previousSegment, paragraph, previousSegment.text.length - 3, previousSegment.text.length - 1);
|
|
24
27
|
ordinalSegment.format.superOrSubScriptSequence = 'super';
|
|
25
28
|
context.canUndoByBackspace = true;
|
|
@@ -29,4 +32,12 @@ function transformOrdinals(previousSegment, paragraph, context) {
|
|
|
29
32
|
return false;
|
|
30
33
|
}
|
|
31
34
|
exports.transformOrdinals = transformOrdinals;
|
|
35
|
+
function getNumericValue(text) {
|
|
36
|
+
var number = text.substring(0, text.length - ORDINAL_LENGTH);
|
|
37
|
+
var isNumber = /^-?\d+$/.test(number);
|
|
38
|
+
if (isNumber) {
|
|
39
|
+
return parseInt(text);
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
32
43
|
//# sourceMappingURL=transformOrdinals.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformOrdinals.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformOrdinals.ts"],"names":[],"mappings":";;;AAAA,2EAA+D;AAO/D,IAAM,UAAU,GAAG,UAAC,KAAa;IAC7B,IAAM,QAAQ,GAA2B;QACrC,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;KACV,CAAC;IACF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;AACnC,CAAC,CAAC;AAEF;;GAEG;AACH,SAAgB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"transformOrdinals.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformOrdinals.ts"],"names":[],"mappings":";;;AAAA,2EAA+D;AAO/D,IAAM,UAAU,GAAG,UAAC,KAAa;IAC7B,IAAM,QAAQ,GAA2B;QACrC,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;KACV,CAAC;IACF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;AACnC,CAAC,CAAC;AAEF;;GAEG;AACH,IAAM,cAAc,GAAG,CAAC,CAAC;AAEzB;;GAEG,CAAC,SAAgB,iBAAiB,CACjC,eAAiC,EACjC,SAA8C,EAC9C,OAAkC;;IAElC,IAAM,KAAK,GAAG,MAAA,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,0CAAE,IAAI,EAAE,CAAC;IAC5D,IAAI,KAAK,EAAE;QACP,IAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,sCAAsC;QACtG,IAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,wDAAwD;QACrG,IAAI,YAAY,IAAI,UAAU,CAAC,YAAY,CAAC,KAAK,OAAO,EAAE;YACtD,IAAM,cAAc,GAAG,IAAA,8CAAgB,EACnC,eAAe,EACf,SAAS,EACT,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAC/B,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAClC,CAAC;YAEF,cAAc,CAAC,MAAM,CAAC,wBAAwB,GAAG,OAAO,CAAC;YACzD,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;YAClC,OAAO,IAAI,CAAC;SACf;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAvBG,8CAuBH;AAED,SAAS,eAAe,CAAC,IAAY;IACjC,IAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,CAAC;IAC/D,IAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxC,IAAI,QAAQ,EAAE;QACV,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;KACzB;IACD,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import { splitTextSegment } from 'roosterjs-content-model-api';\nimport type {\n ContentModelText,\n FormatContentModelContext,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\nconst getOrdinal = (value: number) => {\n const ORDINALS: Record<number, string> = {\n 1: 'st',\n 2: 'nd',\n 3: 'rd',\n };\n return ORDINALS[value] || 'th';\n};\n\n/**\n * The two last characters of ordinal number (st, nd, rd, th)\n */\nconst ORDINAL_LENGTH = 2;\n\n/**\n * @internal\n */ export function transformOrdinals(\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n context: FormatContentModelContext\n): boolean {\n const value = previousSegment.text.split(' ').pop()?.trim();\n if (value) {\n const ordinal = value.substring(value.length - ORDINAL_LENGTH); // This value is equal st, nd, rd, th\n const numericValue = getNumericValue(value); //This is the numeric part. Ex: 10th, numeric value = 10\n if (numericValue && getOrdinal(numericValue) === ordinal) {\n const ordinalSegment = splitTextSegment(\n previousSegment,\n paragraph,\n previousSegment.text.length - 3,\n previousSegment.text.length - 1\n );\n\n ordinalSegment.format.superOrSubScriptSequence = 'super';\n context.canUndoByBackspace = true;\n return true;\n }\n }\n return false;\n}\n\nfunction getNumericValue(text: string) {\n const number = text.substring(0, text.length - ORDINAL_LENGTH);\n const isNumber = /^-?\\d+$/.test(number);\n if (isNumber) {\n return parseInt(text);\n }\n return null;\n}\n"]}
|
|
@@ -9,14 +9,16 @@ var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
|
9
9
|
function setFormat(editor, character, format, codeFormat) {
|
|
10
10
|
(0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (_model, previousSegment, paragraph, markerFormat, context) {
|
|
11
11
|
if (previousSegment.text[previousSegment.text.length - 1] == character) {
|
|
12
|
-
var
|
|
12
|
+
var textSegment = previousSegment.text;
|
|
13
|
+
var textBeforeMarker = textSegment.slice(0, -1);
|
|
13
14
|
context.newPendingFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, markerFormat), { strikethrough: !!markerFormat.strikethrough, italic: !!markerFormat.italic, fontWeight: (markerFormat === null || markerFormat === void 0 ? void 0 : markerFormat.fontWeight) ? 'bold' : undefined });
|
|
14
15
|
if (textBeforeMarker.indexOf(character) > -1) {
|
|
15
|
-
var lastCharIndex =
|
|
16
|
-
var firstCharIndex =
|
|
16
|
+
var lastCharIndex = textSegment.length;
|
|
17
|
+
var firstCharIndex = textSegment
|
|
17
18
|
.substring(0, lastCharIndex - 1)
|
|
18
19
|
.lastIndexOf(character);
|
|
19
|
-
if (
|
|
20
|
+
if (hasSpaceBeforeFirstCharacter(textSegment, firstCharIndex) &&
|
|
21
|
+
lastCharIndex - firstCharIndex > 2) {
|
|
20
22
|
var formattedText = (0, roosterjs_content_model_api_1.splitTextSegment)(previousSegment, paragraph, firstCharIndex, lastCharIndex);
|
|
21
23
|
formattedText.text = formattedText.text.replace(character, '').slice(0, -1);
|
|
22
24
|
formattedText.format = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, formattedText.format), format);
|
|
@@ -34,4 +36,12 @@ function setFormat(editor, character, format, codeFormat) {
|
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
38
|
exports.setFormat = setFormat;
|
|
39
|
+
/**
|
|
40
|
+
* The markdown should not be trigger inside a word, then check if exist a space before the trigger character
|
|
41
|
+
* Should trigger markdown example: _one two_
|
|
42
|
+
* Should not trigger markdown example: one_two_
|
|
43
|
+
*/
|
|
44
|
+
function hasSpaceBeforeFirstCharacter(text, index) {
|
|
45
|
+
return !text[index - 1] || text[index - 1].trim().length == 0;
|
|
46
|
+
}
|
|
37
47
|
//# sourceMappingURL=setFormat.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/markdown/utils/setFormat.ts"],"names":[],"mappings":";;;;AAAA,2EAGqC;AAOrC;;GAEG;AACH,SAAgB,SAAS,CACrB,MAAe,EACf,SAAiB,EACjB,MAAiC,EACjC,UAAmC;IAEnC,IAAA,oEAAsC,EAClC,MAAM,EACN,UAAC,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO;QACtD,IAAI,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE;YACpE,IAAM,
|
|
1
|
+
{"version":3,"file":"setFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/markdown/utils/setFormat.ts"],"names":[],"mappings":";;;;AAAA,2EAGqC;AAOrC;;GAEG;AACH,SAAgB,SAAS,CACrB,MAAe,EACf,SAAiB,EACjB,MAAiC,EACjC,UAAmC;IAEnC,IAAA,oEAAsC,EAClC,MAAM,EACN,UAAC,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO;QACtD,IAAI,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE;YACpE,IAAM,WAAW,GAAG,eAAe,CAAC,IAAI,CAAC;YACzC,IAAM,gBAAgB,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAClD,OAAO,CAAC,gBAAgB,mDACjB,YAAY,KACf,aAAa,EAAE,CAAC,CAAC,YAAY,CAAC,aAAa,EAC3C,MAAM,EAAE,CAAC,CAAC,YAAY,CAAC,MAAM,EAC7B,UAAU,EAAE,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,UAAU,EAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,GAC5D,CAAC;YACF,IAAI,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE;gBAC1C,IAAM,aAAa,GAAG,WAAW,CAAC,MAAM,CAAC;gBACzC,IAAM,cAAc,GAAG,WAAW;qBAC7B,SAAS,CAAC,CAAC,EAAE,aAAa,GAAG,CAAC,CAAC;qBAC/B,WAAW,CAAC,SAAS,CAAC,CAAC;gBAE5B,IACI,4BAA4B,CAAC,WAAW,EAAE,cAAc,CAAC;oBACzD,aAAa,GAAG,cAAc,GAAG,CAAC,EACpC;oBACE,IAAM,aAAa,GAAG,IAAA,8CAAgB,EAClC,eAAe,EACf,SAAS,EACT,cAAc,EACd,aAAa,CAChB,CAAC;oBAEF,aAAa,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;oBAC5E,aAAa,CAAC,MAAM,mDACb,aAAa,CAAC,MAAM,GACpB,MAAM,CACZ,CAAC;oBACF,IAAI,UAAU,EAAE;wBACZ,aAAa,CAAC,IAAI,GAAG;4BACjB,MAAM,EAAE,UAAU;yBACrB,CAAC;qBACL;oBAED,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;oBAClC,OAAO,IAAI,CAAC;iBACf;aACJ;SACJ;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CACJ,CAAC;AACN,CAAC;AAtDD,8BAsDC;AAED;;;;GAIG;AACH,SAAS,4BAA4B,CAAC,IAAY,EAAE,KAAa;IAC7D,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import {\n formatTextSegmentBeforeSelectionMarker,\n splitTextSegment,\n} from 'roosterjs-content-model-api';\nimport type {\n ContentModelCodeFormat,\n ContentModelSegmentFormat,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setFormat(\n editor: IEditor,\n character: string,\n format: ContentModelSegmentFormat,\n codeFormat?: ContentModelCodeFormat\n) {\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (_model, previousSegment, paragraph, markerFormat, context) => {\n if (previousSegment.text[previousSegment.text.length - 1] == character) {\n const textSegment = previousSegment.text;\n const textBeforeMarker = textSegment.slice(0, -1);\n context.newPendingFormat = {\n ...markerFormat,\n strikethrough: !!markerFormat.strikethrough,\n italic: !!markerFormat.italic,\n fontWeight: markerFormat?.fontWeight ? 'bold' : undefined,\n };\n if (textBeforeMarker.indexOf(character) > -1) {\n const lastCharIndex = textSegment.length;\n const firstCharIndex = textSegment\n .substring(0, lastCharIndex - 1)\n .lastIndexOf(character);\n\n if (\n hasSpaceBeforeFirstCharacter(textSegment, firstCharIndex) &&\n lastCharIndex - firstCharIndex > 2\n ) {\n const formattedText = splitTextSegment(\n previousSegment,\n paragraph,\n firstCharIndex,\n lastCharIndex\n );\n\n formattedText.text = formattedText.text.replace(character, '').slice(0, -1);\n formattedText.format = {\n ...formattedText.format,\n ...format,\n };\n if (codeFormat) {\n formattedText.code = {\n format: codeFormat,\n };\n }\n\n context.canUndoByBackspace = true;\n return true;\n }\n }\n }\n return false;\n }\n );\n}\n\n/**\n * The markdown should not be trigger inside a word, then check if exist a space before the trigger character\n * Should trigger markdown example: _one two_\n * Should not trigger markdown example: one_two_\n */\nfunction hasSpaceBeforeFirstCharacter(text: string, index: number) {\n return !text[index - 1] || text[index - 1].trim().length == 0;\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ContentModelText, FormatContentModelContext, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
|
-
*/
|
|
5
|
-
export declare function transformOrdinals(previousSegment: ContentModelText, paragraph: ShallowMutableContentModelParagraph, context: FormatContentModelContext): boolean;
|
|
4
|
+
*/ export declare function transformOrdinals(previousSegment: ContentModelText, paragraph: ShallowMutableContentModelParagraph, context: FormatContentModelContext): boolean;
|
|
@@ -11,15 +11,18 @@ define(["require", "exports", "roosterjs-content-model-api"], function (require,
|
|
|
11
11
|
return ORDINALS[value] || 'th';
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* The two last characters of ordinal number (st, nd, rd, th)
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
var ORDINAL_LENGTH = 2;
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/ function transformOrdinals(previousSegment, paragraph, context) {
|
|
17
20
|
var _a;
|
|
18
21
|
var value = (_a = previousSegment.text.split(' ').pop()) === null || _a === void 0 ? void 0 : _a.trim();
|
|
19
22
|
if (value) {
|
|
20
|
-
var ordinal = value.substring(value.length -
|
|
21
|
-
var
|
|
22
|
-
if (
|
|
23
|
+
var ordinal = value.substring(value.length - ORDINAL_LENGTH); // This value is equal st, nd, rd, th
|
|
24
|
+
var numericValue = getNumericValue(value); //This is the numeric part. Ex: 10th, numeric value = 10
|
|
25
|
+
if (numericValue && getOrdinal(numericValue) === ordinal) {
|
|
23
26
|
var ordinalSegment = (0, roosterjs_content_model_api_1.splitTextSegment)(previousSegment, paragraph, previousSegment.text.length - 3, previousSegment.text.length - 1);
|
|
24
27
|
ordinalSegment.format.superOrSubScriptSequence = 'super';
|
|
25
28
|
context.canUndoByBackspace = true;
|
|
@@ -29,5 +32,13 @@ define(["require", "exports", "roosterjs-content-model-api"], function (require,
|
|
|
29
32
|
return false;
|
|
30
33
|
}
|
|
31
34
|
exports.transformOrdinals = transformOrdinals;
|
|
35
|
+
function getNumericValue(text) {
|
|
36
|
+
var number = text.substring(0, text.length - ORDINAL_LENGTH);
|
|
37
|
+
var isNumber = /^-?\d+$/.test(number);
|
|
38
|
+
if (isNumber) {
|
|
39
|
+
return parseInt(text);
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
32
43
|
});
|
|
33
44
|
//# sourceMappingURL=transformOrdinals.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformOrdinals.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformOrdinals.ts"],"names":[],"mappings":";;;;IAOA,IAAM,UAAU,GAAG,UAAC,KAAa;QAC7B,IAAM,QAAQ,GAA2B;YACrC,CAAC,EAAE,IAAI;YACP,CAAC,EAAE,IAAI;YACP,CAAC,EAAE,IAAI;SACV,CAAC;QACF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IACnC,CAAC,CAAC;IAEF;;OAEG;IACH,SAAgB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"transformOrdinals.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformOrdinals.ts"],"names":[],"mappings":";;;;IAOA,IAAM,UAAU,GAAG,UAAC,KAAa;QAC7B,IAAM,QAAQ,GAA2B;YACrC,CAAC,EAAE,IAAI;YACP,CAAC,EAAE,IAAI;YACP,CAAC,EAAE,IAAI;SACV,CAAC;QACF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IACnC,CAAC,CAAC;IAEF;;OAEG;IACH,IAAM,cAAc,GAAG,CAAC,CAAC;IAEzB;;OAEG,CAAC,SAAgB,iBAAiB,CACjC,eAAiC,EACjC,SAA8C,EAC9C,OAAkC;;QAElC,IAAM,KAAK,GAAG,MAAA,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,0CAAE,IAAI,EAAE,CAAC;QAC5D,IAAI,KAAK,EAAE;YACP,IAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,sCAAsC;YACtG,IAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,wDAAwD;YACrG,IAAI,YAAY,IAAI,UAAU,CAAC,YAAY,CAAC,KAAK,OAAO,EAAE;gBACtD,IAAM,cAAc,GAAG,IAAA,8CAAgB,EACnC,eAAe,EACf,SAAS,EACT,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAC/B,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAClC,CAAC;gBAEF,cAAc,CAAC,MAAM,CAAC,wBAAwB,GAAG,OAAO,CAAC;gBACzD,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;gBAClC,OAAO,IAAI,CAAC;aACf;SACJ;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAvBG,8CAuBH;IAED,SAAS,eAAe,CAAC,IAAY;QACjC,IAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,CAAC;QAC/D,IAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxC,IAAI,QAAQ,EAAE;YACV,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;SACzB;QACD,OAAO,IAAI,CAAC;IAChB,CAAC","sourcesContent":["import { splitTextSegment } from 'roosterjs-content-model-api';\nimport type {\n ContentModelText,\n FormatContentModelContext,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\nconst getOrdinal = (value: number) => {\n const ORDINALS: Record<number, string> = {\n 1: 'st',\n 2: 'nd',\n 3: 'rd',\n };\n return ORDINALS[value] || 'th';\n};\n\n/**\n * The two last characters of ordinal number (st, nd, rd, th)\n */\nconst ORDINAL_LENGTH = 2;\n\n/**\n * @internal\n */ export function transformOrdinals(\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n context: FormatContentModelContext\n): boolean {\n const value = previousSegment.text.split(' ').pop()?.trim();\n if (value) {\n const ordinal = value.substring(value.length - ORDINAL_LENGTH); // This value is equal st, nd, rd, th\n const numericValue = getNumericValue(value); //This is the numeric part. Ex: 10th, numeric value = 10\n if (numericValue && getOrdinal(numericValue) === ordinal) {\n const ordinalSegment = splitTextSegment(\n previousSegment,\n paragraph,\n previousSegment.text.length - 3,\n previousSegment.text.length - 1\n );\n\n ordinalSegment.format.superOrSubScriptSequence = 'super';\n context.canUndoByBackspace = true;\n return true;\n }\n }\n return false;\n}\n\nfunction getNumericValue(text: string) {\n const number = text.substring(0, text.length - ORDINAL_LENGTH);\n const isNumber = /^-?\\d+$/.test(number);\n if (isNumber) {\n return parseInt(text);\n }\n return null;\n}\n"]}
|
|
@@ -8,14 +8,16 @@ define(["require", "exports", "tslib", "roosterjs-content-model-api"], function
|
|
|
8
8
|
function setFormat(editor, character, format, codeFormat) {
|
|
9
9
|
(0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (_model, previousSegment, paragraph, markerFormat, context) {
|
|
10
10
|
if (previousSegment.text[previousSegment.text.length - 1] == character) {
|
|
11
|
-
var
|
|
11
|
+
var textSegment = previousSegment.text;
|
|
12
|
+
var textBeforeMarker = textSegment.slice(0, -1);
|
|
12
13
|
context.newPendingFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, markerFormat), { strikethrough: !!markerFormat.strikethrough, italic: !!markerFormat.italic, fontWeight: (markerFormat === null || markerFormat === void 0 ? void 0 : markerFormat.fontWeight) ? 'bold' : undefined });
|
|
13
14
|
if (textBeforeMarker.indexOf(character) > -1) {
|
|
14
|
-
var lastCharIndex =
|
|
15
|
-
var firstCharIndex =
|
|
15
|
+
var lastCharIndex = textSegment.length;
|
|
16
|
+
var firstCharIndex = textSegment
|
|
16
17
|
.substring(0, lastCharIndex - 1)
|
|
17
18
|
.lastIndexOf(character);
|
|
18
|
-
if (
|
|
19
|
+
if (hasSpaceBeforeFirstCharacter(textSegment, firstCharIndex) &&
|
|
20
|
+
lastCharIndex - firstCharIndex > 2) {
|
|
19
21
|
var formattedText = (0, roosterjs_content_model_api_1.splitTextSegment)(previousSegment, paragraph, firstCharIndex, lastCharIndex);
|
|
20
22
|
formattedText.text = formattedText.text.replace(character, '').slice(0, -1);
|
|
21
23
|
formattedText.format = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, formattedText.format), format);
|
|
@@ -33,5 +35,13 @@ define(["require", "exports", "tslib", "roosterjs-content-model-api"], function
|
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
exports.setFormat = setFormat;
|
|
38
|
+
/**
|
|
39
|
+
* The markdown should not be trigger inside a word, then check if exist a space before the trigger character
|
|
40
|
+
* Should trigger markdown example: _one two_
|
|
41
|
+
* Should not trigger markdown example: one_two_
|
|
42
|
+
*/
|
|
43
|
+
function hasSpaceBeforeFirstCharacter(text, index) {
|
|
44
|
+
return !text[index - 1] || text[index - 1].trim().length == 0;
|
|
45
|
+
}
|
|
36
46
|
});
|
|
37
47
|
//# sourceMappingURL=setFormat.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/markdown/utils/setFormat.ts"],"names":[],"mappings":";;;;IAUA;;OAEG;IACH,SAAgB,SAAS,CACrB,MAAe,EACf,SAAiB,EACjB,MAAiC,EACjC,UAAmC;QAEnC,IAAA,oEAAsC,EAClC,MAAM,EACN,UAAC,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO;YACtD,IAAI,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE;gBACpE,IAAM,
|
|
1
|
+
{"version":3,"file":"setFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/markdown/utils/setFormat.ts"],"names":[],"mappings":";;;;IAUA;;OAEG;IACH,SAAgB,SAAS,CACrB,MAAe,EACf,SAAiB,EACjB,MAAiC,EACjC,UAAmC;QAEnC,IAAA,oEAAsC,EAClC,MAAM,EACN,UAAC,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO;YACtD,IAAI,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE;gBACpE,IAAM,WAAW,GAAG,eAAe,CAAC,IAAI,CAAC;gBACzC,IAAM,gBAAgB,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBAClD,OAAO,CAAC,gBAAgB,mDACjB,YAAY,KACf,aAAa,EAAE,CAAC,CAAC,YAAY,CAAC,aAAa,EAC3C,MAAM,EAAE,CAAC,CAAC,YAAY,CAAC,MAAM,EAC7B,UAAU,EAAE,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,UAAU,EAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,GAC5D,CAAC;gBACF,IAAI,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE;oBAC1C,IAAM,aAAa,GAAG,WAAW,CAAC,MAAM,CAAC;oBACzC,IAAM,cAAc,GAAG,WAAW;yBAC7B,SAAS,CAAC,CAAC,EAAE,aAAa,GAAG,CAAC,CAAC;yBAC/B,WAAW,CAAC,SAAS,CAAC,CAAC;oBAE5B,IACI,4BAA4B,CAAC,WAAW,EAAE,cAAc,CAAC;wBACzD,aAAa,GAAG,cAAc,GAAG,CAAC,EACpC;wBACE,IAAM,aAAa,GAAG,IAAA,8CAAgB,EAClC,eAAe,EACf,SAAS,EACT,cAAc,EACd,aAAa,CAChB,CAAC;wBAEF,aAAa,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;wBAC5E,aAAa,CAAC,MAAM,mDACb,aAAa,CAAC,MAAM,GACpB,MAAM,CACZ,CAAC;wBACF,IAAI,UAAU,EAAE;4BACZ,aAAa,CAAC,IAAI,GAAG;gCACjB,MAAM,EAAE,UAAU;6BACrB,CAAC;yBACL;wBAED,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;wBAClC,OAAO,IAAI,CAAC;qBACf;iBACJ;aACJ;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,CACJ,CAAC;IACN,CAAC;IAtDD,8BAsDC;IAED;;;;OAIG;IACH,SAAS,4BAA4B,CAAC,IAAY,EAAE,KAAa;QAC7D,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC;IAClE,CAAC","sourcesContent":["import {\n formatTextSegmentBeforeSelectionMarker,\n splitTextSegment,\n} from 'roosterjs-content-model-api';\nimport type {\n ContentModelCodeFormat,\n ContentModelSegmentFormat,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setFormat(\n editor: IEditor,\n character: string,\n format: ContentModelSegmentFormat,\n codeFormat?: ContentModelCodeFormat\n) {\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (_model, previousSegment, paragraph, markerFormat, context) => {\n if (previousSegment.text[previousSegment.text.length - 1] == character) {\n const textSegment = previousSegment.text;\n const textBeforeMarker = textSegment.slice(0, -1);\n context.newPendingFormat = {\n ...markerFormat,\n strikethrough: !!markerFormat.strikethrough,\n italic: !!markerFormat.italic,\n fontWeight: markerFormat?.fontWeight ? 'bold' : undefined,\n };\n if (textBeforeMarker.indexOf(character) > -1) {\n const lastCharIndex = textSegment.length;\n const firstCharIndex = textSegment\n .substring(0, lastCharIndex - 1)\n .lastIndexOf(character);\n\n if (\n hasSpaceBeforeFirstCharacter(textSegment, firstCharIndex) &&\n lastCharIndex - firstCharIndex > 2\n ) {\n const formattedText = splitTextSegment(\n previousSegment,\n paragraph,\n firstCharIndex,\n lastCharIndex\n );\n\n formattedText.text = formattedText.text.replace(character, '').slice(0, -1);\n formattedText.format = {\n ...formattedText.format,\n ...format,\n };\n if (codeFormat) {\n formattedText.code = {\n format: codeFormat,\n };\n }\n\n context.canUndoByBackspace = true;\n return true;\n }\n }\n }\n return false;\n }\n );\n}\n\n/**\n * The markdown should not be trigger inside a word, then check if exist a space before the trigger character\n * Should trigger markdown example: _one two_\n * Should not trigger markdown example: one_two_\n */\nfunction hasSpaceBeforeFirstCharacter(text: string, index: number) {\n return !text[index - 1] || text[index - 1].trim().length == 0;\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ContentModelText, FormatContentModelContext, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
|
-
*/
|
|
5
|
-
export declare function transformOrdinals(previousSegment: ContentModelText, paragraph: ShallowMutableContentModelParagraph, context: FormatContentModelContext): boolean;
|
|
4
|
+
*/ export declare function transformOrdinals(previousSegment: ContentModelText, paragraph: ShallowMutableContentModelParagraph, context: FormatContentModelContext): boolean;
|
|
@@ -8,15 +8,18 @@ var getOrdinal = function (value) {
|
|
|
8
8
|
return ORDINALS[value] || 'th';
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* The two last characters of ordinal number (st, nd, rd, th)
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
var ORDINAL_LENGTH = 2;
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/ export function transformOrdinals(previousSegment, paragraph, context) {
|
|
14
17
|
var _a;
|
|
15
18
|
var value = (_a = previousSegment.text.split(' ').pop()) === null || _a === void 0 ? void 0 : _a.trim();
|
|
16
19
|
if (value) {
|
|
17
|
-
var ordinal = value.substring(value.length -
|
|
18
|
-
var
|
|
19
|
-
if (
|
|
20
|
+
var ordinal = value.substring(value.length - ORDINAL_LENGTH); // This value is equal st, nd, rd, th
|
|
21
|
+
var numericValue = getNumericValue(value); //This is the numeric part. Ex: 10th, numeric value = 10
|
|
22
|
+
if (numericValue && getOrdinal(numericValue) === ordinal) {
|
|
20
23
|
var ordinalSegment = splitTextSegment(previousSegment, paragraph, previousSegment.text.length - 3, previousSegment.text.length - 1);
|
|
21
24
|
ordinalSegment.format.superOrSubScriptSequence = 'super';
|
|
22
25
|
context.canUndoByBackspace = true;
|
|
@@ -25,4 +28,12 @@ export function transformOrdinals(previousSegment, paragraph, context) {
|
|
|
25
28
|
}
|
|
26
29
|
return false;
|
|
27
30
|
}
|
|
31
|
+
function getNumericValue(text) {
|
|
32
|
+
var number = text.substring(0, text.length - ORDINAL_LENGTH);
|
|
33
|
+
var isNumber = /^-?\d+$/.test(number);
|
|
34
|
+
if (isNumber) {
|
|
35
|
+
return parseInt(text);
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
28
39
|
//# sourceMappingURL=transformOrdinals.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformOrdinals.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformOrdinals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAO/D,IAAM,UAAU,GAAG,UAAC,KAAa;IAC7B,IAAM,QAAQ,GAA2B;QACrC,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;KACV,CAAC;IACF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;AACnC,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,iBAAiB,
|
|
1
|
+
{"version":3,"file":"transformOrdinals.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformOrdinals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAO/D,IAAM,UAAU,GAAG,UAAC,KAAa;IAC7B,IAAM,QAAQ,GAA2B;QACrC,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;KACV,CAAC;IACF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;AACnC,CAAC,CAAC;AAEF;;GAEG;AACH,IAAM,cAAc,GAAG,CAAC,CAAC;AAEzB;;GAEG,CAAC,MAAM,UAAU,iBAAiB,CACjC,eAAiC,EACjC,SAA8C,EAC9C,OAAkC;;IAElC,IAAM,KAAK,GAAG,MAAA,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,0CAAE,IAAI,EAAE,CAAC;IAC5D,IAAI,KAAK,EAAE;QACP,IAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,sCAAsC;QACtG,IAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,wDAAwD;QACrG,IAAI,YAAY,IAAI,UAAU,CAAC,YAAY,CAAC,KAAK,OAAO,EAAE;YACtD,IAAM,cAAc,GAAG,gBAAgB,CACnC,eAAe,EACf,SAAS,EACT,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAC/B,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAClC,CAAC;YAEF,cAAc,CAAC,MAAM,CAAC,wBAAwB,GAAG,OAAO,CAAC;YACzD,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;YAClC,OAAO,IAAI,CAAC;SACf;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,eAAe,CAAC,IAAY;IACjC,IAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,CAAC;IAC/D,IAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxC,IAAI,QAAQ,EAAE;QACV,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;KACzB;IACD,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import { splitTextSegment } from 'roosterjs-content-model-api';\nimport type {\n ContentModelText,\n FormatContentModelContext,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\nconst getOrdinal = (value: number) => {\n const ORDINALS: Record<number, string> = {\n 1: 'st',\n 2: 'nd',\n 3: 'rd',\n };\n return ORDINALS[value] || 'th';\n};\n\n/**\n * The two last characters of ordinal number (st, nd, rd, th)\n */\nconst ORDINAL_LENGTH = 2;\n\n/**\n * @internal\n */ export function transformOrdinals(\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n context: FormatContentModelContext\n): boolean {\n const value = previousSegment.text.split(' ').pop()?.trim();\n if (value) {\n const ordinal = value.substring(value.length - ORDINAL_LENGTH); // This value is equal st, nd, rd, th\n const numericValue = getNumericValue(value); //This is the numeric part. Ex: 10th, numeric value = 10\n if (numericValue && getOrdinal(numericValue) === ordinal) {\n const ordinalSegment = splitTextSegment(\n previousSegment,\n paragraph,\n previousSegment.text.length - 3,\n previousSegment.text.length - 1\n );\n\n ordinalSegment.format.superOrSubScriptSequence = 'super';\n context.canUndoByBackspace = true;\n return true;\n }\n }\n return false;\n}\n\nfunction getNumericValue(text: string) {\n const number = text.substring(0, text.length - ORDINAL_LENGTH);\n const isNumber = /^-?\\d+$/.test(number);\n if (isNumber) {\n return parseInt(text);\n }\n return null;\n}\n"]}
|
|
@@ -6,14 +6,16 @@ import { formatTextSegmentBeforeSelectionMarker, splitTextSegment, } from 'roost
|
|
|
6
6
|
export function setFormat(editor, character, format, codeFormat) {
|
|
7
7
|
formatTextSegmentBeforeSelectionMarker(editor, function (_model, previousSegment, paragraph, markerFormat, context) {
|
|
8
8
|
if (previousSegment.text[previousSegment.text.length - 1] == character) {
|
|
9
|
-
var
|
|
9
|
+
var textSegment = previousSegment.text;
|
|
10
|
+
var textBeforeMarker = textSegment.slice(0, -1);
|
|
10
11
|
context.newPendingFormat = __assign(__assign({}, markerFormat), { strikethrough: !!markerFormat.strikethrough, italic: !!markerFormat.italic, fontWeight: (markerFormat === null || markerFormat === void 0 ? void 0 : markerFormat.fontWeight) ? 'bold' : undefined });
|
|
11
12
|
if (textBeforeMarker.indexOf(character) > -1) {
|
|
12
|
-
var lastCharIndex =
|
|
13
|
-
var firstCharIndex =
|
|
13
|
+
var lastCharIndex = textSegment.length;
|
|
14
|
+
var firstCharIndex = textSegment
|
|
14
15
|
.substring(0, lastCharIndex - 1)
|
|
15
16
|
.lastIndexOf(character);
|
|
16
|
-
if (
|
|
17
|
+
if (hasSpaceBeforeFirstCharacter(textSegment, firstCharIndex) &&
|
|
18
|
+
lastCharIndex - firstCharIndex > 2) {
|
|
17
19
|
var formattedText = splitTextSegment(previousSegment, paragraph, firstCharIndex, lastCharIndex);
|
|
18
20
|
formattedText.text = formattedText.text.replace(character, '').slice(0, -1);
|
|
19
21
|
formattedText.format = __assign(__assign({}, formattedText.format), format);
|
|
@@ -30,4 +32,12 @@ export function setFormat(editor, character, format, codeFormat) {
|
|
|
30
32
|
return false;
|
|
31
33
|
});
|
|
32
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* The markdown should not be trigger inside a word, then check if exist a space before the trigger character
|
|
37
|
+
* Should trigger markdown example: _one two_
|
|
38
|
+
* Should not trigger markdown example: one_two_
|
|
39
|
+
*/
|
|
40
|
+
function hasSpaceBeforeFirstCharacter(text, index) {
|
|
41
|
+
return !text[index - 1] || text[index - 1].trim().length == 0;
|
|
42
|
+
}
|
|
33
43
|
//# sourceMappingURL=setFormat.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/markdown/utils/setFormat.ts"],"names":[],"mappings":";AAAA,OAAO,EACH,sCAAsC,EACtC,gBAAgB,GACnB,MAAM,6BAA6B,CAAC;AAOrC;;GAEG;AACH,MAAM,UAAU,SAAS,CACrB,MAAe,EACf,SAAiB,EACjB,MAAiC,EACjC,UAAmC;IAEnC,sCAAsC,CAClC,MAAM,EACN,UAAC,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO;QACtD,IAAI,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE;YACpE,IAAM,
|
|
1
|
+
{"version":3,"file":"setFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/markdown/utils/setFormat.ts"],"names":[],"mappings":";AAAA,OAAO,EACH,sCAAsC,EACtC,gBAAgB,GACnB,MAAM,6BAA6B,CAAC;AAOrC;;GAEG;AACH,MAAM,UAAU,SAAS,CACrB,MAAe,EACf,SAAiB,EACjB,MAAiC,EACjC,UAAmC;IAEnC,sCAAsC,CAClC,MAAM,EACN,UAAC,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO;QACtD,IAAI,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE;YACpE,IAAM,WAAW,GAAG,eAAe,CAAC,IAAI,CAAC;YACzC,IAAM,gBAAgB,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAClD,OAAO,CAAC,gBAAgB,yBACjB,YAAY,KACf,aAAa,EAAE,CAAC,CAAC,YAAY,CAAC,aAAa,EAC3C,MAAM,EAAE,CAAC,CAAC,YAAY,CAAC,MAAM,EAC7B,UAAU,EAAE,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,UAAU,EAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,GAC5D,CAAC;YACF,IAAI,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE;gBAC1C,IAAM,aAAa,GAAG,WAAW,CAAC,MAAM,CAAC;gBACzC,IAAM,cAAc,GAAG,WAAW;qBAC7B,SAAS,CAAC,CAAC,EAAE,aAAa,GAAG,CAAC,CAAC;qBAC/B,WAAW,CAAC,SAAS,CAAC,CAAC;gBAE5B,IACI,4BAA4B,CAAC,WAAW,EAAE,cAAc,CAAC;oBACzD,aAAa,GAAG,cAAc,GAAG,CAAC,EACpC;oBACE,IAAM,aAAa,GAAG,gBAAgB,CAClC,eAAe,EACf,SAAS,EACT,cAAc,EACd,aAAa,CAChB,CAAC;oBAEF,aAAa,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;oBAC5E,aAAa,CAAC,MAAM,yBACb,aAAa,CAAC,MAAM,GACpB,MAAM,CACZ,CAAC;oBACF,IAAI,UAAU,EAAE;wBACZ,aAAa,CAAC,IAAI,GAAG;4BACjB,MAAM,EAAE,UAAU;yBACrB,CAAC;qBACL;oBAED,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;oBAClC,OAAO,IAAI,CAAC;iBACf;aACJ;SACJ;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CACJ,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,SAAS,4BAA4B,CAAC,IAAY,EAAE,KAAa;IAC7D,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import {\n formatTextSegmentBeforeSelectionMarker,\n splitTextSegment,\n} from 'roosterjs-content-model-api';\nimport type {\n ContentModelCodeFormat,\n ContentModelSegmentFormat,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setFormat(\n editor: IEditor,\n character: string,\n format: ContentModelSegmentFormat,\n codeFormat?: ContentModelCodeFormat\n) {\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (_model, previousSegment, paragraph, markerFormat, context) => {\n if (previousSegment.text[previousSegment.text.length - 1] == character) {\n const textSegment = previousSegment.text;\n const textBeforeMarker = textSegment.slice(0, -1);\n context.newPendingFormat = {\n ...markerFormat,\n strikethrough: !!markerFormat.strikethrough,\n italic: !!markerFormat.italic,\n fontWeight: markerFormat?.fontWeight ? 'bold' : undefined,\n };\n if (textBeforeMarker.indexOf(character) > -1) {\n const lastCharIndex = textSegment.length;\n const firstCharIndex = textSegment\n .substring(0, lastCharIndex - 1)\n .lastIndexOf(character);\n\n if (\n hasSpaceBeforeFirstCharacter(textSegment, firstCharIndex) &&\n lastCharIndex - firstCharIndex > 2\n ) {\n const formattedText = splitTextSegment(\n previousSegment,\n paragraph,\n firstCharIndex,\n lastCharIndex\n );\n\n formattedText.text = formattedText.text.replace(character, '').slice(0, -1);\n formattedText.format = {\n ...formattedText.format,\n ...format,\n };\n if (codeFormat) {\n formattedText.code = {\n format: codeFormat,\n };\n }\n\n context.canUndoByBackspace = true;\n return true;\n }\n }\n }\n return false;\n }\n );\n}\n\n/**\n * The markdown should not be trigger inside a word, then check if exist a space before the trigger character\n * Should trigger markdown example: _one two_\n * Should not trigger markdown example: one_two_\n */\nfunction hasSpaceBeforeFirstCharacter(text: string, index: number) {\n return !text[index - 1] || text[index - 1].trim().length == 0;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
"description": "Plugins for roosterjs",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"tslib": "^2.3.1",
|
|
6
|
-
"roosterjs-content-model-core": "^9.9.
|
|
7
|
-
"roosterjs-content-model-dom": "^9.9.
|
|
8
|
-
"roosterjs-content-model-types": "^9.9.
|
|
9
|
-
"roosterjs-content-model-api": "^9.9.
|
|
6
|
+
"roosterjs-content-model-core": "^9.9.1",
|
|
7
|
+
"roosterjs-content-model-dom": "^9.9.1",
|
|
8
|
+
"roosterjs-content-model-types": "^9.9.1",
|
|
9
|
+
"roosterjs-content-model-api": "^9.9.1"
|
|
10
10
|
},
|
|
11
|
-
"version": "9.9.
|
|
11
|
+
"version": "9.9.1",
|
|
12
12
|
"main": "./lib/index.js",
|
|
13
13
|
"typings": "./lib/index.d.ts",
|
|
14
14
|
"module": "./lib-mjs/index.js",
|