@hcengineering/text-markdown 0.7.19 → 0.7.21
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/compare.js +3 -1
- package/lib/compare.js.map +2 -2
- package/package.json +5 -5
- package/src/compare.ts +4 -1
- package/types/compare.d.ts.map +1 -1
package/lib/compare.js
CHANGED
|
@@ -45,7 +45,9 @@ function calcS\u00F8rensenDiceCoefficient(a, b) {
|
|
|
45
45
|
intersectionSize++;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
const denominator = first.length + second.length - 2;
|
|
49
|
+
if (denominator <= 0) return 0;
|
|
50
|
+
return 2 * intersectionSize / denominator;
|
|
49
51
|
}
|
|
50
52
|
__name(calcS\u00F8rensenDiceCoefficient, "calcS\xF8rensenDiceCoefficient");
|
|
51
53
|
function isMarkdownsEquals(source1, source2) {
|
package/lib/compare.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/compare.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright \u00A9 2025 Hardcore Engineering Inc.\n//\n// Licensed under the Eclipse Public License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License. You may\n// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n//\n// See the License for the specific language governing permissions and\n// limitations under the License.\n//\n\n/**\n * Calculate S\u00F8rensen\u2013Dice coefficient\n */\nexport function calcS\u00F8rensenDiceCoefficient (a: string, b: string): number {\n if (a == null || b == null) return 0\n\n const first = a.replace(/\\s+/g, '')\n const second = b.replace(/\\s+/g, '')\n\n if (first === second) return 1 // identical or empty\n if (first.length < 2 || second.length < 2) return 0 // if either is a 0-letter or 1-letter string\n\n const firstBigrams = new Map<string, number>()\n for (let i = 0; i < first.length - 1; i++) {\n const bigram = first.substring(i, i + 2)\n const count = (firstBigrams.get(bigram) ?? 0) + 1\n\n firstBigrams.set(bigram, count)\n }\n\n let intersectionSize = 0\n for (let i = 0; i < second.length - 1; i++) {\n const bigram = second.substring(i, i + 2)\n const count = firstBigrams.get(bigram) ?? 0\n\n if (count > 0) {\n firstBigrams.set(bigram, count - 1)\n intersectionSize++\n }\n }\n\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,iCAA6B,GAAW,GAAmB;AACzE,MAAI,KAAK,QAAQ,KAAK,KAAM,QAAO;AAEnC,QAAM,QAAQ,EAAE,QAAQ,QAAQ,EAAE;AAClC,QAAM,SAAS,EAAE,QAAQ,QAAQ,EAAE;AAEnC,MAAI,UAAU,OAAQ,QAAO;AAC7B,MAAI,MAAM,SAAS,KAAK,OAAO,SAAS,EAAG,QAAO;AAElD,QAAM,eAAe,oBAAI,IAAoB;AAC7C,WAAS,IAAI,GAAG,IAAI,MAAM,SAAS,GAAG,KAAK;AACzC,UAAM,SAAS,MAAM,UAAU,GAAG,IAAI,CAAC;AACvC,UAAM,SAAS,aAAa,IAAI,MAAM,KAAK,KAAK;AAEhD,iBAAa,IAAI,QAAQ,KAAK;AAAA,EAChC;AAEA,MAAI,mBAAmB;AACvB,WAAS,IAAI,GAAG,IAAI,OAAO,SAAS,GAAG,KAAK;AAC1C,UAAM,SAAS,OAAO,UAAU,GAAG,IAAI,CAAC;AACxC,UAAM,QAAQ,aAAa,IAAI,MAAM,KAAK;AAE1C,QAAI,QAAQ,GAAG;AACb,mBAAa,IAAI,QAAQ,QAAQ,CAAC;AAClC;AAAA,IACF;AAAA,EACF;AAEA,
|
|
4
|
+
"sourcesContent": ["//\n// Copyright \u00A9 2025 Hardcore Engineering Inc.\n//\n// Licensed under the Eclipse Public License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License. You may\n// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n//\n// See the License for the specific language governing permissions and\n// limitations under the License.\n//\n\n/**\n * Calculate S\u00F8rensen\u2013Dice coefficient\n */\nexport function calcS\u00F8rensenDiceCoefficient (a: string, b: string): number {\n if (a == null || b == null) return 0\n\n const first = a.replace(/\\s+/g, '')\n const second = b.replace(/\\s+/g, '')\n\n if (first === second) return 1 // identical or empty\n if (first.length < 2 || second.length < 2) return 0 // if either is a 0-letter or 1-letter string\n\n const firstBigrams = new Map<string, number>()\n for (let i = 0; i < first.length - 1; i++) {\n const bigram = first.substring(i, i + 2)\n const count = (firstBigrams.get(bigram) ?? 0) + 1\n\n firstBigrams.set(bigram, count)\n }\n\n let intersectionSize = 0\n for (let i = 0; i < second.length - 1; i++) {\n const bigram = second.substring(i, i + 2)\n const count = firstBigrams.get(bigram) ?? 0\n\n if (count > 0) {\n firstBigrams.set(bigram, count - 1)\n intersectionSize++\n }\n }\n\n const denominator = first.length + second.length - 2\n if (denominator <= 0) return 0\n\n return (2.0 * intersectionSize) / denominator\n}\n\n/**\n * Perform markdown diff/comparison to understand do we have a major differences.\n */\nexport function isMarkdownsEquals (source1: string, source2: string): boolean {\n const normalized1 = normalizeMarkdown(source1)\n const normalized2 = normalizeMarkdown(source2)\n return normalized1 === normalized2\n}\n\nexport function normalizeMarkdown (source: string): string {\n if (source == null || typeof source !== 'string') return ''\n\n const tagRegex = /<(\\w+)([^>]*?)(\\/?)>/g\n const attrRegex = /(\\w+)(?:=(?:\"([^\"]*)\"|'([^']*)'|([^\\s>]+)))?/g\n\n // Normalize line endings to LF\n source = source.replace(/\\r\\n/g, '\\n').replace(/\\r/g, '\\n')\n\n // Remove extra blank lines\n source = source\n .split('\\n')\n .map((it) => it.trimEnd())\n .filter((it) => it.length > 0)\n .join('\\n')\n\n // Normalize HTML tags\n source = source.replace(tagRegex, (match, tagName, attributes) => {\n const attrs: Record<string, string> = {}\n\n let attrMatch = attrRegex.exec(attributes)\n while (attrMatch !== null) {\n const attrName = attrMatch[1]\n const attrValue = attrMatch[2] ?? attrMatch[3] ?? attrMatch[4] ?? ''\n attrs[attrName] = attrValue\n attrMatch = attrRegex.exec(attributes)\n }\n\n // Sort attributes by name for consistent order\n const sortedAttrs = Object.keys(attrs)\n .sort()\n .map((key) => {\n const value = attrs[key]\n return value !== '' ? `${key}=\"${value}\"` : key\n })\n .join(' ')\n\n // Normalize to self-closing format for void elements\n const voidElements = [\n 'img',\n 'br',\n 'hr',\n 'input',\n 'meta',\n 'area',\n 'base',\n 'col',\n 'embed',\n 'link',\n 'param',\n 'source',\n 'track',\n 'wbr'\n ]\n const isVoidElement = voidElements.includes(tagName.toLowerCase())\n\n if (sortedAttrs !== '') {\n return isVoidElement ? `<${tagName} ${sortedAttrs} />` : `<${tagName} ${sortedAttrs}>`\n } else {\n return isVoidElement ? `<${tagName} />` : `<${tagName}>`\n }\n })\n\n return source\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,iCAA6B,GAAW,GAAmB;AACzE,MAAI,KAAK,QAAQ,KAAK,KAAM,QAAO;AAEnC,QAAM,QAAQ,EAAE,QAAQ,QAAQ,EAAE;AAClC,QAAM,SAAS,EAAE,QAAQ,QAAQ,EAAE;AAEnC,MAAI,UAAU,OAAQ,QAAO;AAC7B,MAAI,MAAM,SAAS,KAAK,OAAO,SAAS,EAAG,QAAO;AAElD,QAAM,eAAe,oBAAI,IAAoB;AAC7C,WAAS,IAAI,GAAG,IAAI,MAAM,SAAS,GAAG,KAAK;AACzC,UAAM,SAAS,MAAM,UAAU,GAAG,IAAI,CAAC;AACvC,UAAM,SAAS,aAAa,IAAI,MAAM,KAAK,KAAK;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K,EACL,IAAI,CAAC,QAAQ;AACZ,YAAM,QAAQ,MAAM,GAAG;AACvB,aAAO,UAAU,KAAK,GAAG,GAAG,KAAK,KAAK,MAAM;AAAA,IAC9C,CAAC,EACA,KAAK,GAAG;AAGX,UAAM,eAAe;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,UAAM,gBAAgB,aAAa,SAAS,QAAQ,YAAY,CAAC;AAEjE,QAAI,gBAAgB,IAAI;AACtB,aAAO,gBAAgB,IAAI,OAAO,IAAI,WAAW,QAAQ,IAAI,OAAO,IAAI,WAAW;AAAA,IACrF,OAAO;AACL,aAAO,gBAAgB,IAAI,OAAO,QAAQ,IAAI,OAAO;AAAA,IACvD;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAhEgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hcengineering/text-markdown",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.21",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"svelte": "src/index.ts",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"author": "Anticrm Platform Contributors",
|
|
15
15
|
"license": "EPL-2.0",
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@hcengineering/platform-rig": "^0.7.
|
|
17
|
+
"@hcengineering/platform-rig": "^0.7.21",
|
|
18
18
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
19
19
|
"eslint-plugin-import": "^2.26.0",
|
|
20
20
|
"eslint-plugin-promise": "^6.1.1",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"eslint": "^8.54.0",
|
|
23
23
|
"@typescript-eslint/parser": "^6.21.0",
|
|
24
24
|
"eslint-config-standard-with-typescript": "^40.0.0",
|
|
25
|
-
"prettier": "^3.
|
|
25
|
+
"prettier": "^3.6.2",
|
|
26
26
|
"typescript": "^5.9.3",
|
|
27
27
|
"jest": "^29.7.0",
|
|
28
28
|
"ts-jest": "^29.1.1",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"eslint-plugin-svelte": "^2.35.1"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@hcengineering/text-core": "^0.7.
|
|
35
|
-
"@hcengineering/text-html": "^0.7.
|
|
34
|
+
"@hcengineering/text-core": "^0.7.19",
|
|
35
|
+
"@hcengineering/text-html": "^0.7.19",
|
|
36
36
|
"markdown-it": "^14.0.0",
|
|
37
37
|
"fast-equals": "^5.2.2"
|
|
38
38
|
},
|
package/src/compare.ts
CHANGED
|
@@ -44,7 +44,10 @@ export function calcSørensenDiceCoefficient (a: string, b: string): number {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const denominator = first.length + second.length - 2
|
|
48
|
+
if (denominator <= 0) return 0
|
|
49
|
+
|
|
50
|
+
return (2.0 * intersectionSize) / denominator
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
/**
|
package/types/compare.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,wBAAgB,2BAA2B,CAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,wBAAgB,2BAA2B,CAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAgCzE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAI5E;AAED,wBAAgB,iBAAiB,CAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAgEzD"}
|