securemark 0.280.5 → 0.280.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.280.7
4
+
5
+ - Refactoring.
6
+
7
+ ## 0.280.6
8
+
9
+ - Refactoring.
10
+
3
11
  ## 0.280.5
4
12
 
5
13
  - Refactoring.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.280.5 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
1
+ /*! securemark v0.280.7 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory(require("Prism"), require("DOMPurify"));
@@ -6244,16 +6244,21 @@ function indexee(parser, optional) {
6244
6244
  exports.indexee = indexee;
6245
6245
  function identity(id, text, type = 'index') {
6246
6246
  if (id === '') return undefined;
6247
- text &&= text.trim().replace(/\s+/g, '_');
6247
+ text &&= text.trim().replace(/\s\s+/g, ' ');
6248
6248
  if (text === '') return undefined;
6249
- if (text.length <= 120 || type === '') return `${type}:${id ?? ''}:${text}`;
6249
+ const hash = text.replace(/\s/g, '_');
6250
+ if (hash.length <= 120 || type === '') return `${type}:${id ?? ''}:${hash}`;
6250
6251
  const cs = [...text];
6251
- if (cs.length <= 120) return `${type}:${id ?? ''}:${text}`;
6252
+ if (cs.length <= 120) return `${type}:${id ?? ''}:${hash}`;
6253
+ const ellipsis = '...';
6254
+ const len = (120 - ellipsis.length * 2) / 3 | 0;
6252
6255
  switch (type) {
6253
6256
  case 'index':
6254
- return `${type}:${id ?? ''}:${cs.slice(0, 120 - 3).join('')}...`;
6255
6257
  case 'mark':
6256
- return `${type}:${id ?? ''}:${cs.slice(0, 38).join('')}...${cs.slice(cs.length / 2 - 38 / 2 | 0).slice(0, 38).join('')}...${cs.slice(-38).join('')}`;
6258
+ const s1 = hash.slice(0, cs.slice(0, len).join('').trimEnd().length);
6259
+ const s3 = hash.slice(-cs.slice(-len).join('').trimStart().length);
6260
+ const s2 = cs.slice(cs.length / 2 - len / 2 - (len - s1.length) | 0).slice(0, len + len - s3.length).join('').trim().replace(/\s/g, '_');
6261
+ return `${type}:${id ?? ''}:${s1}${ellipsis}${s2}${ellipsis}${s3}`;
6257
6262
  }
6258
6263
  }
6259
6264
  exports.identity = identity;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.280.5",
3
+ "version": "0.280.7",
4
4
  "description": "Secure markdown renderer working on browsers for user input data.",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/falsandtru/securemark",
@@ -13,25 +13,27 @@ export function identity(id: string | undefined, text: string, type: 'index' | '
13
13
  assert(!id?.match(/[^0-9a-z/-]/i));
14
14
  assert(!text.includes('\n'));
15
15
  if (id === '') return undefined;
16
- text &&= text.trim().replace(/\s+/g, '_');
16
+ text &&= text.trim().replace(/\s\s+/g, ' ');
17
17
  if (text === '') return undefined;
18
- if (text.length <= 120 || type === '') return `${type}:${id ?? ''}:${text}`;
18
+ const hash = text.replace(/\s/g, '_');
19
+ if (hash.length <= 120 || type === '') return `${type}:${id ?? ''}:${hash}`;
19
20
  const cs = [...text];
20
- if (cs.length <= 120) return `${type}:${id ?? ''}:${text}`;
21
+ if (cs.length <= 120) return `${type}:${id ?? ''}:${hash}`;
22
+ const ellipsis = '...';
23
+ const len = (120 - ellipsis.length * 2) / 3 | 0;
21
24
  switch (type) {
22
25
  case 'index':
23
- return `${type}:${id ?? ''}:${cs.slice(0, 120 - 3).join('')}...`;
24
26
  case 'mark':
25
- return `${type}:${id ?? ''}:${cs.slice(0, 38).join('')}...${cs.slice(cs.length / 2 - 38 / 2 | 0).slice(0, 38).join('')}...${cs.slice(-38).join('')}`;
27
+ const s1 = hash.slice(0, cs.slice(0, len).join('').trimEnd().length);
28
+ const s3 = hash.slice(-cs.slice(-len).join('').trimStart().length);
29
+ const s2 = cs.slice(cs.length / 2 - len / 2 - (len - s1.length) | 0).slice(0, len + len - s3.length).join('').trim().replace(/\s/g, '_');
30
+ return `${type}:${id ?? ''}:${s1}${ellipsis}${s2}${ellipsis}${s3}`;
26
31
  }
27
32
  assert(false);
28
33
  }
29
34
  assert(identity(undefined, '0'.repeat(120 - 1) + 1)!.slice(7) === '0'.repeat(120 - 1) + 1);
30
- assert(identity(undefined, '0'.repeat(120) + 1)!.slice(7) === '0'.repeat(117) + '...');
31
- assert(identity(undefined, '0'.repeat(200) + 1)!.slice(7) === '0'.repeat(117) + '...');
32
- assert(identity(undefined, '0'.repeat(120 - 1) + 1, 'mark')!.slice(6) === '0'.repeat(120 - 1) + 1);
33
- assert(identity(undefined, '0'.repeat(41) + '1'.repeat(38) + '2'.repeat(41) + 3, 'mark')!.slice(6) === '0'.repeat(38) + '...' + '1'.repeat(38) + '...' + '2'.repeat(38 - 1) + 3);
34
- assert(identity(undefined, '0'.repeat(81) + '1'.repeat(38) + '2'.repeat(81) + 3, 'mark')!.slice(6) === '0'.repeat(38) + '...' + '1'.repeat(38) + '...' + '2'.repeat(38 - 1) + 3);
35
+ assert(identity(undefined, '0'.repeat(41) + '1'.repeat(38) + '2'.repeat(41) + 3)!.slice(7) === '0'.repeat(38) + '...' + '1'.repeat(38) + '...' + '2'.repeat(38 - 1) + 3);
36
+ assert(identity(undefined, '0'.repeat(81) + '1'.repeat(38) + '2'.repeat(81) + 3)!.slice(7) === '0'.repeat(38) + '...' + '1'.repeat(38) + '...' + '2'.repeat(38 - 1) + 3);
35
37
 
36
38
  export function index(source: Element, optional = false): string {
37
39
  assert(!source.matches('.indexer'));