securemark 0.226.2 → 0.226.3

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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.226.3
4
+
5
+ - Refactoring.
6
+
3
7
  ## 0.226.2
4
8
 
5
9
  - Refactoring.
@@ -1,4 +1,4 @@
1
- /*! securemark v0.226.2 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED */
1
+ /*! securemark v0.226.3 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED */
2
2
  require = function () {
3
3
  function r(e, n, t) {
4
4
  function o(i, f) {
@@ -4719,7 +4719,7 @@ require = function () {
4719
4719
  const parser_1 = _dereq_('../../combinator/data/parser');
4720
4720
  const UNICODE_REPLACEMENT_CHARACTER = '\uFFFD';
4721
4721
  function normalize(source) {
4722
- return format(sanitize(source));
4722
+ return sanitize(format(source));
4723
4723
  }
4724
4724
  exports.normalize = normalize;
4725
4725
  function format(source) {
@@ -6402,8 +6402,8 @@ require = function () {
6402
6402
  exports.header = void 0;
6403
6403
  const combinator_1 = _dereq_('../combinator');
6404
6404
  const segment_1 = _dereq_('./segment');
6405
- const normalize_1 = _dereq_('./api/normalize');
6406
6405
  const source_1 = _dereq_('./source');
6406
+ const normalize_1 = _dereq_('./api/normalize');
6407
6407
  const typed_dom_1 = _dereq_('typed-dom');
6408
6408
  exports.header = (0, combinator_1.validate)(/^---+[^\S\v\f\r\n]*\r?\n[^\S\n]*(?=\S)/, (0, combinator_1.inits)([
6409
6409
  (0, combinator_1.rewrite)((source, context) => {
@@ -8214,11 +8214,9 @@ require = function () {
8214
8214
  if (ns.length === 0)
8215
8215
  return ns;
8216
8216
  const el = ns.length === 1 && typeof ns[0] === 'object' ? ns[0] : (0, typed_dom_1.html)('div', ns);
8217
- const es = el.getElementsByClassName('linebreak');
8217
+ const es = el.querySelectorAll('.linebreak:not(:empty)');
8218
8218
  for (let i = 0, len = es.length; i < len; ++i) {
8219
8219
  const sb = es[i];
8220
- if (!sb.firstChild)
8221
- continue;
8222
8220
  if (!check(sb))
8223
8221
  continue;
8224
8222
  sb.firstChild.remove();
@@ -8234,28 +8232,28 @@ require = function () {
8234
8232
  return (0, ja_1.japanese)(char);
8235
8233
  }
8236
8234
  function lastChar(node) {
8235
+ var _a, _b;
8237
8236
  while (node = node === null || node === void 0 ? void 0 : node.previousSibling) {
8238
- if ('id' in node && !node.firstChild) {
8239
- switch (node.tagName) {
8240
- case 'BR':
8237
+ if (!('id' in node))
8238
+ return (_a = [...node.data.slice(-2)].pop()) !== null && _a !== void 0 ? _a : '';
8239
+ if (node.firstChild)
8240
+ return (_b = [...text(node).slice(-2)].pop()) !== null && _b !== void 0 ? _b : '';
8241
+ switch (node.tagName) {
8242
+ case 'BR':
8243
+ return '';
8244
+ case 'SPAN':
8245
+ switch (node.className) {
8246
+ case 'linebreak':
8241
8247
  return '';
8242
- case 'SPAN':
8243
- if (node.className === 'linebreak')
8244
- return '';
8245
8248
  }
8246
- continue;
8247
8249
  }
8248
- const str = text(node);
8249
- return str && [...str.slice(-2)].pop();
8250
8250
  }
8251
8251
  return '';
8252
8252
  }
8253
- function text(node) {
8254
- if (!('id' in node))
8255
- return node.data;
8256
- switch (node.tagName) {
8253
+ function text(el) {
8254
+ switch (el.tagName) {
8257
8255
  case 'RUBY':
8258
- for (let ns = node.childNodes, i = ns.length; i--;) {
8256
+ for (let ns = el.childNodes, i = ns.length; i--;) {
8259
8257
  const child = ns[i];
8260
8258
  if ('id' in child)
8261
8259
  continue;
@@ -8263,7 +8261,7 @@ require = function () {
8263
8261
  }
8264
8262
  return '';
8265
8263
  default:
8266
- return node.textContent;
8264
+ return el.textContent;
8267
8265
  }
8268
8266
  }
8269
8267
  },
@@ -8568,7 +8566,7 @@ require = function () {
8568
8566
  }
8569
8567
  exports.segment = segment;
8570
8568
  function validate(source, size) {
8571
- return source.length <= size / 2 || source.length <= size && new global_1.Blob([source]).size <= size;
8569
+ return source.length <= size / 4 || source.length <= size && new global_1.Blob([source]).size <= size;
8572
8570
  }
8573
8571
  exports.validate = validate;
8574
8572
  },
@@ -8784,6 +8782,30 @@ require = function () {
8784
8782
  ''
8785
8783
  ];
8786
8784
  case 0:
8785
+ switch (source[0]) {
8786
+ case '\\':
8787
+ switch (source[1]) {
8788
+ case '\u3001':
8789
+ case '\u3002':
8790
+ case '\uFF01':
8791
+ case '\uFF1F':
8792
+ return (0, exports.text)(source.slice(1), context);
8793
+ }
8794
+ break;
8795
+ case '\u3001':
8796
+ case '\u3002':
8797
+ case '\uFF01':
8798
+ case '\uFF1F':
8799
+ const i = source.slice(1).search(exports.nonWhitespace) + 1;
8800
+ if (i > 0 && source.slice(i, i + 2) === '\\\n')
8801
+ return [
8802
+ [
8803
+ source[0],
8804
+ (0, typed_dom_1.html)('span', { class: 'linebreak' })
8805
+ ],
8806
+ source.slice(i + 2)
8807
+ ];
8808
+ }
8787
8809
  switch (source[0]) {
8788
8810
  case '\x7F':
8789
8811
  return [
@@ -8822,20 +8844,6 @@ require = function () {
8822
8844
  [source[0]],
8823
8845
  source.slice(1)
8824
8846
  ];
8825
- case '\u3001':
8826
- case '\u3002':
8827
- case '\uFF01':
8828
- case '\uFF1F': {
8829
- const i = source.slice(1).search(exports.nonWhitespace) + 1;
8830
- if (i > 0 && source.slice(i, i + 2) === '\\\n')
8831
- return [
8832
- [
8833
- source[0],
8834
- (0, typed_dom_1.html)('span', { class: 'linebreak' })
8835
- ],
8836
- source.slice(i + 2)
8837
- ];
8838
- }
8839
8847
  default:
8840
8848
  const b = source[0].trimStart() === '';
8841
8849
  const i = b || isAlphanumeric(source[0]) ? source.search(b ? exports.nonWhitespace : exports.nonAlphanumeric) : 1;
package/package-lock.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.226.2",
3
+ "version": "0.226.3",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
@@ -548,9 +548,9 @@
548
548
  "dev": true
549
549
  },
550
550
  "@types/node": {
551
- "version": "17.0.4",
552
- "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.4.tgz",
553
- "integrity": "sha512-6xwbrW4JJiJLgF+zNypN5wr2ykM9/jHcL7rQ8fZe2vuftggjzZeRSM4OwRc6Xk8qWjwJ99qVHo/JgOGmomWRog==",
551
+ "version": "17.0.5",
552
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.5.tgz",
553
+ "integrity": "sha512-w3mrvNXLeDYV1GKTZorGJQivK6XLCoGwpnyJFbJVK/aTBQUxOCaa/GlFAAN3OTDFcb7h5tiFG+YXCO2By+riZw==",
554
554
  "dev": true
555
555
  },
556
556
  "@types/power-assert": {
@@ -1790,9 +1790,9 @@
1790
1790
  "dev": true
1791
1791
  },
1792
1792
  "caniuse-lite": {
1793
- "version": "1.0.30001292",
1794
- "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001292.tgz",
1795
- "integrity": "sha512-jnT4Tq0Q4ma+6nncYQVe7d73kmDmE9C3OGTx3MvW7lBM/eY1S1DZTMBON7dqV481RhNiS5OxD7k9JQvmDOTirw==",
1793
+ "version": "1.0.30001294",
1794
+ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001294.tgz",
1795
+ "integrity": "sha512-LiMlrs1nSKZ8qkNhpUf5KD0Al1KCBE3zaT7OLOwEkagXMEDij98SiOovn9wxVGQpklk9vVC/pUSqgYmkmKOS8g==",
1796
1796
  "dev": true
1797
1797
  },
1798
1798
  "chalk": {
@@ -2413,9 +2413,9 @@
2413
2413
  "dev": true
2414
2414
  },
2415
2415
  "date-fns": {
2416
- "version": "2.27.0",
2417
- "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.27.0.tgz",
2418
- "integrity": "sha512-sj+J0Mo2p2X1e306MHq282WS4/A8Pz/95GIFcsPNMPMZVI3EUrAdSv90al1k+p74WGLCruMXk23bfEDZa71X9Q==",
2416
+ "version": "2.28.0",
2417
+ "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.28.0.tgz",
2418
+ "integrity": "sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw==",
2419
2419
  "dev": true
2420
2420
  },
2421
2421
  "date-format": {
@@ -2867,9 +2867,9 @@
2867
2867
  "dev": true
2868
2868
  },
2869
2869
  "electron-to-chromium": {
2870
- "version": "1.4.28",
2871
- "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.28.tgz",
2872
- "integrity": "sha512-Gzbf0wUtKfyPaqf0Plz+Ctinf9eQIzxEqBHwSvbGfeOm9GMNdLxyu1dNiCUfM+x6r4BE0xUJNh3Nmg9gfAtTmg==",
2870
+ "version": "1.4.30",
2871
+ "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.30.tgz",
2872
+ "integrity": "sha512-609z9sIMxDHg+TcR/VB3MXwH+uwtrYyeAwWc/orhnr90ixs6WVGSrt85CDLGUdNnLqCA7liv426V20EecjvflQ==",
2873
2873
  "dev": true
2874
2874
  },
2875
2875
  "elliptic": {
@@ -5929,9 +5929,9 @@
5929
5929
  }
5930
5930
  },
5931
5931
  "istanbul-reports": {
5932
- "version": "3.1.2",
5933
- "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.1.2.tgz",
5934
- "integrity": "sha512-0gHxuT1NNC0aEIL1zbJ+MTgPbbHhU77eJPuU35WKA7TgXiSNlCAx4PENoMrH0Or6M2H80TaZcWKhM0IK6V8gRw==",
5932
+ "version": "3.1.3",
5933
+ "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.1.3.tgz",
5934
+ "integrity": "sha512-x9LtDVtfm/t1GFiLl3NffC7hz+I1ragvgX1P/Lg1NlIagifZDKUkuuaAxH/qpwj2IuEfD8G2Bs/UKp+sZ/pKkg==",
5935
5935
  "dev": true,
5936
5936
  "requires": {
5937
5937
  "html-escaper": "^2.0.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.226.2",
3
+ "version": "0.226.3",
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",
@@ -5,7 +5,7 @@ const UNICODE_REPLACEMENT_CHARACTER = '\uFFFD';
5
5
  assert(UNICODE_REPLACEMENT_CHARACTER.trim());
6
6
 
7
7
  export function normalize(source: string): string {
8
- return format(sanitize(source));
8
+ return sanitize(format(source));
9
9
  }
10
10
 
11
11
  function format(source: string): string {
@@ -57,7 +57,7 @@ const unreadableHTMLEntityNames = [
57
57
  'it',
58
58
  'InvisibleComma',
59
59
  'ic',
60
- ];
60
+ ] as const;
61
61
  const unreadableEscapableCharacters = unreadableHTMLEntityNames
62
62
  .flatMap(name => eval(unsafehtmlentity(`&${name};`, {}), []));
63
63
  assert(unreadableEscapableCharacters.length === unreadableHTMLEntityNames.length);
@@ -98,10 +98,10 @@ const unreadableSpecialCharacters = [
98
98
  '\u2060',
99
99
  // ZERO WIDTH NON-BREAKING SPACE
100
100
  '\uFEFF',
101
- ];
101
+ ] as const;
102
102
  assert(unreadableSpecialCharacters.every(c => sanitize(c) === UNICODE_REPLACEMENT_CHARACTER));
103
103
 
104
- // 特殊不可視文字はエディタおよびソースビューアの等幅および強調表示により可視化する
104
+ // 特殊不可視文字はエディタおよびソースビューアでは等幅および強調表示により可視化する
105
105
  export function escape(source: string): string {
106
106
  return source
107
107
  .replace(unreadableEscapableCharacter, char =>
@@ -1,8 +1,8 @@
1
1
  import { MarkdownParser } from '../../markdown';
2
2
  import { union, inits, block, validate, focus, rewrite, guard, clear } from '../combinator';
3
3
  import { segment } from './segment';
4
- import { normalize } from './api/normalize';
5
4
  import { str } from './source';
5
+ import { normalize } from './api/normalize';
6
6
  import { html, defrag } from 'typed-dom';
7
7
 
8
8
  export const header: MarkdownParser.HeaderParser = validate(
@@ -10,13 +10,12 @@ export function localize(parser: Parser<HTMLElement | string>): Parser<HTMLEleme
10
10
  const el = ns.length === 1 && typeof ns[0] === 'object'
11
11
  ? ns[0]
12
12
  : html('div', ns);
13
- const es = el.getElementsByClassName('linebreak');
13
+ const es = el.querySelectorAll('.linebreak:not(:empty)');
14
14
  for (let i = 0, len = es.length; i < len; ++i) {
15
15
  const sb = es[i];
16
- if (!sb.firstChild) continue;
16
+ assert(sb.firstChild!.textContent === ' ');
17
17
  if (!check(sb)) continue;
18
- assert(sb.firstChild.textContent === ' ');
19
- sb.firstChild.remove();
18
+ sb.firstChild!.remove();
20
19
  }
21
20
  return ns;
22
21
  });
@@ -31,26 +30,25 @@ function check(el: Element): boolean {
31
30
 
32
31
  function lastChar(node: Element | Text | null): string {
33
32
  while (node = node?.previousSibling as typeof node) {
34
- if ('id' in node && !node.firstChild) {
35
- switch (node.tagName) {
36
- case 'BR':
37
- return '';
38
- case 'SPAN':
39
- if (node.className === 'linebreak') return '';
40
- }
41
- continue;
33
+ if (!('id' in node)) return [...node.data.slice(-2)].pop() ?? '';
34
+ if (node.firstChild) return [...text(node).slice(-2)].pop() ?? '';
35
+ switch (node.tagName) {
36
+ case 'BR':
37
+ return '';
38
+ case 'SPAN':
39
+ switch (node.className) {
40
+ case 'linebreak':
41
+ return '';
42
+ }
42
43
  }
43
- const str = text(node);
44
- return str && [...str.slice(-2)].pop()!;
45
44
  }
46
45
  return '';
47
46
  }
48
47
 
49
- function text(node: Text | Element): string {
50
- if (!('id' in node)) return node.data;
51
- switch (node.tagName) {
48
+ function text(el: Element): string {
49
+ switch (el.tagName) {
52
50
  case 'RUBY':
53
- for (let ns = node.childNodes, i = ns.length; i--;) {
51
+ for (let ns = el.childNodes, i = ns.length; i--;) {
54
52
  const child = ns[i] as Text | Element;
55
53
  if ('id' in child) continue;
56
54
  return child.data;
@@ -58,6 +56,6 @@ function text(node: Text | Element): string {
58
56
  assert(false);
59
57
  return '';
60
58
  default:
61
- return node.textContent!;
59
+ return el.textContent!;
62
60
  }
63
61
  }
@@ -43,6 +43,6 @@ export function* segment(source: string): Generator<string, undefined, undefined
43
43
  }
44
44
 
45
45
  export function validate(source: string, size: number): boolean {
46
- return source.length <= size / 2
46
+ return source.length <= size / 4
47
47
  || source.length <= size && new Blob([source]).size <= size;
48
48
  }
@@ -16,6 +16,23 @@ export const text: TextParser = creator((source, context) => {
16
16
  case -1:
17
17
  return [[source], ''];
18
18
  case 0:
19
+ switch (source[0]) {
20
+ case '\\':
21
+ switch (source[1]) {
22
+ case '、':
23
+ case '。':
24
+ case '!':
25
+ case '?':
26
+ return text(source.slice(1), context);
27
+ }
28
+ break;
29
+ case '、':
30
+ case '。':
31
+ case '!':
32
+ case '?':
33
+ const i = source.slice(1).search(nonWhitespace) + 1;
34
+ if (i > 0 && source.slice(i, i + 2) === '\\\n') return [[source[0], html('span', { class: 'linebreak' })], source.slice(i + 2)];
35
+ }
19
36
  switch (source[0]) {
20
37
  case '\x7F':
21
38
  assert(source[1] === '\\');
@@ -39,15 +56,6 @@ export const text: TextParser = creator((source, context) => {
39
56
  return source[1] === source[0]
40
57
  ? repeat(source, context)
41
58
  : [[source[0]], source.slice(1)];
42
- case '、':
43
- case '。':
44
- case '!':
45
- // @ts-expect-error
46
- case '?': {
47
- const i = source.slice(1).search(nonWhitespace) + 1;
48
- if (i > 0 && source.slice(i, i + 2) === '\\\n') return [[source[0], html('span', { class: 'linebreak' })], source.slice(i + 2)];
49
- // fallthrough
50
- }
51
59
  default:
52
60
  assert(source[0] !== '\n');
53
61
  const b = source[0].trimStart() === '';