securemark 0.251.0 → 0.252.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 +4 -0
- package/dist/index.js +23 -47
- package/markdown.d.ts +8 -18
- package/package.json +1 -1
- package/src/combinator/control/manipulation/indent.ts +8 -8
- package/src/parser/api/parse.test.ts +2 -2
- package/src/parser/block/extension/figure.ts +0 -2
- package/src/parser/block/extension/message.ts +0 -2
- package/src/parser/block/paragraph.test.ts +3 -3
- package/src/parser/block.ts +0 -3
- package/src/parser/inline/extension/index.ts +4 -5
- package/src/parser/inline/reference.test.ts +3 -3
- package/src/parser/inline/reference.ts +3 -3
- package/src/parser/source/str.ts +2 -2
- package/src/parser/util.ts +10 -6
- package/src/parser/block/indentblock.test.ts +0 -37
- package/src/parser/block/indentblock.ts +0 -13
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! securemark v0.
|
|
1
|
+
/*! securemark v0.252.0 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("DOMPurify"), require("Prism"));
|
|
@@ -2339,16 +2339,16 @@ const memoize_1 = __webpack_require__(1808);
|
|
|
2339
2339
|
|
|
2340
2340
|
function indent(opener, parser, separation = false) {
|
|
2341
2341
|
if (typeof opener === 'function') return indent(/^([ \t])\1*/, opener, parser);
|
|
2342
|
-
return (0, bind_1.bind)((0, block_1.block)((0, match_1.match)(opener, (0, memoize_1.memoize)(([indent]) => (0, some_1.some)((0, line_1.line)((0, surround_1.open)(indent, source => [[
|
|
2343
|
-
const result = parser(
|
|
2342
|
+
return (0, bind_1.bind)((0, block_1.block)((0, match_1.match)(opener, (0, memoize_1.memoize)(([indent]) => (0, some_1.some)((0, line_1.line)((0, surround_1.open)(indent, source => [[source], '']))), ([indent]) => indent.length * 2 + +(indent[0] === ' '), [])), separation), (lines, rest, context) => {
|
|
2343
|
+
const result = parser(trimBlockEnd(lines.join('')), context);
|
|
2344
2344
|
return result && (0, parser_1.exec)(result) === '' ? [(0, parser_1.eval)(result), rest] : global_1.undefined;
|
|
2345
2345
|
});
|
|
2346
2346
|
}
|
|
2347
2347
|
|
|
2348
2348
|
exports.indent = indent;
|
|
2349
2349
|
|
|
2350
|
-
function
|
|
2351
|
-
return
|
|
2350
|
+
function trimBlockEnd(block) {
|
|
2351
|
+
return block === '' || block[block.length - 1] !== '\n' ? block : block.slice(0, -1);
|
|
2352
2352
|
}
|
|
2353
2353
|
|
|
2354
2354
|
/***/ }),
|
|
@@ -3632,8 +3632,6 @@ const dlist_1 = __webpack_require__(9373);
|
|
|
3632
3632
|
|
|
3633
3633
|
const table_1 = __webpack_require__(8717);
|
|
3634
3634
|
|
|
3635
|
-
const indentblock_1 = __webpack_require__(3565);
|
|
3636
|
-
|
|
3637
3635
|
const codeblock_1 = __webpack_require__(1849);
|
|
3638
3636
|
|
|
3639
3637
|
const mathblock_1 = __webpack_require__(3754);
|
|
@@ -3657,7 +3655,7 @@ exports.block = (0, combinator_1.creator)(error((0, combinator_1.reset)({
|
|
|
3657
3655
|
budget: 100 * 1000,
|
|
3658
3656
|
recursion: 200
|
|
3659
3657
|
}
|
|
3660
|
-
}, (0, combinator_1.union)([source_1.emptyline, horizontalrule_1.horizontalrule, heading_1.heading, ulist_1.ulist, olist_1.olist, ilist_1.ilist, dlist_1.dlist, table_1.table,
|
|
3658
|
+
}, (0, combinator_1.union)([source_1.emptyline, horizontalrule_1.horizontalrule, heading_1.heading, ulist_1.ulist, olist_1.olist, ilist_1.ilist, dlist_1.dlist, table_1.table, codeblock_1.codeblock, mathblock_1.mathblock, extension_1.extension, sidefence_1.sidefence, blockquote_1.blockquote, reply_1.reply, paragraph_1.paragraph]))));
|
|
3661
3659
|
|
|
3662
3660
|
function error(parser) {
|
|
3663
3661
|
return (0, combinator_1.recover)((0, combinator_1.fallback)((0, combinator_1.open)('\x07', source => {
|
|
@@ -4102,8 +4100,6 @@ const olist_1 = __webpack_require__(7471);
|
|
|
4102
4100
|
|
|
4103
4101
|
const table_1 = __webpack_require__(8717);
|
|
4104
4102
|
|
|
4105
|
-
const indentblock_1 = __webpack_require__(3565);
|
|
4106
|
-
|
|
4107
4103
|
const codeblock_1 = __webpack_require__(1849);
|
|
4108
4104
|
|
|
4109
4105
|
const mathblock_1 = __webpack_require__(3754);
|
|
@@ -4130,7 +4126,7 @@ const array_1 = __webpack_require__(8112);
|
|
|
4130
4126
|
|
|
4131
4127
|
exports.segment = (0, combinator_1.block)((0, combinator_1.match)(/^(~{3,})(?:figure[^\S\n])?(?=\[?\$)/, (0, memoize_1.memoize)(([, fence], closer = new RegExp(String.raw`^${fence}[^\S\n]*(?:$|\n)`)) => (0, combinator_1.close)((0, combinator_1.sequence)([source_1.contentline, (0, combinator_1.inits)([// All parsers which can include closing terms.
|
|
4132
4128
|
(0, combinator_1.union)([codeblock_1.segment_, mathblock_1.segment_, table_2.segment_, blockquote_1.segment, placeholder_1.segment_, (0, combinator_1.some)(source_1.contentline, closer)]), source_1.emptyline, (0, combinator_1.union)([source_1.emptyline, (0, combinator_1.some)(source_1.contentline, closer)])])]), closer), ([, fence]) => fence.length, [])));
|
|
4133
|
-
exports.figure = (0, combinator_1.block)((0, combinator_1.fallback)((0, combinator_1.rewrite)(exports.segment, (0, combinator_1.fmap)((0, combinator_1.convert)(source => source.slice(source.match(/^~+(?:\w+\s+)?/)[0].length, source.trimEnd().lastIndexOf('\n')), (0, combinator_1.sequence)([(0, combinator_1.line)((0, combinator_1.sequence)([label_1.label, (0, source_1.str)(/^(?=\s).*\n/)])), (0, combinator_1.inits)([(0, combinator_1.block)((0, combinator_1.union)([ulist_1.ulist, olist_1.olist, table_1.table,
|
|
4129
|
+
exports.figure = (0, combinator_1.block)((0, combinator_1.fallback)((0, combinator_1.rewrite)(exports.segment, (0, combinator_1.fmap)((0, combinator_1.convert)(source => source.slice(source.match(/^~+(?:\w+\s+)?/)[0].length, source.trimEnd().lastIndexOf('\n')), (0, combinator_1.sequence)([(0, combinator_1.line)((0, combinator_1.sequence)([label_1.label, (0, source_1.str)(/^(?=\s).*\n/)])), (0, combinator_1.inits)([(0, combinator_1.block)((0, combinator_1.union)([ulist_1.ulist, olist_1.olist, table_1.table, codeblock_1.codeblock, mathblock_1.mathblock, example_1.example, table_2.table, blockquote_1.blockquote, placeholder_1.placeholder, (0, combinator_1.line)(inline_1.media), (0, combinator_1.line)(inline_1.shortmedia)])), source_1.emptyline, (0, combinator_1.block)((0, locale_1.localize)((0, combinator_1.context)({
|
|
4134
4130
|
syntax: {
|
|
4135
4131
|
inline: {
|
|
4136
4132
|
media: false
|
|
@@ -4265,8 +4261,6 @@ const ilist_1 = __webpack_require__(238);
|
|
|
4265
4261
|
|
|
4266
4262
|
const table_1 = __webpack_require__(8717);
|
|
4267
4263
|
|
|
4268
|
-
const indentblock_1 = __webpack_require__(3565);
|
|
4269
|
-
|
|
4270
4264
|
const codeblock_1 = __webpack_require__(1849);
|
|
4271
4265
|
|
|
4272
4266
|
const mathblock_1 = __webpack_require__(3754);
|
|
@@ -4327,7 +4321,7 @@ function title(type) {
|
|
|
4327
4321
|
} // Must not have indexed blocks.
|
|
4328
4322
|
|
|
4329
4323
|
|
|
4330
|
-
const content = (0, combinator_1.union)([source_1.emptyline, ulist_1.ulist, olist_1.olist, ilist_1.ilist, table_1.table,
|
|
4324
|
+
const content = (0, combinator_1.union)([source_1.emptyline, ulist_1.ulist, olist_1.olist, ilist_1.ilist, table_1.table, codeblock_1.codeblock, mathblock_1.mathblock, sidefence_1.sidefence, blockquote_1.blockquote, paragraph_1.paragraph]);
|
|
4331
4325
|
|
|
4332
4326
|
/***/ }),
|
|
4333
4327
|
|
|
@@ -4743,29 +4737,6 @@ exports.ilist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combin
|
|
|
4743
4737
|
|
|
4744
4738
|
/***/ }),
|
|
4745
4739
|
|
|
4746
|
-
/***/ 3565:
|
|
4747
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
4748
|
-
|
|
4749
|
-
"use strict";
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
Object.defineProperty(exports, "__esModule", ({
|
|
4753
|
-
value: true
|
|
4754
|
-
}));
|
|
4755
|
-
exports.indentblock = void 0;
|
|
4756
|
-
|
|
4757
|
-
const combinator_1 = __webpack_require__(2087);
|
|
4758
|
-
|
|
4759
|
-
const codeblock_1 = __webpack_require__(1849); // 空行を含むインデントブロックはインデントの違いによるセグメント分割の境界が視認不能となるため採用しない
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
exports.indentblock = (0, combinator_1.block)((0, combinator_1.indent)(/^( {4}|\t)\1*/, (0, combinator_1.convert)(source => {
|
|
4763
|
-
const fence = (source.match(/^`{3,}(?=[^\S\n]*$)/mg) ?? []).reduce((max, fence) => fence > max ? fence : max, '``') + '`';
|
|
4764
|
-
return `${fence}\n${source}\n${fence}`;
|
|
4765
|
-
}, (0, combinator_1.union)([codeblock_1.codeblock])), true));
|
|
4766
|
-
|
|
4767
|
-
/***/ }),
|
|
4768
|
-
|
|
4769
4740
|
/***/ 3754:
|
|
4770
4741
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
4771
4742
|
|
|
@@ -6015,7 +5986,7 @@ exports.index = (0, combinator_1.lazy)(() => (0, combinator_1.creator)((0, combi
|
|
|
6015
5986
|
autolink: false
|
|
6016
5987
|
}
|
|
6017
5988
|
}
|
|
6018
|
-
}, (0, combinator_1.open)((0, source_1.stropt)(
|
|
5989
|
+
}, (0, combinator_1.open)((0, source_1.stropt)(/^\|?/), (0, util_1.trimBlankEnd)((0, combinator_1.some)((0, combinator_1.union)([signature, inline_1.inline]), ']', /^\\?\n/)), true)))), ']'), ns => [(0, dom_1.html)('a', (0, dom_1.defrag)(ns))])), ([el]) => [(0, dom_1.define)(el, {
|
|
6019
5990
|
id: el.id ? null : global_1.undefined,
|
|
6020
5991
|
class: 'index',
|
|
6021
5992
|
href: el.id ? `#${el.id}` : global_1.undefined
|
|
@@ -6719,7 +6690,7 @@ exports.reference = (0, combinator_1.lazy)(() => (0, combinator_1.creator)((0, c
|
|
|
6719
6690
|
}
|
|
6720
6691
|
},
|
|
6721
6692
|
delimiters: global_1.undefined
|
|
6722
|
-
}, (0, combinator_1.subsequence)([abbr, (0, combinator_1.
|
|
6693
|
+
}, (0, combinator_1.subsequence)([abbr, (0, combinator_1.open)((0, source_1.stropt)(/^(?=\^)/), (0, combinator_1.some)(inline_1.inline, ']', /^\\?\n/)), (0, util_1.trimBlank)((0, combinator_1.some)(inline_1.inline, ']', /^\\?\n/))]))), ']]'), ns => [(0, dom_1.html)('sup', attributes(ns), (0, dom_1.defrag)(ns))]))));
|
|
6723
6694
|
const abbr = (0, combinator_1.creator)((0, combinator_1.bind)((0, combinator_1.surround)('^', (0, combinator_1.union)([(0, source_1.str)(/^(?![0-9]+\s?[|\]])[0-9A-Za-z]+(?:(?:-|(?=\W)(?!'\d)'?(?!\.\d)\.?(?!,\S),? ?)[0-9A-Za-z]+)*(?:-|'?\.?,? ?)?/)]), /^\|?(?=]])|^\|[^\S\n]*/), ([source], rest) => [[(0, dom_1.html)('abbr', source)], rest.replace(util_1.regBlankStart, '')]));
|
|
6724
6695
|
|
|
6725
6696
|
function attributes(ns) {
|
|
@@ -7618,11 +7589,11 @@ exports.str = str;
|
|
|
7618
7589
|
function stropt(pattern) {
|
|
7619
7590
|
return typeof pattern === 'string' ? (0, combinator_1.creator)(source => {
|
|
7620
7591
|
if (source === '') return;
|
|
7621
|
-
return source.slice(0, pattern.length) === pattern ? [[pattern], source.slice(pattern.length)] :
|
|
7592
|
+
return source.slice(0, pattern.length) === pattern ? [[pattern], source.slice(pattern.length)] : global_1.undefined;
|
|
7622
7593
|
}) : (0, combinator_1.creator)(source => {
|
|
7623
7594
|
if (source === '') return;
|
|
7624
7595
|
const m = source.match(pattern);
|
|
7625
|
-
return m ? [[m[0]], source.slice(m[0].length)] :
|
|
7596
|
+
return m ? [[m[0]], source.slice(m[0].length)] : global_1.undefined;
|
|
7626
7597
|
});
|
|
7627
7598
|
}
|
|
7628
7599
|
|
|
@@ -7779,7 +7750,7 @@ exports.unescsource = (0, combinator_1.creator)(source => {
|
|
|
7779
7750
|
Object.defineProperty(exports, "__esModule", ({
|
|
7780
7751
|
value: true
|
|
7781
7752
|
}));
|
|
7782
|
-
exports.stringify = exports.
|
|
7753
|
+
exports.stringify = exports.trimBlankEnd = exports.trimBlankStart = exports.trimBlank = exports.isStartTightNodes = exports.startTight = exports.startLoose = exports.visualize = exports.blankWith = exports.regBlankStart = void 0;
|
|
7783
7754
|
|
|
7784
7755
|
const global_1 = __webpack_require__(4128);
|
|
7785
7756
|
|
|
@@ -7926,14 +7897,22 @@ function isVisible(node, strpos) {
|
|
|
7926
7897
|
}
|
|
7927
7898
|
|
|
7928
7899
|
function trimBlank(parser) {
|
|
7929
|
-
return (
|
|
7900
|
+
return trimBlankStart(trimBlankEnd(parser));
|
|
7930
7901
|
}
|
|
7931
7902
|
|
|
7932
7903
|
exports.trimBlank = trimBlank;
|
|
7933
7904
|
|
|
7934
7905
|
function trimBlankStart(parser) {
|
|
7935
7906
|
return (0, combinator_1.convert)((0, memoize_1.reduce)(source => source.replace(exports.regBlankStart, '')), parser);
|
|
7936
|
-
}
|
|
7907
|
+
}
|
|
7908
|
+
|
|
7909
|
+
exports.trimBlankStart = trimBlankStart;
|
|
7910
|
+
|
|
7911
|
+
function trimBlankEnd(parser) {
|
|
7912
|
+
return (0, combinator_1.fmap)(parser, trimNodeEnd);
|
|
7913
|
+
}
|
|
7914
|
+
|
|
7915
|
+
exports.trimBlankEnd = trimBlankEnd; //export function trimNode(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
|
|
7937
7916
|
// return trimNodeStart(trimNodeEnd(nodes));
|
|
7938
7917
|
//}
|
|
7939
7918
|
//function trimNodeStart(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
|
|
@@ -7951,7 +7930,6 @@ function trimBlankStart(parser) {
|
|
|
7951
7930
|
// return nodes;
|
|
7952
7931
|
//}
|
|
7953
7932
|
|
|
7954
|
-
|
|
7955
7933
|
function trimNodeEnd(nodes) {
|
|
7956
7934
|
const skip = nodes.length > 0 && typeof nodes[nodes.length - 1] === 'object' && nodes[nodes.length - 1]['className'] === 'indexer' ? [nodes.pop()] : [];
|
|
7957
7935
|
|
|
@@ -7971,8 +7949,6 @@ function trimNodeEnd(nodes) {
|
|
|
7971
7949
|
return (0, array_1.push)(nodes, skip);
|
|
7972
7950
|
}
|
|
7973
7951
|
|
|
7974
|
-
exports.trimNodeEnd = trimNodeEnd;
|
|
7975
|
-
|
|
7976
7952
|
function stringify(nodes) {
|
|
7977
7953
|
let acc = '';
|
|
7978
7954
|
|
package/markdown.d.ts
CHANGED
|
@@ -77,7 +77,6 @@ export namespace MarkdownParser {
|
|
|
77
77
|
BlockParser.IListParser,
|
|
78
78
|
BlockParser.DListParser,
|
|
79
79
|
BlockParser.TableParser,
|
|
80
|
-
BlockParser.IndentBlockParser,
|
|
81
80
|
BlockParser.CodeBlockParser,
|
|
82
81
|
BlockParser.MathBlockParser,
|
|
83
82
|
BlockParser.ExtensionParser,
|
|
@@ -283,13 +282,6 @@ export namespace MarkdownParser {
|
|
|
283
282
|
}
|
|
284
283
|
}
|
|
285
284
|
}
|
|
286
|
-
export interface IndentBlockParser extends
|
|
287
|
-
// abc
|
|
288
|
-
Block<'indentblock'>,
|
|
289
|
-
Parser<HTMLPreElement, Context, [
|
|
290
|
-
CodeBlockParser,
|
|
291
|
-
]> {
|
|
292
|
-
}
|
|
293
285
|
export interface CodeBlockParser extends
|
|
294
286
|
// ```js index.js
|
|
295
287
|
// abc
|
|
@@ -358,7 +350,6 @@ export namespace MarkdownParser {
|
|
|
358
350
|
UListParser,
|
|
359
351
|
OListParser,
|
|
360
352
|
BlockParser.TableParser,
|
|
361
|
-
IndentBlockParser,
|
|
362
353
|
CodeBlockParser,
|
|
363
354
|
MathBlockParser,
|
|
364
355
|
ExampleParser,
|
|
@@ -503,7 +494,6 @@ export namespace MarkdownParser {
|
|
|
503
494
|
BlockParser.OListParser,
|
|
504
495
|
BlockParser.IListParser,
|
|
505
496
|
BlockParser.TableParser,
|
|
506
|
-
BlockParser.IndentBlockParser,
|
|
507
497
|
BlockParser.CodeBlockParser,
|
|
508
498
|
BlockParser.MathBlockParser,
|
|
509
499
|
BlockParser.SidefenceParser,
|
|
@@ -668,13 +658,6 @@ export namespace MarkdownParser {
|
|
|
668
658
|
}
|
|
669
659
|
export namespace InlineParser {
|
|
670
660
|
interface Inline<T extends string> extends Markdown<`inline/${T}`> { }
|
|
671
|
-
export interface AnnotationParser extends
|
|
672
|
-
// ((abc))
|
|
673
|
-
Inline<'annotation'>,
|
|
674
|
-
Parser<HTMLElement, Context, [
|
|
675
|
-
InlineParser,
|
|
676
|
-
]> {
|
|
677
|
-
}
|
|
678
661
|
export interface EscapeParser extends
|
|
679
662
|
// ****
|
|
680
663
|
// +++
|
|
@@ -685,6 +668,13 @@ export namespace MarkdownParser {
|
|
|
685
668
|
SourceParser.StrParser,
|
|
686
669
|
]> {
|
|
687
670
|
}
|
|
671
|
+
export interface AnnotationParser extends
|
|
672
|
+
// ((abc))
|
|
673
|
+
Inline<'annotation'>,
|
|
674
|
+
Parser<HTMLElement, Context, [
|
|
675
|
+
InlineParser,
|
|
676
|
+
]> {
|
|
677
|
+
}
|
|
688
678
|
export interface ReferenceParser extends
|
|
689
679
|
// [[abc]]
|
|
690
680
|
// [[^abbr]]
|
|
@@ -692,7 +682,7 @@ export namespace MarkdownParser {
|
|
|
692
682
|
Inline<'reference'>,
|
|
693
683
|
Parser<HTMLElement, Context, [
|
|
694
684
|
ReferenceParser.AbbrParser,
|
|
695
|
-
|
|
685
|
+
InlineParser,
|
|
696
686
|
InlineParser,
|
|
697
687
|
]> {
|
|
698
688
|
}
|
package/package.json
CHANGED
|
@@ -17,20 +17,20 @@ export function indent<T>(opener: RegExp | Parser<T>, parser?: Parser<T> | boole
|
|
|
17
17
|
opener,
|
|
18
18
|
memoize(
|
|
19
19
|
([indent]) =>
|
|
20
|
-
some(line(open(indent, source => [[
|
|
20
|
+
some(line(open(indent, source => [[source], '']))),
|
|
21
21
|
([indent]) => indent.length * 2 + +(indent[0] === ' '), [])), separation),
|
|
22
|
-
(
|
|
22
|
+
(lines, rest, context) => {
|
|
23
23
|
assert(parser = parser as Parser<T>);
|
|
24
|
-
const result = parser(
|
|
24
|
+
const result = parser(trimBlockEnd(lines.join('')), context);
|
|
25
25
|
return result && exec(result) === ''
|
|
26
26
|
? [eval(result), rest]
|
|
27
27
|
: undefined;
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function
|
|
32
|
-
return
|
|
33
|
-
||
|
|
34
|
-
?
|
|
35
|
-
:
|
|
31
|
+
function trimBlockEnd(block: string): string {
|
|
32
|
+
return block === ''
|
|
33
|
+
|| block[block.length - 1] !== '\n'
|
|
34
|
+
? block
|
|
35
|
+
: block.slice(0, -1);
|
|
36
36
|
}
|
|
@@ -82,8 +82,8 @@ describe('Unit: parser/api/parse', () => {
|
|
|
82
82
|
|
|
83
83
|
it('indent', () => {
|
|
84
84
|
assert.deepStrictEqual(
|
|
85
|
-
[...parse('
|
|
86
|
-
['<p
|
|
85
|
+
[...parse('\ta').children].map(el => el.outerHTML),
|
|
86
|
+
['<p>\ta</p>']);
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
it('url', () => {
|
|
@@ -6,7 +6,6 @@ import { label, segment as seg_label } from '../../inline/extension/label';
|
|
|
6
6
|
import { ulist } from '../ulist';
|
|
7
7
|
import { olist } from '../olist';
|
|
8
8
|
import { table as styled_table } from '../table';
|
|
9
|
-
import { indentblock } from '../indentblock';
|
|
10
9
|
import { codeblock, segment_ as seg_code } from '../codeblock';
|
|
11
10
|
import { mathblock, segment_ as seg_math } from '../mathblock';
|
|
12
11
|
import { example } from './example';
|
|
@@ -57,7 +56,6 @@ export const figure: FigureParser = block(fallback(rewrite(segment, fmap(
|
|
|
57
56
|
ulist,
|
|
58
57
|
olist,
|
|
59
58
|
styled_table,
|
|
60
|
-
indentblock,
|
|
61
59
|
codeblock,
|
|
62
60
|
mathblock,
|
|
63
61
|
example,
|
|
@@ -7,7 +7,6 @@ import { ulist } from '../ulist';
|
|
|
7
7
|
import { olist } from '../olist';
|
|
8
8
|
import { ilist } from '../ilist';
|
|
9
9
|
import { table } from '../table';
|
|
10
|
-
import { indentblock } from '../indentblock';
|
|
11
10
|
import { codeblock } from '../codeblock';
|
|
12
11
|
import { mathblock } from '../mathblock';
|
|
13
12
|
import { sidefence } from '../sidefence';
|
|
@@ -71,7 +70,6 @@ const content: MessageParser.ContentParser = union([
|
|
|
71
70
|
olist,
|
|
72
71
|
ilist,
|
|
73
72
|
table,
|
|
74
|
-
indentblock,
|
|
75
73
|
codeblock,
|
|
76
74
|
mathblock,
|
|
77
75
|
sidefence,
|
|
@@ -33,7 +33,7 @@ describe('Unit: parser/block/paragraph', () => {
|
|
|
33
33
|
assert.deepStrictEqual(inspect(parser('***a*b\n<wbr>**\nc')), [['<p>**<em>a</em>b<br><wbr>**<br>c</p>'], '']);
|
|
34
34
|
assert.deepStrictEqual(inspect(parser('***a**b\n<wbr>*\nc')), [['<p>*<strong>a</strong>b<br><wbr>*<br>c</p>'], '']);
|
|
35
35
|
assert.deepStrictEqual(inspect(parser('==a\n<wbr>==\nb')), [['<p>==a<br><wbr>==<br>b</p>'], '']);
|
|
36
|
-
assert.deepStrictEqual(inspect(parser('
|
|
36
|
+
assert.deepStrictEqual(inspect(parser('\ta')), [['<p>\ta</p>'], '']);
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
it('anchor', () => {
|
|
@@ -50,8 +50,8 @@ describe('Unit: parser/block/paragraph', () => {
|
|
|
50
50
|
assert.deepStrictEqual(inspect(parser('a\n>>1')), [['<p>a<br><a href="?at=1" class="anchor">>>1</a></p>'], '']);
|
|
51
51
|
assert.deepStrictEqual(inspect(parser('a\n>>1\nb')), [['<p>a<br><a href="?at=1" class="anchor">>>1</a><br>b</p>'], '']);
|
|
52
52
|
assert.deepStrictEqual(inspect(parser('a\n>> b\nc')), [['<p>a<br>>> b<br>c</p>'], '']);
|
|
53
|
-
assert.deepStrictEqual(inspect(parser('
|
|
54
|
-
assert.deepStrictEqual(inspect(parser('
|
|
53
|
+
assert.deepStrictEqual(inspect(parser('\t>>1')), [['<p>\t<a href="?at=1" class="anchor">>>1</a></p>'], '']);
|
|
54
|
+
assert.deepStrictEqual(inspect(parser('\t>>>1')), [['<p>\t><a href="?at=1" class="anchor">>>1</a></p>'], '']);
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
it('comment', () => {
|
package/src/parser/block.ts
CHANGED
|
@@ -9,7 +9,6 @@ import { olist } from './block/olist';
|
|
|
9
9
|
import { ilist } from './block/ilist';
|
|
10
10
|
import { dlist } from './block/dlist';
|
|
11
11
|
import { table } from './block/table';
|
|
12
|
-
import { indentblock } from './block/indentblock';
|
|
13
12
|
import { codeblock } from './block/codeblock';
|
|
14
13
|
import { mathblock } from './block/mathblock';
|
|
15
14
|
import { extension } from './block/extension';
|
|
@@ -28,7 +27,6 @@ export import OListParser = BlockParser.OListParser;
|
|
|
28
27
|
export import IListParser = BlockParser.IListParser;
|
|
29
28
|
export import DListParser = BlockParser.DListParser;
|
|
30
29
|
export import TableParser = BlockParser.TableParser;
|
|
31
|
-
export import IndentBlockParser = BlockParser.IndentBlockParser;
|
|
32
30
|
export import CodeBlockParser = BlockParser.CodeBlockParser;
|
|
33
31
|
export import MathBlockParser = BlockParser.MathBlockParser;
|
|
34
32
|
export import ExtensionParser = BlockParser.ExtensionParser;
|
|
@@ -48,7 +46,6 @@ export const block: BlockParser = creator(error(
|
|
|
48
46
|
ilist,
|
|
49
47
|
dlist,
|
|
50
48
|
table,
|
|
51
|
-
indentblock,
|
|
52
49
|
codeblock,
|
|
53
50
|
mathblock,
|
|
54
51
|
extension,
|
|
@@ -4,7 +4,7 @@ import { union, some, validate, guard, context, creator, surround, open, lazy, f
|
|
|
4
4
|
import { inline } from '../../inline';
|
|
5
5
|
import { indexee, identity } from './indexee';
|
|
6
6
|
import { txt, str, stropt } from '../../source';
|
|
7
|
-
import { startTight,
|
|
7
|
+
import { startTight, trimBlankEnd } from '../../util';
|
|
8
8
|
import { html, define, defrag } from 'typed-dom/dom';
|
|
9
9
|
|
|
10
10
|
import IndexParser = ExtensionParser.IndexParser;
|
|
@@ -22,13 +22,12 @@ export const index: IndexParser = lazy(() => creator(validate('[#', ']', '\n', f
|
|
|
22
22
|
media: false,
|
|
23
23
|
autolink: false,
|
|
24
24
|
}}},
|
|
25
|
-
open(stropt(
|
|
26
|
-
some(union([
|
|
25
|
+
open(stropt(/^\|?/), trimBlankEnd(some(union([
|
|
27
26
|
signature,
|
|
28
27
|
inline,
|
|
29
|
-
]), ']', /^\\?\n/), true)))),
|
|
28
|
+
]), ']', /^\\?\n/)), true)))),
|
|
30
29
|
']'),
|
|
31
|
-
ns => [html('a',
|
|
30
|
+
ns => [html('a', defrag(ns))])),
|
|
32
31
|
([el]: [HTMLAnchorElement]) => [
|
|
33
32
|
define(el,
|
|
34
33
|
{
|
|
@@ -58,7 +58,7 @@ describe('Unit: parser/inline/reference', () => {
|
|
|
58
58
|
assert.deepStrictEqual(inspect(parser('[[^a,]]')), [['<sup class="reference" data-abbr="a,"></sup>'], '']);
|
|
59
59
|
assert.deepStrictEqual(inspect(parser('[[^a, ]]')), [['<sup class="reference" data-abbr="a,"></sup>'], '']);
|
|
60
60
|
assert.deepStrictEqual(inspect(parser('[[^a ]]')), [['<sup class="reference" data-abbr="a"></sup>'], '']);
|
|
61
|
-
assert.deepStrictEqual(inspect(parser('[[^a ]]')), [['<sup class="invalid">^a</sup>'], '']);
|
|
61
|
+
assert.deepStrictEqual(inspect(parser('[[^a ]]')), [['<sup class="invalid">^a </sup>'], '']);
|
|
62
62
|
assert.deepStrictEqual(inspect(parser('[[^a b]]')), [['<sup class="reference" data-abbr="a b"></sup>'], '']);
|
|
63
63
|
assert.deepStrictEqual(inspect(parser('[[^a b]]')), [['<sup class="invalid">^a b</sup>'], '']);
|
|
64
64
|
assert.deepStrictEqual(inspect(parser('[[^a|]]')), [['<sup class="reference" data-abbr="a"></sup>'], '']);
|
|
@@ -76,7 +76,7 @@ describe('Unit: parser/inline/reference', () => {
|
|
|
76
76
|
assert.deepStrictEqual(inspect(parser('[[^a| ]]')), [['<sup class="reference" data-abbr="a"></sup>'], '']);
|
|
77
77
|
assert.deepStrictEqual(inspect(parser('[[^1]]')), [['<sup class="invalid">^1</sup>'], '']);
|
|
78
78
|
assert.deepStrictEqual(inspect(parser('[[^1a]]')), [['<sup class="reference" data-abbr="1a"></sup>'], '']);
|
|
79
|
-
assert.deepStrictEqual(inspect(parser('[[^1 ]]')), [['<sup class="invalid">^1</sup>'], '']);
|
|
79
|
+
assert.deepStrictEqual(inspect(parser('[[^1 ]]')), [['<sup class="invalid">^1 </sup>'], '']);
|
|
80
80
|
assert.deepStrictEqual(inspect(parser('[[^1 a]]')), [['<sup class="reference" data-abbr="1 a"></sup>'], '']);
|
|
81
81
|
assert.deepStrictEqual(inspect(parser('[[^1|]]')), [['<sup class="invalid">^1|</sup>'], '']);
|
|
82
82
|
assert.deepStrictEqual(inspect(parser('[[^1 |]]')), [['<sup class="invalid">^1 |</sup>'], '']);
|
|
@@ -91,7 +91,7 @@ describe('Unit: parser/inline/reference', () => {
|
|
|
91
91
|
assert.deepStrictEqual(inspect(parser('[[^ a]]')), [['<sup class="invalid">^ a</sup>'], '']);
|
|
92
92
|
assert.deepStrictEqual(inspect(parser('[[^ |]]')), [['<sup class="invalid">^ |</sup>'], '']);
|
|
93
93
|
assert.deepStrictEqual(inspect(parser('[[^ |b]]')), [['<sup class="invalid">^ |b</sup>'], '']);
|
|
94
|
-
assert.deepStrictEqual(inspect(parser('[[^ | ]]')), [['<sup class="invalid">^
|
|
94
|
+
assert.deepStrictEqual(inspect(parser('[[^ | ]]')), [['<sup class="invalid">^ | </sup>'], '']);
|
|
95
95
|
assert.deepStrictEqual(inspect(parser('[[^ | b]]')), [['<sup class="invalid">^ | b</sup>'], '']);
|
|
96
96
|
});
|
|
97
97
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { ReferenceParser } from '../inline';
|
|
3
|
-
import { union, subsequence, some, validate,
|
|
3
|
+
import { union, subsequence, some, validate, guard, context, creator, surround, open, lazy, fmap, bind } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
|
-
import { str } from '../source';
|
|
5
|
+
import { str, stropt } from '../source';
|
|
6
6
|
import { regBlankStart, trimBlank, stringify } from '../util';
|
|
7
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
8
8
|
|
|
@@ -21,7 +21,7 @@ export const reference: ReferenceParser = lazy(() => creator(validate('[[', ']]'
|
|
|
21
21
|
}}, delimiters: undefined },
|
|
22
22
|
subsequence([
|
|
23
23
|
abbr,
|
|
24
|
-
|
|
24
|
+
open(stropt(/^(?=\^)/), some(inline, ']', /^\\?\n/)),
|
|
25
25
|
trimBlank(some(inline, ']', /^\\?\n/)),
|
|
26
26
|
]))),
|
|
27
27
|
']]'),
|
package/src/parser/source/str.ts
CHANGED
|
@@ -30,13 +30,13 @@ export function stropt(pattern: string | RegExp): Parser<string, Context<StrPars
|
|
|
30
30
|
if (source === '') return;
|
|
31
31
|
return source.slice(0, pattern.length) === pattern
|
|
32
32
|
? [[pattern], source.slice(pattern.length)]
|
|
33
|
-
:
|
|
33
|
+
: undefined;
|
|
34
34
|
})
|
|
35
35
|
: creator(source => {
|
|
36
36
|
if (source === '') return;
|
|
37
37
|
const m = source.match(pattern);
|
|
38
38
|
return m
|
|
39
39
|
? [[m[0]], source.slice(m[0].length)]
|
|
40
|
-
:
|
|
40
|
+
: undefined;
|
|
41
41
|
});
|
|
42
42
|
}
|
package/src/parser/util.ts
CHANGED
|
@@ -139,16 +139,20 @@ function isVisible(node: HTMLElement | string, strpos?: number): boolean {
|
|
|
139
139
|
|
|
140
140
|
export function trimBlank<P extends Parser<HTMLElement | string>>(parser: P): P;
|
|
141
141
|
export function trimBlank<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
|
|
142
|
-
return
|
|
143
|
-
trimBlankStart(parser),
|
|
144
|
-
trimNodeEnd);
|
|
142
|
+
return trimBlankStart(trimBlankEnd(parser));
|
|
145
143
|
}
|
|
146
|
-
function trimBlankStart<P extends Parser<unknown>>(parser: P): P;
|
|
147
|
-
function trimBlankStart<T>(parser: Parser<T>): Parser<T> {
|
|
144
|
+
export function trimBlankStart<P extends Parser<unknown>>(parser: P): P;
|
|
145
|
+
export function trimBlankStart<T>(parser: Parser<T>): Parser<T> {
|
|
148
146
|
return convert(
|
|
149
147
|
reduce(source => source.replace(regBlankStart, '')),
|
|
150
148
|
parser);
|
|
151
149
|
}
|
|
150
|
+
export function trimBlankEnd<P extends Parser<HTMLElement | string>>(parser: P): P;
|
|
151
|
+
export function trimBlankEnd<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
|
|
152
|
+
return fmap(
|
|
153
|
+
parser,
|
|
154
|
+
trimNodeEnd);
|
|
155
|
+
}
|
|
152
156
|
//export function trimNode(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
|
|
153
157
|
// return trimNodeStart(trimNodeEnd(nodes));
|
|
154
158
|
//}
|
|
@@ -166,7 +170,7 @@ function trimBlankStart<T>(parser: Parser<T>): Parser<T> {
|
|
|
166
170
|
// }
|
|
167
171
|
// return nodes;
|
|
168
172
|
//}
|
|
169
|
-
|
|
173
|
+
function trimNodeEnd<T extends HTMLElement | string>(nodes: T[]): T[] {
|
|
170
174
|
const skip = nodes.length > 0 &&
|
|
171
175
|
typeof nodes[nodes.length - 1] === 'object' &&
|
|
172
176
|
nodes[nodes.length - 1]['className'] === 'indexer'
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { indentblock } from './indentblock';
|
|
2
|
-
import { some } from '../../combinator';
|
|
3
|
-
import { inspect } from '../../debug.test';
|
|
4
|
-
|
|
5
|
-
describe('Unit: parser/block/indentblock', () => {
|
|
6
|
-
describe('indentblock', () => {
|
|
7
|
-
const parser = (source: string) => some(indentblock)(source, {});
|
|
8
|
-
|
|
9
|
-
it('invalid', () => {
|
|
10
|
-
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
11
|
-
assert.deepStrictEqual(inspect(parser('\na')), undefined);
|
|
12
|
-
assert.deepStrictEqual(inspect(parser('a')), undefined);
|
|
13
|
-
assert.deepStrictEqual(inspect(parser(' a')), undefined);
|
|
14
|
-
assert.deepStrictEqual(inspect(parser(' a')), undefined);
|
|
15
|
-
assert.deepStrictEqual(inspect(parser(' \ta')), undefined);
|
|
16
|
-
assert.deepStrictEqual(inspect(parser(' a\nb')), undefined);
|
|
17
|
-
assert.deepStrictEqual(inspect(parser(' a\n b')), undefined);
|
|
18
|
-
assert.deepStrictEqual(inspect(parser(' a\n\tb')), undefined);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('valid', () => {
|
|
22
|
-
assert.deepStrictEqual(inspect(parser(' a')), [['<pre class="text">a</pre>'], '']);
|
|
23
|
-
assert.deepStrictEqual(inspect(parser(' a ')), [['<pre class="text">a </pre>'], '']);
|
|
24
|
-
assert.deepStrictEqual(inspect(parser(' a \n')), [['<pre class="text">a </pre>'], '']);
|
|
25
|
-
assert.deepStrictEqual(inspect(parser(' a \n b')), [['<pre class="text">a <br> b</pre>'], '']);
|
|
26
|
-
assert.deepStrictEqual(inspect(parser(' a \\\n b')), [['<pre class="text">a \\<br> b</pre>'], '']);
|
|
27
|
-
assert.deepStrictEqual(inspect(parser(' a')), [['<pre class="text"> a</pre>'], '']);
|
|
28
|
-
assert.deepStrictEqual(inspect(parser(' a')), [['<pre class="text">a</pre>'], '']);
|
|
29
|
-
assert.deepStrictEqual(inspect(parser(' \ta')), [['<pre class="text">\ta</pre>'], '']);
|
|
30
|
-
assert.deepStrictEqual(inspect(parser('\ta')), [['<pre class="text">a</pre>'], '']);
|
|
31
|
-
assert.deepStrictEqual(inspect(parser('\t\ta')), [['<pre class="text">a</pre>'], '']);
|
|
32
|
-
assert.deepStrictEqual(inspect(parser('\t a')), [['<pre class="text"> a</pre>'], '']);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { IndentBlockParser } from '../block';
|
|
2
|
-
import { union, block, indent, convert } from '../../combinator';
|
|
3
|
-
import { codeblock } from './codeblock';
|
|
4
|
-
|
|
5
|
-
// 空行を含むインデントブロックはインデントの違いによるセグメント分割の境界が視認不能となるため採用しない
|
|
6
|
-
|
|
7
|
-
export const indentblock: IndentBlockParser = block(indent(/^( {4}|\t)\1*/, convert(
|
|
8
|
-
source => {
|
|
9
|
-
const fence = (source.match(/^`{3,}(?=[^\S\n]*$)/mg) ?? [])
|
|
10
|
-
.reduce((max, fence) => fence > max ? fence : max, '``') + '`';
|
|
11
|
-
return `${fence}\n${source}\n${fence}`;
|
|
12
|
-
},
|
|
13
|
-
union([codeblock])), true));
|