securemark 0.280.0 → 0.280.1
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 +4 -0
- package/dist/index.js +6 -42
- package/markdown.d.ts +0 -6
- package/package.json +1 -1
- package/src/combinator/data/parser/context/delimiter.ts +1 -1
- package/src/combinator/data/parser/some.ts +1 -1
- package/src/parser/api/bind.ts +4 -1
- package/src/parser/api/parse.ts +4 -1
- package/src/parser/block/heading.ts +1 -1
- package/src/parser/block/reply/quote.ts +9 -46
- package/src/util/toc.ts +4 -1
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! securemark v0.280.
|
|
1
|
+
/*! securemark v0.280.1 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"));
|
|
@@ -3547,7 +3547,7 @@ class Delimiters {
|
|
|
3547
3547
|
return `r/${pattern.source}/${pattern.flags}`;
|
|
3548
3548
|
}
|
|
3549
3549
|
}
|
|
3550
|
-
push(
|
|
3550
|
+
push(delims) {
|
|
3551
3551
|
const {
|
|
3552
3552
|
registry,
|
|
3553
3553
|
delimiters,
|
|
@@ -3781,7 +3781,7 @@ function some(parser, end, delimiters = [], limit = -1) {
|
|
|
3781
3781
|
let nodes;
|
|
3782
3782
|
if (delims.length > 0) {
|
|
3783
3783
|
context.delimiters ??= new delimiter_1.Delimiters();
|
|
3784
|
-
context.delimiters.push(
|
|
3784
|
+
context.delimiters.push(delims);
|
|
3785
3785
|
}
|
|
3786
3786
|
while (true) {
|
|
3787
3787
|
if (rest === '') break;
|
|
@@ -5254,7 +5254,7 @@ const dom_1 = __webpack_require__(3252);
|
|
|
5254
5254
|
exports.segment = (0, combinator_1.block)((0, combinator_1.validate)('#', (0, combinator_1.focus)(/^#+[^\S\n]+\S[^\n]*(?:\n#+(?!\S)[^\n]*)*(?:$|\n)/, (0, combinator_1.some)((0, combinator_1.line)(({
|
|
5255
5255
|
source
|
|
5256
5256
|
}) => [[source], ''])))));
|
|
5257
|
-
exports.heading = (0, combinator_1.block)((0, combinator_1.rewrite)(exports.segment, (0, combinator_1.state)(256 /* State.annotation */ | 128 /* State.reference */ | 64 /* State.index */ | 32 /* State.label */ | 16 /* State.link */ | 8 /* State.media */, (0, combinator_1.line)((0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.union)([(0, combinator_1.open)((0, source_1.str)(/^##+/), (0, visibility_1.visualize)((0, visibility_1.trimBlankStart)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline])))), true), (0, combinator_1.open)((0, source_1.str)('#'), (0, combinator_1.state)(
|
|
5257
|
+
exports.heading = (0, combinator_1.block)((0, combinator_1.rewrite)(exports.segment, (0, combinator_1.state)(256 /* State.annotation */ | 128 /* State.reference */ | 64 /* State.index */ | 32 /* State.label */ | 16 /* State.link */ | 8 /* State.media */, (0, combinator_1.line)((0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.union)([(0, combinator_1.open)((0, source_1.str)(/^##+/), (0, visibility_1.visualize)((0, visibility_1.trimBlankStart)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline])))), true), (0, combinator_1.open)((0, source_1.str)('#'), (0, combinator_1.state)(502 /* State.linkers */, (0, visibility_1.visualize)((0, visibility_1.trimBlankStart)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline]))))), true)]), ([h, ...ns]) => [h.length <= 6 ? (0, dom_1.html)(`h${h.length}`, (0, visibility_1.trimNodeEnd)((0, dom_1.defrag)(ns))) : (0, dom_1.html)(`h6`, {
|
|
5258
5258
|
class: 'invalid',
|
|
5259
5259
|
'data-invalid-syntax': 'heading',
|
|
5260
5260
|
'data-invalid-type': 'syntax',
|
|
@@ -5586,7 +5586,6 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
5586
5586
|
value: true
|
|
5587
5587
|
}));
|
|
5588
5588
|
exports.quote = exports.syntax = void 0;
|
|
5589
|
-
const parser_1 = __webpack_require__(6728);
|
|
5590
5589
|
const combinator_1 = __webpack_require__(2087);
|
|
5591
5590
|
const math_1 = __webpack_require__(8946);
|
|
5592
5591
|
const autolink_1 = __webpack_require__(6051);
|
|
@@ -5601,42 +5600,7 @@ exports.quote = (0, combinator_1.lazy)(() => (0, combinator_1.creation)(1, false
|
|
|
5601
5600
|
'data-invalid-type': 'syntax',
|
|
5602
5601
|
'data-invalid-message': `Missing the whitespace after "${ns[0].split(/[^>]/, 1)[0]}"`
|
|
5603
5602
|
}, (0, dom_1.defrag)(ns)), (0, dom_1.html)('br')]), false)));
|
|
5604
|
-
const qblock = (
|
|
5605
|
-
source,
|
|
5606
|
-
context
|
|
5607
|
-
}) => {
|
|
5608
|
-
source = source.replace(/\n$/, '');
|
|
5609
|
-
const lines = source.match(/^.*\n?/mg);
|
|
5610
|
-
const quotes = source.match(/^>+[^\S\n]/mg);
|
|
5611
|
-
const content = lines.reduce((acc, line, i) => acc + line.slice(quotes[i].length), '');
|
|
5612
|
-
const nodes = (0, parser_1.eval)(text({
|
|
5613
|
-
source: `\r${content}`,
|
|
5614
|
-
context
|
|
5615
|
-
}), []);
|
|
5616
|
-
nodes.unshift(quotes.shift());
|
|
5617
|
-
for (let i = 0; i < nodes.length; ++i) {
|
|
5618
|
-
const child = nodes[i];
|
|
5619
|
-
if (typeof child === 'string') continue;
|
|
5620
|
-
if ('wholeText' in child) {
|
|
5621
|
-
nodes[i] = child.data;
|
|
5622
|
-
continue;
|
|
5623
|
-
}
|
|
5624
|
-
if (child.tagName === 'BR') {
|
|
5625
|
-
nodes.splice(i + 1, 0, quotes.shift());
|
|
5626
|
-
++i;
|
|
5627
|
-
continue;
|
|
5628
|
-
}
|
|
5629
|
-
if (child.className === 'cite' || child.classList.contains('quote')) {
|
|
5630
|
-
context.resources && (context.resources.clock -= child.childNodes.length);
|
|
5631
|
-
nodes.splice(i, 1, ...child.childNodes);
|
|
5632
|
-
--i;
|
|
5633
|
-
continue;
|
|
5634
|
-
}
|
|
5635
|
-
}
|
|
5636
|
-
nodes.unshift('');
|
|
5637
|
-
return [nodes, ''];
|
|
5638
|
-
};
|
|
5639
|
-
const text = (0, combinator_1.some)((0, combinator_1.union)([math_1.math, autolink_1.autolink, source_1.linebreak, source_1.unescsource]));
|
|
5603
|
+
const qblock = (0, combinator_1.convert)(source => source.replace(/\n$/, '').replace(/(?<=^>+[^\S\n])/mg, '\r'), (0, combinator_1.some)((0, combinator_1.union)([math_1.math, autolink_1.autolink, source_1.linebreak, source_1.unescsource])));
|
|
5640
5604
|
|
|
5641
5605
|
/***/ }),
|
|
5642
5606
|
|
|
@@ -8564,7 +8528,7 @@ function level(h) {
|
|
|
8564
8528
|
function unlink(h) {
|
|
8565
8529
|
for (let es = h.getElementsByTagName('a'), len = es.length, i = 0; i < len; ++i) {
|
|
8566
8530
|
const el = es[i];
|
|
8567
|
-
el.replaceWith(
|
|
8531
|
+
el.firstChild ? el.replaceWith(el.firstChild) : el.remove();
|
|
8568
8532
|
}
|
|
8569
8533
|
return h.childNodes;
|
|
8570
8534
|
}
|
package/markdown.d.ts
CHANGED
|
@@ -631,12 +631,6 @@ export namespace MarkdownParser {
|
|
|
631
631
|
export namespace QuoteParser {
|
|
632
632
|
export interface BlockParser extends
|
|
633
633
|
Block<'reply/quote/block'>,
|
|
634
|
-
Parser<string | HTMLElement, Context, [
|
|
635
|
-
TextParser,
|
|
636
|
-
]> {
|
|
637
|
-
}
|
|
638
|
-
export interface TextParser extends
|
|
639
|
-
Block<'reply/quote/text'>,
|
|
640
634
|
Parser<string | HTMLElement, Context, [
|
|
641
635
|
InlineParser.MathParser,
|
|
642
636
|
InlineParser.AutolinkParser,
|
package/package.json
CHANGED
|
@@ -34,7 +34,7 @@ export class Delimiters {
|
|
|
34
34
|
private readonly delimiters: Delimiter[] = [];
|
|
35
35
|
private readonly order: number[] = [];
|
|
36
36
|
public push(
|
|
37
|
-
|
|
37
|
+
delims: readonly {
|
|
38
38
|
readonly signature: string;
|
|
39
39
|
readonly matcher: (source: string) => boolean | undefined;
|
|
40
40
|
readonly precedence?: number;
|
|
@@ -22,7 +22,7 @@ export function some<T>(parser: Parser<T>, end?: string | RegExp | number, delim
|
|
|
22
22
|
let nodes: T[] | undefined;
|
|
23
23
|
if (delims.length > 0) {
|
|
24
24
|
context.delimiters ??= new Delimiters();
|
|
25
|
-
context.delimiters.push(
|
|
25
|
+
context.delimiters.push(delims);
|
|
26
26
|
}
|
|
27
27
|
while (true) {
|
|
28
28
|
if (rest === '') break;
|
package/src/parser/api/bind.ts
CHANGED
|
@@ -26,9 +26,12 @@ export function bind(target: DocumentFragment | HTMLElement | ShadowRoot, settin
|
|
|
26
26
|
host: settings.host ?? new ReadonlyURL(location.pathname, location.origin),
|
|
27
27
|
memo: new Memo({ targets: State.backtrackers }),
|
|
28
28
|
};
|
|
29
|
+
assert(!context.offset);
|
|
30
|
+
assert(!context.precedence);
|
|
31
|
+
assert(!context.delimiters);
|
|
32
|
+
assert(!context.state);
|
|
29
33
|
if (context.id?.match(/[^0-9a-z/-]/i)) throw new Error('Invalid ID: ID must be alphanumeric');
|
|
30
34
|
if (context.host?.origin === 'null') throw new Error(`Invalid host: ${context.host.href}`);
|
|
31
|
-
assert(!settings.id);
|
|
32
35
|
type Block = readonly [segment: string, blocks: readonly HTMLElement[], url: string];
|
|
33
36
|
const blocks: Block[] = [];
|
|
34
37
|
const adds: [HTMLElement, Node | null][] = [];
|
package/src/parser/api/parse.ts
CHANGED
|
@@ -21,7 +21,6 @@ export function parse(source: string, opts: Options = {}, context?: MarkdownPars
|
|
|
21
21
|
if (!validate(source, MAX_SEGMENT_SIZE)) throw new Error(`Too large input over ${MAX_SEGMENT_SIZE.toLocaleString('en')} bytes`);
|
|
22
22
|
const url = headers(source).find(field => field.toLowerCase().startsWith('url:'))?.slice(4).trim() ?? '';
|
|
23
23
|
source = !context ? normalize(source) : source;
|
|
24
|
-
assert(!context?.delimiters);
|
|
25
24
|
context = {
|
|
26
25
|
host: opts.host ?? context?.host ?? new ReadonlyURL(location.pathname, location.origin),
|
|
27
26
|
url: url ? new ReadonlyURL(url as ':') : context?.url,
|
|
@@ -32,6 +31,10 @@ export function parse(source: string, opts: Options = {}, context?: MarkdownPars
|
|
|
32
31
|
},
|
|
33
32
|
memo: new Memo({ targets: State.backtrackers }),
|
|
34
33
|
};
|
|
34
|
+
assert(!context.offset);
|
|
35
|
+
assert(!context.precedence);
|
|
36
|
+
assert(!context.delimiters);
|
|
37
|
+
assert(!context.state);
|
|
35
38
|
if (context.id?.match(/[^0-9a-z/-]/i)) throw new Error('Invalid ID: ID must be alphanumeric');
|
|
36
39
|
if (context.host?.origin === 'null') throw new Error(`Invalid host: ${context.host.href}`);
|
|
37
40
|
const node = frag();
|
|
@@ -18,7 +18,7 @@ export const heading: HeadingParser = block(rewrite(segment,
|
|
|
18
18
|
visualize(trimBlankStart(some(union([indexer, inline])))), true),
|
|
19
19
|
open(
|
|
20
20
|
str('#'),
|
|
21
|
-
state(State.
|
|
21
|
+
state(State.linkers,
|
|
22
22
|
visualize(trimBlankStart(some(union([indexer, inline]))))), true),
|
|
23
23
|
]),
|
|
24
24
|
([h, ...ns]: [string, ...(HTMLElement | string)[]]) => [
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ReplyParser } from '../../block';
|
|
2
|
-
import {
|
|
3
|
-
import { union, some, creation, block, line, validate, rewrite, lazy, fmap } from '../../../combinator';
|
|
2
|
+
import { union, some, creation, block, line, validate, rewrite, convert, lazy, fmap } from '../../../combinator';
|
|
4
3
|
import { math } from '../../inline/math';
|
|
5
4
|
import { autolink } from '../../inline/autolink';
|
|
6
5
|
import { linebreak, unescsource, str, anyline } from '../../source';
|
|
@@ -33,47 +32,11 @@ export const quote: ReplyParser.QuoteParser = lazy(() => creation(1, false, bloc
|
|
|
33
32
|
]),
|
|
34
33
|
false)));
|
|
35
34
|
|
|
36
|
-
const qblock: ReplyParser.QuoteParser.BlockParser = (
|
|
37
|
-
source
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const nodes = eval(text({ source: `\r${content}`, context }), []);
|
|
45
|
-
nodes.unshift(quotes.shift()!);
|
|
46
|
-
for (let i = 0; i < nodes.length; ++i) {
|
|
47
|
-
const child = nodes[i] as string | Text | Element;
|
|
48
|
-
if (typeof child === 'string') continue;
|
|
49
|
-
if ('wholeText' in child) {
|
|
50
|
-
nodes[i] = child.data;
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
assert(child instanceof HTMLElement);
|
|
54
|
-
if (child.tagName === 'BR') {
|
|
55
|
-
assert(quotes.length > 0);
|
|
56
|
-
nodes.splice(i + 1, 0, quotes.shift()!);
|
|
57
|
-
++i;
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
if (child.className === 'cite' || child.classList.contains('quote')) {
|
|
61
|
-
context.resources && (context.resources.clock -= child.childNodes.length);
|
|
62
|
-
nodes.splice(i, 1, ...child.childNodes as NodeListOf<HTMLElement>);
|
|
63
|
-
--i;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
nodes.unshift('');
|
|
68
|
-
assert(nodes.length > 1);
|
|
69
|
-
assert(nodes.every(n => typeof n === 'string' || n instanceof HTMLElement));
|
|
70
|
-
assert(quotes.length === 0);
|
|
71
|
-
return [nodes, ''];
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const text: ReplyParser.QuoteParser.TextParser = some(union([
|
|
75
|
-
math, // quote補助関数が残した数式をパースする。他の構文で数式を残す場合はソーステキストを直接使用する。
|
|
76
|
-
autolink,
|
|
77
|
-
linebreak,
|
|
78
|
-
unescsource,
|
|
79
|
-
]));
|
|
35
|
+
const qblock: ReplyParser.QuoteParser.BlockParser = convert(
|
|
36
|
+
source => source.replace(/\n$/, '').replace(/(?<=^>+[^\S\n])/mg, '\r'),
|
|
37
|
+
some(union([
|
|
38
|
+
math, // quote補助関数が残した数式をパースする。他の構文で数式を残す場合はソーステキストを直接使用する。
|
|
39
|
+
autolink,
|
|
40
|
+
linebreak,
|
|
41
|
+
unescsource,
|
|
42
|
+
])));
|
package/src/util/toc.ts
CHANGED
|
@@ -61,7 +61,10 @@ function level(h: HTMLHeadingElement): number {
|
|
|
61
61
|
function unlink(h: HTMLHeadingElement): Iterable<Node> {
|
|
62
62
|
for (let es = h.getElementsByTagName('a'), len = es.length, i = 0; i < len; ++i) {
|
|
63
63
|
const el = es[i];
|
|
64
|
-
|
|
64
|
+
assert(el.childNodes.length <= 1);
|
|
65
|
+
el.firstChild
|
|
66
|
+
? el.replaceWith(el.firstChild)
|
|
67
|
+
: el.remove();
|
|
65
68
|
}
|
|
66
69
|
return h.childNodes;
|
|
67
70
|
}
|