securemark 0.256.0 → 0.257.2

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +21 -8
  3. package/dist/index.js +237 -197
  4. package/markdown.d.ts +23 -17
  5. package/package.json +1 -1
  6. package/src/combinator/control/manipulation/context.ts +13 -2
  7. package/src/combinator/control/manipulation/resource.ts +36 -2
  8. package/src/combinator/control/manipulation/surround.ts +6 -6
  9. package/src/combinator/data/parser/inits.ts +1 -1
  10. package/src/combinator/data/parser/sequence.ts +1 -1
  11. package/src/combinator/data/parser/some.ts +16 -38
  12. package/src/combinator/data/parser.ts +34 -18
  13. package/src/debug.test.ts +2 -2
  14. package/src/parser/api/bind.ts +9 -11
  15. package/src/parser/api/parse.test.ts +48 -11
  16. package/src/parser/block.ts +1 -1
  17. package/src/parser/inline/annotation.test.ts +7 -5
  18. package/src/parser/inline/annotation.ts +10 -6
  19. package/src/parser/inline/autolink/account.ts +3 -7
  20. package/src/parser/inline/autolink/anchor.ts +3 -7
  21. package/src/parser/inline/autolink/hashnum.ts +3 -7
  22. package/src/parser/inline/autolink/hashtag.ts +3 -7
  23. package/src/parser/inline/autolink/url.test.ts +1 -0
  24. package/src/parser/inline/autolink/url.ts +7 -8
  25. package/src/parser/inline/bracket.test.ts +13 -7
  26. package/src/parser/inline/bracket.ts +10 -10
  27. package/src/parser/inline/comment.test.ts +5 -3
  28. package/src/parser/inline/comment.ts +4 -4
  29. package/src/parser/inline/deletion.ts +3 -3
  30. package/src/parser/inline/emphasis.ts +3 -3
  31. package/src/parser/inline/emstrong.ts +4 -5
  32. package/src/parser/inline/extension/index.test.ts +1 -0
  33. package/src/parser/inline/extension/index.ts +8 -7
  34. package/src/parser/inline/extension/indexer.ts +3 -5
  35. package/src/parser/inline/extension/label.ts +1 -1
  36. package/src/parser/inline/extension/placeholder.test.ts +1 -0
  37. package/src/parser/inline/extension/placeholder.ts +4 -4
  38. package/src/parser/inline/html.test.ts +2 -0
  39. package/src/parser/inline/html.ts +5 -5
  40. package/src/parser/inline/insertion.ts +3 -3
  41. package/src/parser/inline/link.test.ts +1 -0
  42. package/src/parser/inline/link.ts +58 -17
  43. package/src/parser/inline/mark.ts +3 -3
  44. package/src/parser/inline/math.test.ts +21 -14
  45. package/src/parser/inline/math.ts +7 -19
  46. package/src/parser/inline/media.test.ts +0 -2
  47. package/src/parser/inline/media.ts +10 -10
  48. package/src/parser/inline/reference.test.ts +6 -5
  49. package/src/parser/inline/reference.ts +12 -8
  50. package/src/parser/inline/ruby.ts +29 -27
  51. package/src/parser/inline/strong.ts +3 -3
  52. package/src/parser/inline/template.ts +4 -4
  53. package/src/parser/inline.test.ts +13 -8
  54. package/src/parser/inline.ts +1 -0
  55. package/src/parser/util.ts +35 -19
@@ -5,9 +5,25 @@ import { union, some, verify, convert, fmap } from '../combinator';
5
5
  import { unsafehtmlentity } from './inline/htmlentity';
6
6
  import { linebreak, unescsource } from './source';
7
7
  import { invisibleHTMLEntityNames } from './api/normalize';
8
- import { reduce } from 'spica/memoize';
8
+ import { memoize, reduce } from 'spica/memoize';
9
9
  import { push } from 'spica/array';
10
10
 
11
+ export function clean<P extends Parser<unknown>>(parser: P): P;
12
+ export function clean<T>(parser: Parser<T, MarkdownParser.Context>): Parser<T, MarkdownParser.Context> {
13
+ const clean = memoize<MarkdownParser.Context, MarkdownParser.Context>(context => ({
14
+ resources: context.resources,
15
+ precedence: context.precedence,
16
+ delimiters: context.delimiters,
17
+ host: context.host,
18
+ url: context.url,
19
+ id: context.id,
20
+ header: context.header,
21
+ cache: context.caches,
22
+ }), new WeakMap());
23
+ return (source, context) =>
24
+ parser(source, context.syntax ? clean(context) : context);
25
+ }
26
+
11
27
  export const regBlankStart = new RegExp(
12
28
  /^(?:\\?[^\S\n]|&IHN;|<wbr>)+/.source.replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`));
13
29
 
@@ -166,24 +182,24 @@ export function trimBlankEnd<T extends HTMLElement | string>(parser: Parser<T>):
166
182
  parser,
167
183
  trimNodeEnd);
168
184
  }
169
- //export function trimNode(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
170
- // return trimNodeStart(trimNodeEnd(nodes));
171
- //}
172
- //function trimNodeStart(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
173
- // for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
174
- // if (nodes.length === 1 && typeof node === 'object' && node.className === 'indexer') break;
175
- // if (typeof node === 'string') {
176
- // const pos = node.length - node.trimStart().length;
177
- // if (pos > 0) {
178
- // nodes[0] = node.slice(pos);
179
- // break;
180
- // }
181
- // }
182
- // nodes.shift();
183
- // }
184
- // return nodes;
185
- //}
186
- export function trimNodeEnd<T extends HTMLElement | string>(nodes: T[]): T[] {
185
+ export function trimNode<T extends HTMLElement | string>(nodes: T[]): T[] {
186
+ return trimNodeStart(trimNodeEnd(nodes));
187
+ }
188
+ function trimNodeStart<T extends HTMLElement | string>(nodes: T[]): T[] {
189
+ for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
190
+ if (nodes.length === 1 && typeof node === 'object' && node.className === 'indexer') break;
191
+ if (typeof node === 'string') {
192
+ const pos = node.trimStart().length;
193
+ if (pos > 0) {
194
+ nodes[0] = node.slice(pos) as T;
195
+ break;
196
+ }
197
+ }
198
+ nodes.shift();
199
+ }
200
+ return nodes;
201
+ }
202
+ function trimNodeEnd<T extends HTMLElement | string>(nodes: T[]): T[] {
187
203
  const skip = nodes.length > 0 &&
188
204
  typeof nodes[nodes.length - 1] === 'object' &&
189
205
  nodes[nodes.length - 1]['className'] === 'indexer'