securemark 0.231.2 → 0.232.0

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,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.232.0
4
+
5
+ - Refine paragraph syntax to separate mention syntax.
6
+ - Rename mention syntax to reply syntax.
7
+
3
8
  ## 0.231.2
4
9
 
5
10
  - Refactoring.
@@ -1,4 +1,4 @@
1
- /*! securemark v0.231.2 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED */
1
+ /*! securemark v0.232.0 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) {
@@ -4544,6 +4544,7 @@ require = function () {
4544
4544
  const codeblock_1 = _dereq_('./block/codeblock');
4545
4545
  const mathblock_1 = _dereq_('./block/mathblock');
4546
4546
  const extension_1 = _dereq_('./block/extension');
4547
+ const reply_1 = _dereq_('./block/reply');
4547
4548
  const paragraph_1 = _dereq_('./block/paragraph');
4548
4549
  const typed_dom_1 = _dereq_('typed-dom');
4549
4550
  const random_1 = _dereq_('spica/random');
@@ -4560,6 +4561,7 @@ require = function () {
4560
4561
  mathblock_1.mathblock,
4561
4562
  extension_1.extension,
4562
4563
  blockquote_1.blockquote,
4564
+ reply_1.reply,
4563
4565
  paragraph_1.paragraph
4564
4566
  ]))));
4565
4567
  function error(parser) {
@@ -4593,6 +4595,7 @@ require = function () {
4593
4595
  './block/mathblock': 79,
4594
4596
  './block/olist': 80,
4595
4597
  './block/paragraph': 81,
4598
+ './block/reply': 82,
4596
4599
  './block/table': 85,
4597
4600
  './block/ulist': 86,
4598
4601
  './source': 128,
@@ -5307,7 +5310,7 @@ require = function () {
5307
5310
  colspan,
5308
5311
  ...valid ? { 'data-highlight-level': +highlight > 1 ? highlight : global_1.undefined } : {
5309
5312
  'data-invalid-syntax': 'table',
5310
- 'data-invalid-type': 'highlight',
5313
+ 'data-invalid-type': 'syntax',
5311
5314
  'data-invalid-description': 'Too much highlight level.'
5312
5315
  }
5313
5316
  };
@@ -5776,31 +5779,17 @@ require = function () {
5776
5779
  Object.defineProperty(exports, '__esModule', { value: true });
5777
5780
  exports.paragraph = void 0;
5778
5781
  const combinator_1 = _dereq_('../../combinator');
5779
- const mention_1 = _dereq_('./paragraph/mention');
5780
- const quote_1 = _dereq_('./paragraph/mention/quote');
5781
5782
  const inline_1 = _dereq_('../inline');
5782
- const source_1 = _dereq_('../source');
5783
5783
  const locale_1 = _dereq_('../locale');
5784
5784
  const util_1 = _dereq_('../util');
5785
5785
  const typed_dom_1 = _dereq_('typed-dom');
5786
- const array_1 = _dereq_('spica/array');
5787
- exports.paragraph = (0, combinator_1.block)((0, locale_1.localize)((0, combinator_1.fmap)((0, combinator_1.subsequence)([
5788
- (0, combinator_1.some)(mention_1.mention),
5789
- (0, combinator_1.some)((0, combinator_1.union)([
5790
- quote_1.quote,
5791
- (0, combinator_1.fmap)((0, combinator_1.rewrite)((0, combinator_1.some)(source_1.anyline, quote_1.syntax), (0, combinator_1.trim)((0, util_1.visualize)((0, combinator_1.some)(inline_1.inline)))), ns => (0, array_1.push)(ns, [(0, typed_dom_1.html)('br')]))
5792
- ]))
5793
- ]), ns => [(0, typed_dom_1.html)('p', (0, typed_dom_1.defrag)((0, array_1.pop)(ns)[0]))])));
5786
+ exports.paragraph = (0, combinator_1.block)((0, locale_1.localize)((0, combinator_1.fmap)((0, combinator_1.trim)((0, util_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline])))), ns => [(0, typed_dom_1.html)('p', (0, typed_dom_1.defrag)(ns))])));
5794
5787
  },
5795
5788
  {
5796
5789
  '../../combinator': 27,
5797
5790
  '../inline': 88,
5798
5791
  '../locale': 123,
5799
- '../source': 128,
5800
5792
  '../util': 134,
5801
- './paragraph/mention': 82,
5802
- './paragraph/mention/quote': 84,
5803
- 'spica/array': 6,
5804
5793
  'typed-dom': 26
5805
5794
  }
5806
5795
  ],
@@ -5808,19 +5797,37 @@ require = function () {
5808
5797
  function (_dereq_, module, exports) {
5809
5798
  'use strict';
5810
5799
  Object.defineProperty(exports, '__esModule', { value: true });
5811
- exports.mention = void 0;
5812
- const combinator_1 = _dereq_('../../../combinator');
5813
- const cite_1 = _dereq_('./mention/cite');
5814
- const quote_1 = _dereq_('./mention/quote');
5815
- exports.mention = (0, combinator_1.validate)('>', (0, combinator_1.inits)([
5816
- (0, combinator_1.some)(cite_1.cite),
5817
- quote_1.quote
5818
- ]));
5800
+ exports.reply = void 0;
5801
+ const combinator_1 = _dereq_('../../combinator');
5802
+ const cite_1 = _dereq_('./reply/cite');
5803
+ const quote_1 = _dereq_('./reply/quote');
5804
+ const inline_1 = _dereq_('../inline');
5805
+ const source_1 = _dereq_('../source');
5806
+ const locale_1 = _dereq_('../locale');
5807
+ const util_1 = _dereq_('../util');
5808
+ const typed_dom_1 = _dereq_('typed-dom');
5809
+ const array_1 = _dereq_('spica/array');
5810
+ exports.reply = (0, combinator_1.block)((0, combinator_1.validate)('>', (0, locale_1.localize)((0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.inits)([
5811
+ (0, combinator_1.some)((0, combinator_1.inits)([
5812
+ cite_1.cite,
5813
+ quote_1.quote
5814
+ ])),
5815
+ (0, combinator_1.subsequence)([
5816
+ (0, combinator_1.some)(quote_1.quote),
5817
+ (0, combinator_1.fmap)((0, combinator_1.rewrite)((0, combinator_1.some)(source_1.anyline, quote_1.syntax), (0, combinator_1.trim)((0, util_1.visualize)((0, combinator_1.some)(inline_1.inline)))), ns => (0, array_1.push)(ns, [(0, typed_dom_1.html)('br')]))
5818
+ ])
5819
+ ])), ns => [(0, typed_dom_1.html)('p', (0, typed_dom_1.defrag)((0, array_1.pop)(ns)[0]))]))));
5819
5820
  },
5820
5821
  {
5821
- '../../../combinator': 27,
5822
- './mention/cite': 83,
5823
- './mention/quote': 84
5822
+ '../../combinator': 27,
5823
+ '../inline': 88,
5824
+ '../locale': 123,
5825
+ '../source': 128,
5826
+ '../util': 134,
5827
+ './reply/cite': 83,
5828
+ './reply/quote': 84,
5829
+ 'spica/array': 6,
5830
+ 'typed-dom': 26
5824
5831
  }
5825
5832
  ],
5826
5833
  83: [
@@ -5828,9 +5835,9 @@ require = function () {
5828
5835
  'use strict';
5829
5836
  Object.defineProperty(exports, '__esModule', { value: true });
5830
5837
  exports.cite = void 0;
5831
- const combinator_1 = _dereq_('../../../../combinator');
5832
- const anchor_1 = _dereq_('../../../inline/autolink/anchor');
5833
- const source_1 = _dereq_('../../../source');
5838
+ const combinator_1 = _dereq_('../../../combinator');
5839
+ const anchor_1 = _dereq_('../../inline/autolink/anchor');
5840
+ const source_1 = _dereq_('../../source');
5834
5841
  const typed_dom_1 = _dereq_('typed-dom');
5835
5842
  exports.cite = (0, combinator_1.creator)((0, combinator_1.line)((0, combinator_1.fmap)((0, combinator_1.validate)('>>', (0, combinator_1.reverse)((0, combinator_1.tails)([
5836
5843
  (0, source_1.str)(/^>*(?=>>)/),
@@ -5844,9 +5851,9 @@ require = function () {
5844
5851
  ])));
5845
5852
  },
5846
5853
  {
5847
- '../../../../combinator': 27,
5848
- '../../../inline/autolink/anchor': 92,
5849
- '../../../source': 128,
5854
+ '../../../combinator': 27,
5855
+ '../../inline/autolink/anchor': 92,
5856
+ '../../source': 128,
5850
5857
  'typed-dom': 26
5851
5858
  }
5852
5859
  ],
@@ -5855,11 +5862,11 @@ require = function () {
5855
5862
  'use strict';
5856
5863
  Object.defineProperty(exports, '__esModule', { value: true });
5857
5864
  exports.quote = exports.syntax = void 0;
5858
- const parser_1 = _dereq_('../../../../combinator/data/parser');
5859
- const combinator_1 = _dereq_('../../../../combinator');
5860
- const math_1 = _dereq_('../../../inline/math');
5861
- const source_1 = _dereq_('../../../source');
5862
- const autolink_1 = _dereq_('../../../autolink');
5865
+ const parser_1 = _dereq_('../../../combinator/data/parser');
5866
+ const combinator_1 = _dereq_('../../../combinator');
5867
+ const math_1 = _dereq_('../../inline/math');
5868
+ const source_1 = _dereq_('../../source');
5869
+ const autolink_1 = _dereq_('../../autolink');
5863
5870
  const typed_dom_1 = _dereq_('typed-dom');
5864
5871
  exports.syntax = /^>+(?=[^\S\n])|^>(?=[^\s>])|^>+(?=[^\s>])(?![0-9a-z]+(?:-[0-9a-z]+)*(?![0-9A-Za-z@#:]))/;
5865
5872
  exports.quote = (0, combinator_1.lazy)(() => (0, combinator_1.creator)((0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)('>', (0, combinator_1.union)([
@@ -5912,11 +5919,11 @@ require = function () {
5912
5919
  ]);
5913
5920
  },
5914
5921
  {
5915
- '../../../../combinator': 27,
5916
- '../../../../combinator/data/parser': 47,
5917
- '../../../autolink': 62,
5918
- '../../../inline/math': 116,
5919
- '../../../source': 128,
5922
+ '../../../combinator': 27,
5923
+ '../../../combinator/data/parser': 47,
5924
+ '../../autolink': 62,
5925
+ '../../inline/math': 116,
5926
+ '../../source': 128,
5920
5927
  'typed-dom': 26
5921
5928
  }
5922
5929
  ],
@@ -9350,7 +9357,7 @@ require = function () {
9350
9357
  exports.info = void 0;
9351
9358
  const scope_1 = _dereq_('./scope');
9352
9359
  function info(source) {
9353
- const match = (0, scope_1.scope)(source, 'section, article, aside, blockquote, .quote, pre, .math, .media');
9360
+ const match = (0, scope_1.scope)(source, '.invalid');
9354
9361
  return {
9355
9362
  url: find('a:not(.email):not(.account):not(.channel):not(.hashtag):not(.hashnum):not(.anchor)').filter(el => [
9356
9363
  'http:',
@@ -9362,7 +9369,7 @@ require = function () {
9362
9369
  channel: find('a.channel'),
9363
9370
  hashtag: find('a.hashtag'),
9364
9371
  hashnum: find('a.hashnum'),
9365
- mention: find('.cite > a.anchor'),
9372
+ reply: find('.cite > a.anchor'),
9366
9373
  anchor: find(':not(.cite) > a.anchor'),
9367
9374
  media: find('.media[data-src]')
9368
9375
  };
@@ -9387,7 +9394,7 @@ require = function () {
9387
9394
  Object.defineProperty(exports, '__esModule', { value: true });
9388
9395
  exports.quote = void 0;
9389
9396
  const parser_1 = _dereq_('../combinator/data/parser');
9390
- const cite_1 = _dereq_('../parser/block/paragraph/mention/cite');
9397
+ const cite_1 = _dereq_('../parser/block/reply/cite');
9391
9398
  const typed_dom_1 = _dereq_('typed-dom');
9392
9399
  function quote(anchor, range) {
9393
9400
  var _a, _b;
@@ -9466,7 +9473,7 @@ require = function () {
9466
9473
  },
9467
9474
  {
9468
9475
  '../combinator/data/parser': 47,
9469
- '../parser/block/paragraph/mention/cite': 83,
9476
+ '../parser/block/reply/cite': 83,
9470
9477
  'typed-dom': 26
9471
9478
  }
9472
9479
  ],
@@ -9476,7 +9483,8 @@ require = function () {
9476
9483
  Object.defineProperty(exports, '__esModule', { value: true });
9477
9484
  exports.scope = void 0;
9478
9485
  const global_1 = _dereq_('spica/global');
9479
- function scope(base, bound = `${ 'id' in base && base.id ? `#${ base.id }, ` : '' }section, article, aside, blockquote`) {
9486
+ function scope(base, filter = '', bound = `${ 'id' in base && base.id ? `#${ base.id }, ` : '' }section, article, aside, blockquote, pre, .quote, .math, .media`) {
9487
+ bound += filter && `, ${ filter }`;
9480
9488
  const memory = new global_1.WeakMap();
9481
9489
  const context = 'id' in base && base.closest(bound) || null;
9482
9490
  return el => {
package/index.d.ts CHANGED
@@ -22,7 +22,7 @@ export function normalize(source: string): string;
22
22
  export function quote(anchor: string, range: Range): string;
23
23
  export function toc(source: DocumentFragment | HTMLElement | ShadowRoot): HTMLUListElement;
24
24
  export function info(source: DocumentFragment | HTMLElement | ShadowRoot): Info;
25
- export function scope(base: DocumentFragment | HTMLElement | ShadowRoot, bound?: string): (el: Element) => boolean;
25
+ export function scope(base: DocumentFragment | HTMLElement | ShadowRoot, filter?: string, bound?: string): (el: Element) => boolean;
26
26
  export function sync(editor: HTMLElement, viewer: HTMLElement, bottom?: Element | null): () => void;
27
27
 
28
28
  export type ParserOptions = Omit<Partial<ParserSettings>, 'chunk'>;
@@ -76,7 +76,7 @@ export interface Info {
76
76
  readonly channel: HTMLAnchorElement[];
77
77
  readonly hashtag: HTMLAnchorElement[];
78
78
  readonly hashnum: HTMLAnchorElement[];
79
- readonly mention: HTMLAnchorElement[];
79
+ readonly reply: HTMLAnchorElement[];
80
80
  readonly anchor: HTMLAnchorElement[];
81
81
  readonly media: HTMLElement[];
82
82
  }
package/markdown.d.ts CHANGED
@@ -87,6 +87,7 @@ export namespace MarkdownParser {
87
87
  BlockParser.MathBlockParser,
88
88
  BlockParser.ExtensionParser,
89
89
  BlockParser.BlockquoteParser,
90
+ BlockParser.ReplyParser,
90
91
  BlockParser.ParagraphParser,
91
92
  ]> {
92
93
  }
@@ -550,65 +551,66 @@ export namespace MarkdownParser {
550
551
  }
551
552
  }
552
553
  }
553
- export interface ParagraphParser extends
554
+ export interface ReplyParser extends
555
+ // >>1
556
+ // > text
554
557
  // abc
555
- Block<'paragraph'>,
558
+ Block<'reply'>,
556
559
  Parser<HTMLParagraphElement, Context, [
557
- ParagraphParser.MentionParser,
558
560
  Parser<string | HTMLElement, Context, [
559
- ParagraphParser.MentionParser.QuoteParser,
561
+ ReplyParser.CiteParser,
562
+ ReplyParser.QuoteParser,
563
+ ]>,
564
+ Parser<string | HTMLElement, Context, [
565
+ ReplyParser.QuoteParser,
560
566
  InlineParser,
561
567
  ]>,
562
568
  ]> {
563
569
  }
564
- export namespace ParagraphParser {
565
- export interface MentionParser extends
566
- // >>1
567
- // > text
568
- Block<'paragraph/mention'>,
570
+ export namespace ReplyParser {
571
+ export interface CiteParser extends
572
+ Block<'reply/cite'>,
569
573
  Parser<HTMLSpanElement | HTMLBRElement, Context, [
570
- ParagraphParser.MentionParser.CiteParser,
571
- ParagraphParser.MentionParser.QuoteParser,
574
+ SourceParser.StrParser,
575
+ InlineParser.AutolinkParser.AnchorParser,
572
576
  ]> {
573
577
  }
574
- export namespace MentionParser {
575
- export interface CiteParser extends
576
- Block<'paragraph/mention/cite'>,
577
- Parser<HTMLSpanElement | HTMLBRElement, Context, [
578
- SourceParser.StrParser,
579
- InlineParser.AutolinkParser.AnchorParser,
578
+ export interface QuoteParser extends
579
+ Block<'reply/quote'>,
580
+ Parser<HTMLSpanElement | HTMLBRElement, Context, [
581
+ QuoteParser.BlockParser,
582
+ QuoteParser.PlaceholderParser,
583
+ ]> {
584
+ }
585
+ export namespace QuoteParser {
586
+ export interface BlockParser extends
587
+ Block<'reply/quote/block'>,
588
+ Parser<string | HTMLElement, Context, [
589
+ TextParser,
580
590
  ]> {
581
591
  }
582
- export interface QuoteParser extends
583
- Block<'paragraph/mention/quote'>,
584
- Parser<HTMLSpanElement | HTMLBRElement, Context, [
585
- QuoteParser.BlockParser,
586
- QuoteParser.PlaceholderParser,
592
+ export interface TextParser extends
593
+ Block<'reply/quote/text'>,
594
+ Parser<string | HTMLElement, Context, [
595
+ InlineParser.MathParser,
596
+ AutolinkParser,
587
597
  ]> {
588
598
  }
589
- export namespace QuoteParser {
590
- export interface BlockParser extends
591
- Block<'paragraph/mention/quote/block'>,
592
- Parser<string | HTMLElement, Context, [
593
- TextParser,
594
- ]> {
595
- }
596
- export interface TextParser extends
597
- Block<'paragraph/mention/quote/text'>,
598
- Parser<string | HTMLElement, Context, [
599
- InlineParser.MathParser,
600
- AutolinkParser,
601
- ]> {
602
- }
603
- export interface PlaceholderParser extends
604
- Block<'paragraph/mention/quote/placeholder'>,
605
- Parser<string | HTMLElement, Context, [
606
- SourceParser.StrParser,
607
- ]> {
608
- }
599
+ export interface PlaceholderParser extends
600
+ Block<'reply/quote/placeholder'>,
601
+ Parser<string | HTMLElement, Context, [
602
+ SourceParser.StrParser,
603
+ ]> {
609
604
  }
610
605
  }
611
606
  }
607
+ export interface ParagraphParser extends
608
+ // abc
609
+ Block<'paragraph'>,
610
+ Parser<HTMLParagraphElement, Context, [
611
+ InlineParser,
612
+ ]> {
613
+ }
612
614
  }
613
615
  export interface InlineParser extends
614
616
  Markdown<'inline'>,
package/package-lock.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.231.2",
3
+ "version": "0.232.0",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
@@ -1918,9 +1918,9 @@
1918
1918
  "dev": true
1919
1919
  },
1920
1920
  "caniuse-lite": {
1921
- "version": "1.0.30001313",
1922
- "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001313.tgz",
1923
- "integrity": "sha512-rI1UN0koZUiKINjysQDuRi2VeSCce3bYJNmDcj3PIKREiAmjakugBul1QSkg/fPrlULYl6oWfGg3PbgOSY9X4Q==",
1921
+ "version": "1.0.30001314",
1922
+ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001314.tgz",
1923
+ "integrity": "sha512-0zaSO+TnCHtHJIbpLroX7nsD+vYuOVjl3uzFbJO1wMVbuveJA0RK2WcQA9ZUIOiO0/ArMiMgHJLxfEZhQiC0kw==",
1924
1924
  "dev": true
1925
1925
  },
1926
1926
  "chalk": {
@@ -3024,9 +3024,9 @@
3024
3024
  "dev": true
3025
3025
  },
3026
3026
  "electron-to-chromium": {
3027
- "version": "1.4.76",
3028
- "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.76.tgz",
3029
- "integrity": "sha512-3Vftv7cenJtQb+k00McEBZ2vVmZ/x+HEF7pcZONZIkOsESqAqVuACmBxMv0JhzX7u0YltU0vSqRqgBSTAhFUjA==",
3027
+ "version": "1.4.77",
3028
+ "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.77.tgz",
3029
+ "integrity": "sha512-fiDxw8mO9Ph1Z0bjX2sFTPpi0J0QkOiwOJF+5Q0J0baNc/F9lLePAvDPlnoxvbUYYMizqrKPeotRRkJ9LtxAew==",
3030
3030
  "dev": true
3031
3031
  },
3032
3032
  "elliptic": {
@@ -3243,14 +3243,14 @@
3243
3243
  }
3244
3244
  },
3245
3245
  "es5-ext": {
3246
- "version": "0.10.53",
3247
- "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.53.tgz",
3248
- "integrity": "sha512-Xs2Stw6NiNHWypzRTY1MtaG/uJlwCk8kH81920ma8mvN8Xq1gsfhZvpkImLQArw8AHnv8MT2I45J3c0R8slE+Q==",
3246
+ "version": "0.10.56",
3247
+ "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.56.tgz",
3248
+ "integrity": "sha512-YUhqzoMnIjMW5y8FzaMxsCu0eWCwq32GrlwhOhbQmL5OiZReWFm/KvRiYuvqf3CaG/zZ36Kyb4KfVe674cafCQ==",
3249
3249
  "dev": true,
3250
3250
  "requires": {
3251
- "es6-iterator": "~2.0.3",
3252
- "es6-symbol": "~3.1.3",
3253
- "next-tick": "~1.0.0"
3251
+ "es6-iterator": "^2.0.3",
3252
+ "es6-symbol": "^3.1.3",
3253
+ "next-tick": "^1.1.0"
3254
3254
  }
3255
3255
  },
3256
3256
  "es6-iterator": {
@@ -7896,9 +7896,9 @@
7896
7896
  "dev": true
7897
7897
  },
7898
7898
  "next-tick": {
7899
- "version": "1.0.0",
7900
- "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
7901
- "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=",
7899
+ "version": "1.1.0",
7900
+ "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz",
7901
+ "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==",
7902
7902
  "dev": true
7903
7903
  },
7904
7904
  "nice-try": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.231.2",
3
+ "version": "0.232.0",
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",
@@ -127,7 +127,7 @@ function attributes(source: string) {
127
127
  ? { 'data-highlight-level': +highlight! > 1 ? highlight : undefined }
128
128
  : {
129
129
  'data-invalid-syntax': 'table',
130
- 'data-invalid-type': 'highlight',
130
+ 'data-invalid-type': 'syntax',
131
131
  'data-invalid-description': 'Too much highlight level.',
132
132
  },
133
133
  };
@@ -28,28 +28,20 @@ describe('Unit: parser/block/paragraph', () => {
28
28
  assert.deepStrictEqual(inspect(parser(' a')), [['<p>a</p>'], '']);
29
29
  });
30
30
 
31
- it('mention', () => {
32
- assert.deepStrictEqual(inspect(parser('>>1')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span></p>'], '']);
33
- assert.deepStrictEqual(inspect(parser('>>1\na')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br>a</p>'], '']);
34
- assert.deepStrictEqual(inspect(parser('>>1\na\n>>2')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br>a<br><a href="?comment=2" class="anchor">&gt;&gt;2</a></p>'], '']);
35
- assert.deepStrictEqual(inspect(parser('>>1\n>>2')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br><span class="cite">&gt;<a href="?comment=2" class="anchor" data-depth="1">&gt;2</a></span></p>'], '']);
36
- assert.deepStrictEqual(inspect(parser('>>1\n> a')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br><span class="quote">&gt; a</span></p>'], '']);
37
- assert.deepStrictEqual(inspect(parser('>>1\n> a\nb')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br><span class="quote">&gt; a</span><br>b</p>'], '']);
38
- assert.deepStrictEqual(inspect(parser('>>1\n> a\n>>2')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br><span class="quote">&gt; a</span><br><span class="cite">&gt;<a href="?comment=2" class="anchor" data-depth="1">&gt;2</a></span></p>'], '']);
39
- assert.deepStrictEqual(inspect(parser('>>1\n> a\n>> b')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br><span class="quote">&gt; a<br>&gt;&gt; b</span></p>'], '']);
31
+ it('anchor', () => {
40
32
  assert.deepStrictEqual(inspect(parser('>>1 a\nb')), [['<p><a href="?comment=1" class="anchor">&gt;&gt;1</a> a<br>b</p>'], '']);
41
33
  assert.deepStrictEqual(inspect(parser('>>1 a\n>>2')), [['<p><a href="?comment=1" class="anchor">&gt;&gt;1</a> a<br><a href="?comment=2" class="anchor">&gt;&gt;2</a></p>'], '']);
42
34
  assert.deepStrictEqual(inspect(parser('>>1 a\n>>b')), [['<p><a href="?comment=1" class="anchor">&gt;&gt;1</a> a<br><a href="?comment=b" class="anchor">&gt;&gt;b</a></p>'], '']);
43
- assert.deepStrictEqual(inspect(parser('>>1 a\n>> b')), [['<p><a href="?comment=1" class="anchor">&gt;&gt;1</a> a<br><span class="quote">&gt;&gt; b</span></p>'], '']);
35
+ assert.deepStrictEqual(inspect(parser('>>1 a\n>> b')), [['<p><a href="?comment=1" class="anchor">&gt;&gt;1</a> a<br>&gt;&gt; b</p>'], '']);
44
36
  assert.deepStrictEqual(inspect(parser('>>11.')), [['<p><a href="?comment=11" class="anchor">&gt;&gt;11</a>.</p>'], '']);
45
37
  assert.deepStrictEqual(inspect(parser('>>11 a')), [['<p><a href="?comment=11" class="anchor">&gt;&gt;11</a> a</p>'], '']);
46
38
  assert.deepStrictEqual(inspect(parser('>>>11 a')), [['<p>&gt;<a href="?comment=11" class="anchor">&gt;&gt;11</a> a</p>'], '']);
47
- assert.deepStrictEqual(inspect(parser('>> a\n>>1')), [['<p><span class="quote">&gt;&gt; a</span><br><a href="?comment=1" class="anchor">&gt;&gt;1</a></p>'], '']);
39
+ assert.deepStrictEqual(inspect(parser('>> a\n>>1')), [['<p>&gt;&gt; a<br><a href="?comment=1" class="anchor">&gt;&gt;1</a></p>'], '']);
48
40
  assert.deepStrictEqual(inspect(parser('a>>1')), [['<p>a<a href="?comment=1" class="anchor">&gt;&gt;1</a></p>'], '']);
49
41
  assert.deepStrictEqual(inspect(parser('a >>1')), [['<p>a <a href="?comment=1" class="anchor">&gt;&gt;1</a></p>'], '']);
50
42
  assert.deepStrictEqual(inspect(parser('a\n>>1')), [['<p>a<br><a href="?comment=1" class="anchor">&gt;&gt;1</a></p>'], '']);
51
43
  assert.deepStrictEqual(inspect(parser('a\n>>1\nb')), [['<p>a<br><a href="?comment=1" class="anchor">&gt;&gt;1</a><br>b</p>'], '']);
52
- assert.deepStrictEqual(inspect(parser('a\n>> b\nc')), [['<p>a<br><span class="quote">&gt;&gt; b</span><br>c</p>'], '']);
44
+ assert.deepStrictEqual(inspect(parser('a\n>> b\nc')), [['<p>a<br>&gt;&gt; b<br>c</p>'], '']);
53
45
  assert.deepStrictEqual(inspect(parser(' >>1')), [['<p><a href="?comment=1" class="anchor">&gt;&gt;1</a></p>'], '']);
54
46
  assert.deepStrictEqual(inspect(parser(' >>>1')), [['<p>&gt;<a href="?comment=1" class="anchor">&gt;&gt;1</a></p>'], '']);
55
47
  });
@@ -1,24 +1,10 @@
1
1
  import { ParagraphParser } from '../block';
2
- import { union, subsequence, some, block, rewrite, trim, fmap } from '../../combinator';
3
- import { mention } from './paragraph/mention';
4
- import { quote, syntax as delimiter } from './paragraph/mention/quote';
2
+ import { union, some, block, trim, fmap } from '../../combinator';
5
3
  import { inline } from '../inline';
6
- import { anyline } from '../source';
7
4
  import { localize } from '../locale';
8
5
  import { visualize } from '../util';
9
6
  import { html, defrag } from 'typed-dom';
10
- import { push, pop } from 'spica/array';
11
7
 
12
8
  export const paragraph: ParagraphParser = block(localize(fmap(
13
- subsequence([
14
- some(mention),
15
- some(union([
16
- quote,
17
- fmap(
18
- rewrite(
19
- some(anyline, delimiter),
20
- trim(visualize(some(inline)))),
21
- ns => push(ns, [html('br')])),
22
- ])),
23
- ]),
24
- ns => [html('p', defrag(pop(ns)[0]))])));
9
+ trim(visualize(some(union([inline])))),
10
+ ns => [html('p', defrag(ns))])));
@@ -1,8 +1,8 @@
1
1
  import { cite } from './cite';
2
- import { some } from '../../../../combinator';
3
- import { inspect } from '../../../../debug.test';
2
+ import { some } from '../../../combinator';
3
+ import { inspect } from '../../../debug.test';
4
4
 
5
- describe('Unit: parser/block/paragraph/mention/cite', () => {
5
+ describe('Unit: parser/block/reply/cite', () => {
6
6
  describe('cite', () => {
7
7
  const parser = (source: string) => some(cite)(source, {});
8
8
 
@@ -1,10 +1,10 @@
1
- import { ParagraphParser } from '../../../block';
2
- import { tails, line, validate, creator, reverse, fmap } from '../../../../combinator';
3
- import { anchor } from '../../../inline/autolink/anchor';
4
- import { str } from '../../../source';
1
+ import { ReplyParser } from '../../block';
2
+ import { tails, line, validate, creator, reverse, fmap } from '../../../combinator';
3
+ import { anchor } from '../../inline/autolink/anchor';
4
+ import { str } from '../../source';
5
5
  import { html, define, defrag } from 'typed-dom';
6
6
 
7
- export const cite: ParagraphParser.MentionParser.CiteParser = creator(line(fmap(validate(
7
+ export const cite: ReplyParser.CiteParser = creator(line(fmap(validate(
8
8
  '>>',
9
9
  reverse(tails([
10
10
  str(/^>*(?=>>)/),
@@ -1,8 +1,8 @@
1
1
  import { quote } from './quote';
2
- import { some } from '../../../../combinator';
3
- import { inspect } from '../../../../debug.test';
2
+ import { some } from '../../../combinator';
3
+ import { inspect } from '../../../debug.test';
4
4
 
5
- describe('Unit: parser/block/paragraph/mention/quote', () => {
5
+ describe('Unit: parser/block/reply/quote', () => {
6
6
  describe('quote', () => {
7
7
  const parser = (source: string) => some(quote)(source, {});
8
8
 
@@ -1,14 +1,14 @@
1
- import { ParagraphParser } from '../../../block';
2
- import { eval } from '../../../../combinator/data/parser';
3
- import { union, some, block, line, validate, rewrite, creator, lazy, fmap } from '../../../../combinator';
4
- import { math } from '../../../inline/math';
5
- import { str, anyline } from '../../../source';
6
- import { autolink } from '../../../autolink';
1
+ import { ReplyParser } from '../../block';
2
+ import { eval } from '../../../combinator/data/parser';
3
+ import { union, some, block, line, validate, rewrite, creator, lazy, fmap } from '../../../combinator';
4
+ import { math } from '../../inline/math';
5
+ import { str, anyline } from '../../source';
6
+ import { autolink } from '../../autolink';
7
7
  import { html, defrag } from 'typed-dom';
8
8
 
9
9
  export const syntax = /^>+(?=[^\S\n])|^>(?=[^\s>])|^>+(?=[^\s>])(?![0-9a-z]+(?:-[0-9a-z]+)*(?![0-9A-Za-z@#:]))/;
10
10
 
11
- export const quote: ParagraphParser.MentionParser.QuoteParser = lazy(() => creator(block(fmap(validate(
11
+ export const quote: ReplyParser.QuoteParser = lazy(() => creator(block(fmap(validate(
12
12
  '>',
13
13
  union([
14
14
  rewrite(
@@ -33,7 +33,7 @@ export const quote: ParagraphParser.MentionParser.QuoteParser = lazy(() => creat
33
33
  ]),
34
34
  false)));
35
35
 
36
- const qblock: ParagraphParser.MentionParser.QuoteParser.BlockParser = (source, context) => {
36
+ const qblock: ReplyParser.QuoteParser.BlockParser = (source, context) => {
37
37
  source = source.replace(/\n$/, '');
38
38
  const lines = source.match(/^.*\n?/mg)!;
39
39
  assert(lines);
@@ -69,7 +69,7 @@ const qblock: ParagraphParser.MentionParser.QuoteParser.BlockParser = (source, c
69
69
  return [defrag(nodes), ''];
70
70
  };
71
71
 
72
- const text: ParagraphParser.MentionParser.QuoteParser.TextParser = union([
72
+ const text: ReplyParser.QuoteParser.TextParser = union([
73
73
  math,
74
74
  autolink,
75
75
  ]);
@@ -0,0 +1,22 @@
1
+ import { reply } from './reply';
2
+ import { some } from '../../combinator';
3
+ import { inspect } from '../../debug.test';
4
+
5
+ describe('Unit: parser/block/reply', () => {
6
+ describe('reply', () => {
7
+ const parser = (source: string) => some(reply)(source, {});
8
+
9
+ it('basic', () => {
10
+ assert.deepStrictEqual(inspect(parser('>>1')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span></p>'], '']);
11
+ assert.deepStrictEqual(inspect(parser('>>1\na')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br>a</p>'], '']);
12
+ assert.deepStrictEqual(inspect(parser('>>1\na\n>>2')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br>a<br><a href="?comment=2" class="anchor">&gt;&gt;2</a></p>'], '']);
13
+ assert.deepStrictEqual(inspect(parser('>>1\n>>2')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br><span class="cite">&gt;<a href="?comment=2" class="anchor" data-depth="1">&gt;2</a></span></p>'], '']);
14
+ assert.deepStrictEqual(inspect(parser('>>1\n> a')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br><span class="quote">&gt; a</span></p>'], '']);
15
+ assert.deepStrictEqual(inspect(parser('>>1\n> a\nb')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br><span class="quote">&gt; a</span><br>b</p>'], '']);
16
+ assert.deepStrictEqual(inspect(parser('>>1\n> a\n>>2')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br><span class="quote">&gt; a</span><br><span class="cite">&gt;<a href="?comment=2" class="anchor" data-depth="1">&gt;2</a></span></p>'], '']);
17
+ assert.deepStrictEqual(inspect(parser('>>1\n> a\n>> b')), [['<p><span class="cite">&gt;<a href="?comment=1" class="anchor" data-depth="1">&gt;1</a></span><br><span class="quote">&gt; a<br>&gt;&gt; b</span></p>'], '']);
18
+ });
19
+
20
+ });
21
+
22
+ });
@@ -0,0 +1,27 @@
1
+ import { ReplyParser } from '../block';
2
+ import { inits, subsequence, some, block, validate, rewrite, trim, fmap } from '../../combinator';
3
+ import { cite } from './reply/cite';
4
+ import { quote, syntax as delimiter } from './reply/quote';
5
+ import { inline } from '../inline';
6
+ import { anyline } from '../source';
7
+ import { localize } from '../locale';
8
+ import { visualize } from '../util';
9
+ import { html, defrag } from 'typed-dom';
10
+ import { push, pop } from 'spica/array';
11
+
12
+ export const reply: ReplyParser = block(validate('>', localize(fmap(
13
+ some(inits([
14
+ some(inits([
15
+ cite,
16
+ quote,
17
+ ])),
18
+ subsequence([
19
+ some(quote),
20
+ fmap(
21
+ rewrite(
22
+ some(anyline, delimiter),
23
+ trim(visualize(some(inline)))),
24
+ ns => push(ns, [html('br')])),
25
+ ]),
26
+ ])),
27
+ ns => [html('p', defrag(pop(ns)[0]))]))));
@@ -13,6 +13,7 @@ import { blockquote } from './block/blockquote';
13
13
  import { codeblock } from './block/codeblock';
14
14
  import { mathblock } from './block/mathblock';
15
15
  import { extension } from './block/extension';
16
+ import { reply } from './block/reply';
16
17
  import { paragraph } from './block/paragraph';
17
18
  import { html } from 'typed-dom';
18
19
  import { rnd0Z } from 'spica/random';
@@ -29,6 +30,7 @@ export import CodeBlockParser = BlockParser.CodeBlockParser;
29
30
  export import MathBlockParser = BlockParser.MathBlockParser;
30
31
  export import ExtensionParser = BlockParser.ExtensionParser;
31
32
  export import BlockquoteParser = BlockParser.BlockquoteParser;
33
+ export import ReplyParser = BlockParser.ReplyParser;
32
34
  export import ParagraphParser = BlockParser.ParagraphParser;
33
35
 
34
36
  export const block: BlockParser = creator(error(
@@ -46,6 +48,7 @@ export const block: BlockParser = creator(error(
46
48
  mathblock,
47
49
  extension,
48
50
  blockquote,
51
+ reply,
49
52
  paragraph
50
53
  ]))));
51
54
 
@@ -229,7 +229,7 @@ export function stringify(nodes: readonly (HTMLElement | string)[]): string {
229
229
  }
230
230
  else {
231
231
  assert(!node.matches('br') && !node.querySelector('br'));
232
- // Note: Doesn't reflect line breaks.
232
+ // NOTE: Doesn't reflect line breaks.
233
233
  acc += node.innerText;
234
234
  }
235
235
  }
@@ -14,7 +14,7 @@ describe('Unit: util/info', () => {
14
14
  channel: [],
15
15
  hashtag: [],
16
16
  hashnum: [],
17
- mention: [],
17
+ reply: [],
18
18
  anchor: [],
19
19
  media: [],
20
20
  });
package/src/util/info.ts CHANGED
@@ -2,7 +2,7 @@ import { Info } from '../..';
2
2
  import { scope } from './scope';
3
3
 
4
4
  export function info(source: DocumentFragment | HTMLElement | ShadowRoot): Info {
5
- const match = scope(source, 'section, article, aside, blockquote, .quote, pre, .math, .media');
5
+ const match = scope(source, '.invalid');
6
6
  return {
7
7
  url: find<HTMLAnchorElement>('a:not(.email):not(.account):not(.channel):not(.hashtag):not(.hashnum):not(.anchor)')
8
8
  .filter(el => ['http:', 'https:'].includes(el.protocol)),
@@ -13,7 +13,7 @@ export function info(source: DocumentFragment | HTMLElement | ShadowRoot): Info
13
13
  channel: find('a.channel'),
14
14
  hashtag: find('a.hashtag'),
15
15
  hashnum: find('a.hashnum'),
16
- mention: find('.cite > a.anchor'),
16
+ reply: find('.cite > a.anchor'),
17
17
  anchor: find(':not(.cite) > a.anchor'),
18
18
  media: find('.media[data-src]'),
19
19
  };
package/src/util/quote.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { exec } from '../combinator/data/parser';
2
- import { cite } from '../parser/block/paragraph/mention/cite';
2
+ import { cite } from '../parser/block/reply/cite';
3
3
  import { define } from 'typed-dom';
4
4
 
5
5
  export function quote(anchor: string, range: Range): string {
package/src/util/scope.ts CHANGED
@@ -2,8 +2,10 @@ import { undefined, WeakMap } from 'spica/global';
2
2
 
3
3
  export function scope(
4
4
  base: DocumentFragment | HTMLElement | ShadowRoot,
5
- bound: string = `${'id' in base && base.id ? `#${base.id}, ` : ''}section, article, aside, blockquote`,
5
+ filter: string = '',
6
+ bound: string = `${'id' in base && base.id ? `#${base.id}, ` : ''}section, article, aside, blockquote, pre, .quote, .math, .media`,
6
7
  ): (el: Element) => boolean {
8
+ bound += filter && `, ${filter}`;
7
9
  const memory = new WeakMap<Node, boolean>();
8
10
  const context = 'id' in base && base.closest(bound) || null;
9
11
  return el => {
@@ -1,9 +0,0 @@
1
- import { ParagraphParser } from '../../block';
2
- import { inits, some, validate } from '../../../combinator';
3
- import { cite } from './mention/cite';
4
- import { quote } from './mention/quote';
5
-
6
- export const mention: ParagraphParser.MentionParser = validate('>', inits([
7
- some(cite),
8
- quote,
9
- ]));