securemark 0.258.8 → 0.258.9
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 +54 -31
- package/markdown.d.ts +37 -20
- package/package.json +1 -1
- package/src/parser/inline/autolink/account.ts +2 -2
- package/src/parser/inline/autolink/anchor.ts +2 -2
- package/src/parser/inline/autolink/hashnum.ts +2 -2
- package/src/parser/inline/autolink/hashtag.ts +2 -2
- package/src/parser/inline/autolink/url.ts +2 -2
- package/src/parser/inline/link.ts +72 -60
- package/src/parser/inline/media.ts +10 -9
- package/src/parser/inline.ts +0 -1
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! securemark v0.258.
|
|
1
|
+
/*! securemark v0.258.9 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"));
|
|
@@ -5778,7 +5778,7 @@ const source_1 = __webpack_require__(6743);
|
|
|
5778
5778
|
const dom_1 = __webpack_require__(3252); // https://example/@user must be a user page or a redirect page going there.
|
|
5779
5779
|
|
|
5780
5780
|
|
|
5781
|
-
exports.account = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.rewrite)((0, combinator_1.open)('@', (0, combinator_1.tails)([(0, combinator_1.verify)((0, source_1.str)(/^[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?)*\//), ([source]) => source.length <= 253 + 1), (0, combinator_1.verify)((0, source_1.str)(/^[A-Za-z][0-9A-Za-z]*(?:-[0-9A-Za-z]+)*/), ([source]) => source.length <= 64)])), (0, combinator_1.convert)(source => `[${source}]{ ${source.includes('/') ? `https://${source.slice(1).replace('/', '/@')}` : `/${source}`} }`, (0, combinator_1.union)([link_1.
|
|
5781
|
+
exports.account = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.rewrite)((0, combinator_1.open)('@', (0, combinator_1.tails)([(0, combinator_1.verify)((0, source_1.str)(/^[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?)*\//), ([source]) => source.length <= 253 + 1), (0, combinator_1.verify)((0, source_1.str)(/^[A-Za-z][0-9A-Za-z]*(?:-[0-9A-Za-z]+)*/), ([source]) => source.length <= 64)])), (0, combinator_1.convert)(source => `[${source}]{ ${source.includes('/') ? `https://${source.slice(1).replace('/', '/@')}` : `/${source}`} }`, (0, combinator_1.union)([link_1.unsafelink]))), ([el]) => [(0, dom_1.define)(el, {
|
|
5782
5782
|
class: 'account'
|
|
5783
5783
|
})]));
|
|
5784
5784
|
|
|
@@ -5807,7 +5807,7 @@ const dom_1 = __webpack_require__(3252); // Timeline(pseudonym): user/tid
|
|
|
5807
5807
|
// 外部表現は投稿ごとに投稿者の投稿時のタイムゾーンに統一する(非時系列順)
|
|
5808
5808
|
|
|
5809
5809
|
|
|
5810
|
-
exports.anchor = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('>>', (0, combinator_1.fmap)((0, combinator_1.focus)(/^>>(?:[A-Za-z][0-9A-Za-z]*(?:-[0-9A-Za-z]+)*\/)?[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*(?![0-9A-Za-z@#:])/, (0, combinator_1.convert)(source => `[${source}]{ ${source.includes('/') ? `/@${source.slice(2).replace('/', '/timeline/')}` : `?at=${source.slice(2)}`} }`, (0, combinator_1.union)([link_1.
|
|
5810
|
+
exports.anchor = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('>>', (0, combinator_1.fmap)((0, combinator_1.focus)(/^>>(?:[A-Za-z][0-9A-Za-z]*(?:-[0-9A-Za-z]+)*\/)?[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*(?![0-9A-Za-z@#:])/, (0, combinator_1.convert)(source => `[${source}]{ ${source.includes('/') ? `/@${source.slice(2).replace('/', '/timeline/')}` : `?at=${source.slice(2)}`} }`, (0, combinator_1.union)([link_1.unsafelink]))), ([el]) => [(0, dom_1.define)(el, {
|
|
5811
5811
|
class: 'anchor'
|
|
5812
5812
|
})])));
|
|
5813
5813
|
|
|
@@ -5894,7 +5894,7 @@ const source_1 = __webpack_require__(6743);
|
|
|
5894
5894
|
|
|
5895
5895
|
const dom_1 = __webpack_require__(3252);
|
|
5896
5896
|
|
|
5897
|
-
exports.hashnum = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.rewrite)((0, combinator_1.open)('#', (0, source_1.str)(new RegExp(/^[0-9]{1,16}(?![^\p{C}\p{S}\p{P}\s]|emoji|['_])/u.source.replace(/emoji/, hashtag_1.emoji), 'u'))), (0, combinator_1.convert)(source => `[${source}]{ ${source.slice(1)} }`, (0, combinator_1.union)([link_1.
|
|
5897
|
+
exports.hashnum = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.rewrite)((0, combinator_1.open)('#', (0, source_1.str)(new RegExp(/^[0-9]{1,16}(?![^\p{C}\p{S}\p{P}\s]|emoji|['_])/u.source.replace(/emoji/, hashtag_1.emoji), 'u'))), (0, combinator_1.convert)(source => `[${source}]{ ${source.slice(1)} }`, (0, combinator_1.union)([link_1.unsafelink]))), ([el]) => [(0, dom_1.define)(el, {
|
|
5898
5898
|
class: 'hashnum',
|
|
5899
5899
|
href: null
|
|
5900
5900
|
})]));
|
|
@@ -5923,7 +5923,7 @@ const dom_1 = __webpack_require__(3252); // https://example/hashtags/a must be a
|
|
|
5923
5923
|
|
|
5924
5924
|
|
|
5925
5925
|
exports.emoji = String.raw`\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F`;
|
|
5926
|
-
exports.hashtag = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.rewrite)((0, combinator_1.open)('#', (0, combinator_1.tails)([(0, combinator_1.verify)((0, source_1.str)(/^[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?)*\//), ([source]) => source.length <= 253 + 1), (0, combinator_1.verify)((0, source_1.str)(new RegExp([/^(?=[0-9]{0,127}_?(?:[^\d\p{C}\p{S}\p{P}\s]|emoji))/u.source, /(?:[^\p{C}\p{S}\p{P}\s]|emoji|_(?=[^\p{C}\p{S}\p{P}\s]|emoji)){1,128}/u.source, /(?!_?(?:[^\p{C}\p{S}\p{P}\s]|emoji)|')/u.source].join('').replace(/emoji/g, exports.emoji), 'u')), ([source]) => source.length <= 128)])), (0, combinator_1.convert)(source => `[${source}]{ ${source.includes('/') ? `https://${source.slice(1).replace('/', '/hashtags/')}` : `/hashtags/${source.slice(1)}`} }`, (0, combinator_1.union)([link_1.
|
|
5926
|
+
exports.hashtag = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.rewrite)((0, combinator_1.open)('#', (0, combinator_1.tails)([(0, combinator_1.verify)((0, source_1.str)(/^[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?)*\//), ([source]) => source.length <= 253 + 1), (0, combinator_1.verify)((0, source_1.str)(new RegExp([/^(?=[0-9]{0,127}_?(?:[^\d\p{C}\p{S}\p{P}\s]|emoji))/u.source, /(?:[^\p{C}\p{S}\p{P}\s]|emoji|_(?=[^\p{C}\p{S}\p{P}\s]|emoji)){1,128}/u.source, /(?!_?(?:[^\p{C}\p{S}\p{P}\s]|emoji)|')/u.source].join('').replace(/emoji/g, exports.emoji), 'u')), ([source]) => source.length <= 128)])), (0, combinator_1.convert)(source => `[${source}]{ ${source.includes('/') ? `https://${source.slice(1).replace('/', '/hashtags/')}` : `/hashtags/${source.slice(1)}`} }`, (0, combinator_1.union)([link_1.unsafelink]))), ([el]) => [(0, dom_1.define)(el, {
|
|
5927
5927
|
class: 'hashtag'
|
|
5928
5928
|
}, el.innerText)]));
|
|
5929
5929
|
|
|
@@ -5947,7 +5947,7 @@ const link_1 = __webpack_require__(9628);
|
|
|
5947
5947
|
const source_1 = __webpack_require__(6743);
|
|
5948
5948
|
|
|
5949
5949
|
const closer = /^[-+*=~^,.;:!?]*(?=[\\"`|\[\](){}<>]|$)/;
|
|
5950
|
-
exports.url = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['http://', 'https://'], (0, combinator_1.rewrite)((0, combinator_1.open)(/^https?:\/\/(?=[\x21-\x7E])/, (0, combinator_1.focus)(/^[\x21-\x7E]+/, (0, combinator_1.some)((0, combinator_1.union)([bracket, (0, combinator_1.some)(source_1.unescsource, closer)])))), (0, combinator_1.convert)(url => `{ ${url} }`, (0, combinator_1.union)([link_1.
|
|
5950
|
+
exports.url = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['http://', 'https://'], (0, combinator_1.rewrite)((0, combinator_1.open)(/^https?:\/\/(?=[\x21-\x7E])/, (0, combinator_1.focus)(/^[\x21-\x7E]+/, (0, combinator_1.some)((0, combinator_1.union)([bracket, (0, combinator_1.some)(source_1.unescsource, closer)])))), (0, combinator_1.convert)(url => `{ ${url} }`, (0, combinator_1.union)([link_1.unsafelink])))));
|
|
5951
5951
|
const bracket = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, combinator_1.precedence)(2, (0, combinator_1.union)([(0, combinator_1.surround)('(', (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.unescsource]), ')'), ')', true), (0, combinator_1.surround)('[', (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.unescsource]), ']'), ']', true), (0, combinator_1.surround)('{', (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.unescsource]), '}'), '}', true), (0, combinator_1.surround)('"', (0, combinator_1.precedence)(8, (0, combinator_1.some)(source_1.unescsource, '"')), '"', true)]))));
|
|
5952
5952
|
|
|
5953
5953
|
/***/ }),
|
|
@@ -6650,7 +6650,7 @@ exports.insertion = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0,
|
|
|
6650
6650
|
Object.defineProperty(exports, "__esModule", ({
|
|
6651
6651
|
value: true
|
|
6652
6652
|
}));
|
|
6653
|
-
exports.resolve = exports.option = exports.uri = exports.
|
|
6653
|
+
exports.resolve = exports.option = exports.uri = exports.unsafelink = exports.link = void 0;
|
|
6654
6654
|
|
|
6655
6655
|
const global_1 = __webpack_require__(4128);
|
|
6656
6656
|
|
|
@@ -6678,11 +6678,14 @@ const optspec = {
|
|
|
6678
6678
|
rel: ['nofollow']
|
|
6679
6679
|
};
|
|
6680
6680
|
Object.setPrototypeOf(optspec, null);
|
|
6681
|
-
exports.link = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['[', '{'], (0, combinator_1.
|
|
6681
|
+
exports.link = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['[', '{'], (0, combinator_1.union)([medialink, textlink])));
|
|
6682
|
+
const textlink = (0, combinator_1.lazy)(() => (0, combinator_1.constraint)(4
|
|
6682
6683
|
/* State.link */
|
|
6683
|
-
, false, (0, combinator_1.
|
|
6684
|
+
, false, (0, combinator_1.state)(4
|
|
6684
6685
|
/* State.link */
|
|
6685
|
-
|
|
6686
|
+
| 2
|
|
6687
|
+
/* State.media */
|
|
6688
|
+
| 64
|
|
6686
6689
|
/* State.annotation */
|
|
6687
6690
|
| 32
|
|
6688
6691
|
/* State.reference */
|
|
@@ -6690,37 +6693,56 @@ exports.link = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['[', '{'
|
|
|
6690
6693
|
/* State.index */
|
|
6691
6694
|
| 8
|
|
6692
6695
|
/* State.label */
|
|
6693
|
-
| 2
|
|
6694
|
-
/* State.media */
|
|
6695
6696
|
| 1
|
|
6696
6697
|
/* State.autolink */
|
|
6697
6698
|
, (0, combinator_1.syntax)(256
|
|
6698
6699
|
/* Syntax.link */
|
|
6699
|
-
, 2, 0, (0, combinator_1.some)(inline_1.inline, ']', [[/^\\?\n/, 9], [']', 2]])
|
|
6700
|
-
if (content[0] === '') return [content, rest];
|
|
6701
|
-
if (params.length === 0) return;
|
|
6700
|
+
, 2, 10, (0, combinator_1.bind)((0, combinator_1.reverse)((0, combinator_1.tails)([(0, combinator_1.dup)((0, combinator_1.surround)('[', (0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), ']', [[/^\\?\n/, 9], [']', 2]]), ']', true)), (0, combinator_1.dup)((0, combinator_1.surround)(/^{(?![{}])/, (0, combinator_1.inits)([exports.uri, (0, combinator_1.some)(exports.option)]), /^[^\S\n]*}/))])), ([params, content = []], rest, context) => {
|
|
6702
6701
|
if (content.length !== 0 && (0, visibility_1.trimNode)(content).length === 0) return;
|
|
6703
6702
|
|
|
6704
6703
|
for (let source = (0, util_1.stringify)(content); source;) {
|
|
6705
|
-
const result = (0,
|
|
6704
|
+
const result = (0, combinator_1.state)(1
|
|
6705
|
+
/* State.autolink */
|
|
6706
|
+
, false, autolink_1.autolink)(source, context);
|
|
6706
6707
|
if (typeof (0, parser_1.eval)(result)[0] === 'object') return;
|
|
6707
6708
|
source = (0, parser_1.exec)(result);
|
|
6708
6709
|
}
|
|
6709
6710
|
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6711
|
+
return parse(content, params, rest, context);
|
|
6712
|
+
})))));
|
|
6713
|
+
const medialink = (0, combinator_1.lazy)(() => (0, combinator_1.constraint)(4
|
|
6714
|
+
/* State.link */
|
|
6715
|
+
| 2
|
|
6716
|
+
/* State.media */
|
|
6717
|
+
, false, (0, combinator_1.state)(4
|
|
6718
|
+
/* State.link */
|
|
6719
|
+
| 64
|
|
6720
|
+
/* State.annotation */
|
|
6721
|
+
| 32
|
|
6722
|
+
/* State.reference */
|
|
6723
|
+
| 16
|
|
6724
|
+
/* State.index */
|
|
6725
|
+
| 8
|
|
6726
|
+
/* State.label */
|
|
6727
|
+
| 1
|
|
6728
|
+
/* State.autolink */
|
|
6729
|
+
, (0, combinator_1.syntax)(256
|
|
6730
|
+
/* Syntax.link */
|
|
6731
|
+
, 2, 10, (0, combinator_1.bind)((0, combinator_1.reverse)((0, combinator_1.sequence)([(0, combinator_1.dup)((0, combinator_1.surround)('[', (0, combinator_1.union)([inline_1.media, inline_1.shortmedia]), ']')), (0, combinator_1.dup)((0, combinator_1.surround)(/^{(?![{}])/, (0, combinator_1.inits)([exports.uri, (0, combinator_1.some)(exports.option)]), /^[^\S\n]*}/))])), ([params, content = []], rest, context) => {
|
|
6732
|
+
return parse(content, params, rest, context);
|
|
6733
|
+
})))));
|
|
6734
|
+
exports.unsafelink = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['[', '{'], (0, combinator_1.bind)((0, combinator_1.creation)(10, (0, combinator_1.precedence)(2, (0, combinator_1.reverse)((0, combinator_1.tails)([(0, combinator_1.dup)((0, combinator_1.surround)('[', (0, combinator_1.some)((0, combinator_1.union)([source_1.unescsource]), ']'), ']')), (0, combinator_1.dup)((0, combinator_1.surround)(/^{(?![{}])/, (0, combinator_1.inits)([exports.uri, (0, combinator_1.some)(exports.option)]), /^[^\S\n]*}/))])))), ([params, content = []], rest, context) => {
|
|
6735
|
+
return parse(content, params, rest, context);
|
|
6714
6736
|
})));
|
|
6715
|
-
exports.
|
|
6716
|
-
|
|
6717
|
-
|
|
6737
|
+
exports.uri = (0, combinator_1.union)([(0, combinator_1.open)(/^[^\S\n]+/, (0, source_1.str)(/^\S+/)), (0, source_1.str)(/^[^\s{}]+/)]);
|
|
6738
|
+
exports.option = (0, combinator_1.union)([(0, combinator_1.fmap)((0, source_1.str)(/^[^\S\n]+nofollow(?=[^\S\n]|})/), () => [` rel="nofollow"`]), (0, source_1.str)(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="(?:\\[^\n]|[^\\\n"])*")?(?=[^\S\n]|})/), (0, combinator_1.fmap)((0, source_1.str)(/^[^\S\n]+[^\s{}]+/), opt => [` \\${opt.slice(1)}`])]);
|
|
6739
|
+
|
|
6740
|
+
function parse(content, params, rest, context) {
|
|
6718
6741
|
const INSECURE_URI = params.shift();
|
|
6719
6742
|
const el = elem(INSECURE_URI, (0, dom_1.defrag)(content), new url_1.ReadonlyURL(resolve(INSECURE_URI, context.host ?? global_1.location, context.url ?? context.host ?? global_1.location), context.host?.href || global_1.location.href), context.host?.origin || global_1.location.origin);
|
|
6743
|
+
if (el.className === 'invalid') return [[el], rest];
|
|
6720
6744
|
return [[(0, dom_1.define)(el, (0, html_1.attributes)('link', [], optspec, params))], rest];
|
|
6721
|
-
}
|
|
6722
|
-
exports.uri = (0, combinator_1.fmap)((0, combinator_1.union)([(0, combinator_1.open)(/^[^\S\n]+/, (0, source_1.str)(/^\S+/)), (0, source_1.str)(/^[^\s{}]+/)]), ([uri]) => ['\r', uri]);
|
|
6723
|
-
exports.option = (0, combinator_1.union)([(0, combinator_1.fmap)((0, source_1.str)(/^[^\S\n]+nofollow(?=[^\S\n]|})/), () => [` rel="nofollow"`]), (0, source_1.str)(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="(?:\\[^\n]|[^\\\n"])*")?(?=[^\S\n]|})/), (0, combinator_1.fmap)((0, source_1.str)(/^[^\S\n]+[^\s{}]+/), opt => [` \\${opt.slice(1)}`])]);
|
|
6745
|
+
}
|
|
6724
6746
|
|
|
6725
6747
|
function resolve(uri, host, source) {
|
|
6726
6748
|
switch (true) {
|
|
@@ -6900,11 +6922,11 @@ const optspec = {
|
|
|
6900
6922
|
rel: global_1.undefined
|
|
6901
6923
|
};
|
|
6902
6924
|
Object.setPrototypeOf(optspec, null);
|
|
6903
|
-
exports.media = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['![', '!{'], (0, combinator_1.
|
|
6925
|
+
exports.media = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['![', '!{'], (0, combinator_1.open)('!', (0, combinator_1.constraint)(2
|
|
6904
6926
|
/* State.media */
|
|
6905
6927
|
, false, (0, combinator_1.syntax)(64
|
|
6906
6928
|
/* Syntax.media */
|
|
6907
|
-
, 2, 10, (0, combinator_1.tails)([(0, combinator_1.dup)((0, combinator_1.surround)('[', (0, combinator_1.some)((0, combinator_1.union)([htmlentity_1.unsafehtmlentity, bracket, source_1.txt]), ']', [[/^\\?\n/, 9]]), ']', true)), (0, combinator_1.dup)((0, combinator_1.surround)(/^{(?![{}])/, (0, combinator_1.inits)([link_1.uri, (0, combinator_1.some)(option)]), /^[^\S\n]*}/))])
|
|
6929
|
+
, 2, 10, (0, combinator_1.bind)((0, combinator_1.verify)((0, combinator_1.fmap)((0, combinator_1.tails)([(0, combinator_1.dup)((0, combinator_1.surround)('[', (0, combinator_1.some)((0, combinator_1.union)([htmlentity_1.unsafehtmlentity, bracket, source_1.txt]), ']', [[/^\\?\n/, 9]]), ']', true)), (0, combinator_1.dup)((0, combinator_1.surround)(/^{(?![{}])/, (0, combinator_1.inits)([link_1.uri, (0, combinator_1.some)(option)]), /^[^\S\n]*}/))]), ([as, bs]) => bs ? [[as.join('').trim() || as.join('')], bs] : [[''], as]), ([[text]]) => text === '' || text.trim() !== ''), ([[text], params], rest, context) => {
|
|
6908
6930
|
const INSECURE_URI = params.shift();
|
|
6909
6931
|
const url = new url_1.ReadonlyURL((0, link_1.resolve)(INSECURE_URI, context.host ?? global_1.location, context.url ?? context.host ?? global_1.location), context.host?.href || global_1.location.href);
|
|
6910
6932
|
let cache;
|
|
@@ -6924,11 +6946,12 @@ exports.media = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['![', '
|
|
|
6924
6946
|
|
|
6925
6947
|
if (context.state & 4
|
|
6926
6948
|
/* State.link */
|
|
6927
|
-
|
|
6928
|
-
return (0, combinator_1.
|
|
6949
|
+
) return [[el], rest];
|
|
6950
|
+
if (cache && cache.tagName !== 'IMG') return (0, combinator_1.creation)(10, (..._) => [[el], rest])('!', context);
|
|
6951
|
+
return (0, combinator_1.fmap)(link_1.unsafelink, ([link]) => [(0, dom_1.define)(link, {
|
|
6929
6952
|
target: '_blank'
|
|
6930
6953
|
}, [el])])(`{ ${INSECURE_URI}${params.join('')} }${rest}`, context);
|
|
6931
|
-
})));
|
|
6954
|
+
}))))));
|
|
6932
6955
|
const bracket = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, combinator_1.union)([(0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.some)((0, combinator_1.union)([htmlentity_1.unsafehtmlentity, bracket, source_1.txt]), ')'), (0, source_1.str)(')'), true, global_1.undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('['), (0, combinator_1.some)((0, combinator_1.union)([htmlentity_1.unsafehtmlentity, bracket, source_1.txt]), ']'), (0, source_1.str)(']'), true, global_1.undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('{'), (0, combinator_1.some)((0, combinator_1.union)([htmlentity_1.unsafehtmlentity, bracket, source_1.txt]), '}'), (0, source_1.str)('}'), true, global_1.undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('"'), (0, combinator_1.precedence)(8, (0, combinator_1.some)((0, combinator_1.union)([htmlentity_1.unsafehtmlentity, source_1.txt]), '"')), (0, source_1.str)('"'), true)])));
|
|
6933
6956
|
const option = (0, combinator_1.union)([(0, combinator_1.fmap)((0, source_1.str)(/^[^\S\n]+[1-9][0-9]*x[1-9][0-9]*(?=[^\S\n]|})/), ([opt]) => [` width="${opt.slice(1).split('x')[0]}"`, ` height="${opt.slice(1).split('x')[1]}"`]), (0, combinator_1.fmap)((0, source_1.str)(/^[^\S\n]+[1-9][0-9]*:[1-9][0-9]*(?=[^\S\n]|})/), ([opt]) => [` aspect-ratio="${opt.slice(1).split(':').join('/')}"`]), link_1.option]);
|
|
6934
6957
|
|
package/markdown.d.ts
CHANGED
|
@@ -660,7 +660,7 @@ export namespace MarkdownParser {
|
|
|
660
660
|
export interface AnnotationParser extends
|
|
661
661
|
// ((abc))
|
|
662
662
|
Inline<'annotation'>,
|
|
663
|
-
Parser<HTMLElement
|
|
663
|
+
Parser<HTMLElement, Context, [
|
|
664
664
|
InlineParser,
|
|
665
665
|
]> {
|
|
666
666
|
}
|
|
@@ -669,7 +669,7 @@ export namespace MarkdownParser {
|
|
|
669
669
|
// [[^abbr]]
|
|
670
670
|
// [[^abbr| abc]]
|
|
671
671
|
Inline<'reference'>,
|
|
672
|
-
Parser<HTMLElement
|
|
672
|
+
Parser<HTMLElement, Context, [
|
|
673
673
|
ReferenceParser.AbbrParser,
|
|
674
674
|
InlineParser,
|
|
675
675
|
InlineParser,
|
|
@@ -689,7 +689,7 @@ export namespace MarkdownParser {
|
|
|
689
689
|
export interface TemplateParser extends
|
|
690
690
|
// {{abc}}
|
|
691
691
|
Inline<'template'>,
|
|
692
|
-
Parser<HTMLSpanElement
|
|
692
|
+
Parser<HTMLSpanElement, Context, [
|
|
693
693
|
TemplateParser.BracketParser,
|
|
694
694
|
SourceParser.EscapableSourceParser,
|
|
695
695
|
]> {
|
|
@@ -842,21 +842,38 @@ export namespace MarkdownParser {
|
|
|
842
842
|
// { uri }
|
|
843
843
|
// [abc]{uri nofollow}
|
|
844
844
|
Inline<'link'>,
|
|
845
|
-
Parser<HTMLElement
|
|
846
|
-
LinkParser.
|
|
847
|
-
LinkParser.
|
|
848
|
-
]> {
|
|
849
|
-
}
|
|
850
|
-
export interface TextLinkParser extends
|
|
851
|
-
// { uri }
|
|
852
|
-
// [abc]{uri nofollow}
|
|
853
|
-
Inline<'textlink'>,
|
|
854
|
-
Parser<HTMLAnchorElement, Context, [
|
|
855
|
-
LinkParser.TextParser,
|
|
856
|
-
LinkParser.ParameterParser,
|
|
845
|
+
Parser<HTMLElement, Context, [
|
|
846
|
+
LinkParser.MediaLinkParser,
|
|
847
|
+
LinkParser.TextLinkParser,
|
|
857
848
|
]> {
|
|
858
849
|
}
|
|
859
850
|
export namespace LinkParser {
|
|
851
|
+
export interface TextLinkParser extends
|
|
852
|
+
Inline<'link/textlink'>,
|
|
853
|
+
Parser<HTMLElement, Context, [
|
|
854
|
+
Parser<(HTMLElement | string)[], Context, [
|
|
855
|
+
InlineParser,
|
|
856
|
+
]>,
|
|
857
|
+
LinkParser.ParameterParser,
|
|
858
|
+
]> {
|
|
859
|
+
}
|
|
860
|
+
export interface MediaLinkParser extends
|
|
861
|
+
Inline<'link/medialink'>,
|
|
862
|
+
Parser<HTMLElement, Context, [
|
|
863
|
+
Parser<HTMLElement[], Context, [
|
|
864
|
+
MediaParser,
|
|
865
|
+
ShortmediaParser,
|
|
866
|
+
]>,
|
|
867
|
+
LinkParser.ParameterParser,
|
|
868
|
+
]> {
|
|
869
|
+
}
|
|
870
|
+
export interface UnsafeLinkParser extends
|
|
871
|
+
Inline<'link/unsafelink'>,
|
|
872
|
+
Parser<HTMLAnchorElement, Context, [
|
|
873
|
+
LinkParser.TextParser,
|
|
874
|
+
LinkParser.ParameterParser,
|
|
875
|
+
]> {
|
|
876
|
+
}
|
|
860
877
|
export interface ContentParser extends
|
|
861
878
|
Inline<'link/content'>,
|
|
862
879
|
Parser<(HTMLElement | string)[], Context, [
|
|
@@ -1093,7 +1110,7 @@ export namespace MarkdownParser {
|
|
|
1093
1110
|
// https://host
|
|
1094
1111
|
Inline<'url'>,
|
|
1095
1112
|
Parser<HTMLAnchorElement, Context, [
|
|
1096
|
-
|
|
1113
|
+
LinkParser.UnsafeLinkParser,
|
|
1097
1114
|
]> {
|
|
1098
1115
|
}
|
|
1099
1116
|
export namespace UrlParser {
|
|
@@ -1135,28 +1152,28 @@ export namespace MarkdownParser {
|
|
|
1135
1152
|
// @user
|
|
1136
1153
|
Inline<'account'>,
|
|
1137
1154
|
Parser<HTMLAnchorElement, Context, [
|
|
1138
|
-
|
|
1155
|
+
LinkParser.UnsafeLinkParser,
|
|
1139
1156
|
]> {
|
|
1140
1157
|
}
|
|
1141
1158
|
export interface HashtagParser extends
|
|
1142
1159
|
// #tag
|
|
1143
1160
|
Inline<'hashtag'>,
|
|
1144
1161
|
Parser<HTMLAnchorElement, Context, [
|
|
1145
|
-
|
|
1162
|
+
LinkParser.UnsafeLinkParser,
|
|
1146
1163
|
]> {
|
|
1147
1164
|
}
|
|
1148
1165
|
export interface HashnumParser extends
|
|
1149
1166
|
// #1
|
|
1150
1167
|
Inline<'hashnum'>,
|
|
1151
1168
|
Parser<HTMLAnchorElement, Context, [
|
|
1152
|
-
|
|
1169
|
+
LinkParser.UnsafeLinkParser,
|
|
1153
1170
|
]> {
|
|
1154
1171
|
}
|
|
1155
1172
|
export interface AnchorParser extends
|
|
1156
1173
|
// >>1
|
|
1157
1174
|
Inline<'anchor'>,
|
|
1158
1175
|
Parser<HTMLAnchorElement, Context, [
|
|
1159
|
-
|
|
1176
|
+
LinkParser.UnsafeLinkParser,
|
|
1160
1177
|
]> {
|
|
1161
1178
|
}
|
|
1162
1179
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AutolinkParser } from '../../inline';
|
|
2
2
|
import { union, tails, verify, rewrite, open, convert, fmap, lazy } from '../../../combinator';
|
|
3
|
-
import {
|
|
3
|
+
import { unsafelink } from '../link';
|
|
4
4
|
import { str } from '../../source';
|
|
5
5
|
import { define } from 'typed-dom/dom';
|
|
6
6
|
|
|
@@ -24,5 +24,5 @@ export const account: AutolinkParser.AccountParser = lazy(() => fmap(rewrite(
|
|
|
24
24
|
? `https://${source.slice(1).replace('/', '/@')}`
|
|
25
25
|
: `/${source}`
|
|
26
26
|
} }`,
|
|
27
|
-
union([
|
|
27
|
+
union([unsafelink]))),
|
|
28
28
|
([el]) => [define(el, { class: 'account' })]));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AutolinkParser } from '../../inline';
|
|
2
2
|
import { union, validate, focus, convert, fmap, lazy } from '../../../combinator';
|
|
3
|
-
import {
|
|
3
|
+
import { unsafelink } from '../link';
|
|
4
4
|
import { define } from 'typed-dom/dom';
|
|
5
5
|
|
|
6
6
|
// Timeline(pseudonym): user/tid
|
|
@@ -21,5 +21,5 @@ export const anchor: AutolinkParser.AnchorParser = lazy(() => validate('>>', fma
|
|
|
21
21
|
? `/@${source.slice(2).replace('/', '/timeline/')}`
|
|
22
22
|
: `?at=${source.slice(2)}`
|
|
23
23
|
} }`,
|
|
24
|
-
union([
|
|
24
|
+
union([unsafelink]))),
|
|
25
25
|
([el]) => [define(el, { class: 'anchor' })])));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AutolinkParser } from '../../inline';
|
|
2
2
|
import { union, rewrite, open, convert, fmap, lazy } from '../../../combinator';
|
|
3
|
-
import {
|
|
3
|
+
import { unsafelink } from '../link';
|
|
4
4
|
import { emoji } from './hashtag';
|
|
5
5
|
import { str } from '../../source';
|
|
6
6
|
import { define } from 'typed-dom/dom';
|
|
@@ -9,5 +9,5 @@ export const hashnum: AutolinkParser.HashnumParser = lazy(() => fmap(rewrite(
|
|
|
9
9
|
open('#', str(new RegExp(/^[0-9]{1,16}(?![^\p{C}\p{S}\p{P}\s]|emoji|['_])/u.source.replace(/emoji/, emoji), 'u'))),
|
|
10
10
|
convert(
|
|
11
11
|
source => `[${source}]{ ${source.slice(1)} }`,
|
|
12
|
-
union([
|
|
12
|
+
union([unsafelink]))),
|
|
13
13
|
([el]) => [define(el, { class: 'hashnum', href: null })]));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AutolinkParser } from '../../inline';
|
|
2
2
|
import { union, tails, verify, rewrite, open, convert, fmap, lazy } from '../../../combinator';
|
|
3
|
-
import {
|
|
3
|
+
import { unsafelink } from '../link';
|
|
4
4
|
import { str } from '../../source';
|
|
5
5
|
import { define } from 'typed-dom/dom';
|
|
6
6
|
|
|
@@ -31,5 +31,5 @@ export const hashtag: AutolinkParser.HashtagParser = lazy(() => fmap(rewrite(
|
|
|
31
31
|
? `https://${source.slice(1).replace('/', '/hashtags/')}`
|
|
32
32
|
: `/hashtags/${source.slice(1)}`
|
|
33
33
|
} }`,
|
|
34
|
-
union([
|
|
34
|
+
union([unsafelink]))),
|
|
35
35
|
([el]) => [define(el, { class: 'hashtag' }, el.innerText)]));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AutolinkParser } from '../../inline';
|
|
2
2
|
import { union, some, creation, precedence, validate, focus, rewrite, convert, surround, open, lazy } from '../../../combinator';
|
|
3
|
-
import {
|
|
3
|
+
import { unsafelink } from '../link';
|
|
4
4
|
import { unescsource } from '../../source';
|
|
5
5
|
|
|
6
6
|
const closer = /^[-+*=~^,.;:!?]*(?=[\\"`|\[\](){}<>]|$)/;
|
|
@@ -11,7 +11,7 @@ export const url: AutolinkParser.UrlParser = lazy(() => validate(['http://', 'ht
|
|
|
11
11
|
focus(/^[\x21-\x7E]+/, some(union([bracket, some(unescsource, closer)])))),
|
|
12
12
|
convert(
|
|
13
13
|
url => `{ ${url} }`,
|
|
14
|
-
union([
|
|
14
|
+
union([unsafelink])))));
|
|
15
15
|
|
|
16
16
|
const bracket: AutolinkParser.UrlParser.BracketParser = lazy(() => creation(precedence(2, union([
|
|
17
17
|
surround('(', some(union([bracket, unescsource]), ')'), ')', true),
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { undefined, location, encodeURI, decodeURI, Location } from 'spica/global';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { MarkdownParser } from '../../../markdown';
|
|
3
|
+
import { LinkParser } from '../inline';
|
|
4
|
+
import { Result, eval, exec } from '../../combinator/data/parser';
|
|
5
|
+
import { union, inits, tails, sequence, some, constraint, syntax, creation, precedence, state, validate, surround, open, dup, reverse, lazy, fmap, bind } from '../../combinator';
|
|
5
6
|
import { inline, media, shortmedia } from '../inline';
|
|
6
7
|
import { attributes } from './html';
|
|
7
8
|
import { autolink } from '../autolink';
|
|
@@ -17,82 +18,72 @@ const optspec = {
|
|
|
17
18
|
} as const;
|
|
18
19
|
Object.setPrototypeOf(optspec, null);
|
|
19
20
|
|
|
20
|
-
export const link: LinkParser = lazy(() => validate(['[', '{'],
|
|
21
|
+
export const link: LinkParser = lazy(() => validate(['[', '{'], union([
|
|
22
|
+
medialink,
|
|
23
|
+
textlink,
|
|
24
|
+
])));
|
|
25
|
+
|
|
26
|
+
const textlink: LinkParser.TextLinkParser = lazy(() =>
|
|
21
27
|
constraint(State.link, false,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
dup(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
state(State.annotation | State.reference | State.index | State.label | State.media | State.autolink,
|
|
31
|
-
syntax(Syntax.link, 2, 0,
|
|
32
|
-
some(inline, ']', [[/^\\?\n/, 9], [']', 2]]))),
|
|
33
|
-
']',
|
|
34
|
-
true),
|
|
35
|
-
]))),
|
|
28
|
+
state(State.link | State.media | State.annotation | State.reference | State.index | State.label | State.autolink,
|
|
29
|
+
syntax(Syntax.link, 2, 10,
|
|
30
|
+
bind(reverse(tails([
|
|
31
|
+
dup(surround(
|
|
32
|
+
'[',
|
|
33
|
+
some(union([inline]), ']', [[/^\\?\n/, 9], [']', 2]]),
|
|
34
|
+
']',
|
|
35
|
+
true)),
|
|
36
36
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
37
|
-
]
|
|
38
|
-
([
|
|
39
|
-
|
|
40
|
-
assert(content[0] !== '' || params.length === 0);
|
|
41
|
-
if (content[0] === '') return [content, rest];
|
|
42
|
-
if (params.length === 0) return;
|
|
37
|
+
])),
|
|
38
|
+
([params, content = []]: [string[], (HTMLElement | string)[]], rest, context) => {
|
|
39
|
+
assert(params.length > 0);
|
|
43
40
|
assert(params.every(p => typeof p === 'string'));
|
|
44
41
|
if (content.length !== 0 && trimNode(content).length === 0) return;
|
|
45
42
|
for (let source = stringify(content); source;) {
|
|
46
|
-
const result = autolink(source, context);
|
|
43
|
+
const result = state(State.autolink, false, autolink)(source, context);
|
|
47
44
|
if (typeof eval(result!)[0] === 'object') return;
|
|
48
45
|
source = exec(result!);
|
|
49
46
|
}
|
|
50
|
-
assert(!html('div', content).querySelector('a, .media, .annotation, .reference')
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
47
|
+
assert(!html('div', content).querySelector('a, .media, .annotation, .reference'));
|
|
48
|
+
return parse(content, params, rest, context);
|
|
49
|
+
})))));
|
|
50
|
+
|
|
51
|
+
const medialink: LinkParser.MediaLinkParser = lazy(() =>
|
|
52
|
+
constraint(State.link | State.media, false,
|
|
53
|
+
state(State.link | State.annotation | State.reference | State.index | State.label | State.autolink,
|
|
54
|
+
syntax(Syntax.link, 2, 10,
|
|
55
|
+
bind(reverse(sequence([
|
|
56
|
+
dup(surround(
|
|
57
|
+
'[',
|
|
58
|
+
union([media, shortmedia]),
|
|
59
|
+
']')),
|
|
60
|
+
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
61
|
+
])),
|
|
62
|
+
([params, content = []]: [string[], (HTMLElement | string)[]], rest, context) => {
|
|
63
|
+
assert(params.length > 0);
|
|
64
|
+
assert(params.every(p => typeof p === 'string'));
|
|
65
|
+
assert(content.length === 1);
|
|
66
|
+
return parse(content, params, rest, context);
|
|
67
|
+
})))));
|
|
65
68
|
|
|
66
|
-
export const
|
|
69
|
+
export const unsafelink: LinkParser.UnsafeLinkParser = lazy(() => validate(['[', '{'], bind(
|
|
67
70
|
creation(10, precedence(2,
|
|
68
71
|
reverse(tails([
|
|
69
|
-
dup(surround(
|
|
72
|
+
dup(surround(
|
|
73
|
+
'[',
|
|
74
|
+
some(union([unescsource]), ']'),
|
|
75
|
+
']')),
|
|
70
76
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
71
77
|
])))),
|
|
72
78
|
([params, content = []], rest, context) => {
|
|
73
|
-
assert(params[0] === '\r');
|
|
74
|
-
params.shift();
|
|
75
79
|
assert(params.every(p => typeof p === 'string'));
|
|
76
|
-
|
|
77
|
-
const INSECURE_URI = params.shift()!;
|
|
78
|
-
assert(INSECURE_URI === INSECURE_URI.trim());
|
|
79
|
-
assert(!INSECURE_URI.match(/\s/));
|
|
80
|
-
const el = elem(
|
|
81
|
-
INSECURE_URI,
|
|
82
|
-
defrag(content),
|
|
83
|
-
new ReadonlyURL(
|
|
84
|
-
resolve(INSECURE_URI, context.host ?? location, context.url ?? context.host ?? location),
|
|
85
|
-
context.host?.href || location.href),
|
|
86
|
-
context.host?.origin || location.origin);
|
|
87
|
-
assert(el.className !== 'invalid');
|
|
88
|
-
assert(el.classList.length === 0);
|
|
89
|
-
return [[define(el, attributes('link', [], optspec, params))], rest];
|
|
80
|
+
return parse(content, params, rest, context);
|
|
90
81
|
})));
|
|
91
82
|
|
|
92
|
-
export const uri: LinkParser.ParameterParser.UriParser =
|
|
83
|
+
export const uri: LinkParser.ParameterParser.UriParser = union([
|
|
93
84
|
open(/^[^\S\n]+/, str(/^\S+/)),
|
|
94
85
|
str(/^[^\s{}]+/),
|
|
95
|
-
])
|
|
86
|
+
]);
|
|
96
87
|
|
|
97
88
|
export const option: LinkParser.ParameterParser.OptionParser = union([
|
|
98
89
|
fmap(str(/^[^\S\n]+nofollow(?=[^\S\n]|})/), () => [` rel="nofollow"`]),
|
|
@@ -100,6 +91,27 @@ export const option: LinkParser.ParameterParser.OptionParser = union([
|
|
|
100
91
|
fmap(str(/^[^\S\n]+[^\s{}]+/), opt => [` \\${opt.slice(1)}`]),
|
|
101
92
|
]);
|
|
102
93
|
|
|
94
|
+
function parse(
|
|
95
|
+
content: (string | HTMLElement)[],
|
|
96
|
+
params: string[],
|
|
97
|
+
rest: string,
|
|
98
|
+
context: MarkdownParser.Context,
|
|
99
|
+
): Result<HTMLAnchorElement, MarkdownParser.Context> {
|
|
100
|
+
const INSECURE_URI = params.shift()!;
|
|
101
|
+
assert(INSECURE_URI === INSECURE_URI.trim());
|
|
102
|
+
assert(!INSECURE_URI.match(/\s/));
|
|
103
|
+
const el = elem(
|
|
104
|
+
INSECURE_URI,
|
|
105
|
+
defrag(content),
|
|
106
|
+
new ReadonlyURL(
|
|
107
|
+
resolve(INSECURE_URI, context.host ?? location, context.url ?? context.host ?? location),
|
|
108
|
+
context.host?.href || location.href),
|
|
109
|
+
context.host?.origin || location.origin);
|
|
110
|
+
if (el.className === 'invalid') return [[el], rest];
|
|
111
|
+
assert(el.classList.length === 0);
|
|
112
|
+
return [[define(el, attributes('link', [], optspec, params))], rest];
|
|
113
|
+
}
|
|
114
|
+
|
|
103
115
|
export function resolve(uri: string, host: URL | Location, source: URL | Location): string {
|
|
104
116
|
assert(uri);
|
|
105
117
|
assert(uri === uri.trim());
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { undefined, location } from 'spica/global';
|
|
2
2
|
import { MediaParser } from '../inline';
|
|
3
3
|
import { union, inits, tails, some, syntax, creation, precedence, constraint, validate, verify, surround, open, dup, lazy, fmap, bind } from '../../combinator';
|
|
4
|
-
import {
|
|
4
|
+
import { unsafelink, uri, option as linkoption, resolve } from './link';
|
|
5
5
|
import { attributes } from './html';
|
|
6
6
|
import { unsafehtmlentity } from './htmlentity';
|
|
7
7
|
import { txt, str } from '../source';
|
|
8
8
|
import { Syntax, State } from '../context';
|
|
9
9
|
import { html, define } from 'typed-dom/dom';
|
|
10
10
|
import { ReadonlyURL } from 'spica/url';
|
|
11
|
-
import { unshift,
|
|
11
|
+
import { unshift, push } from 'spica/array';
|
|
12
12
|
|
|
13
13
|
const optspec = {
|
|
14
14
|
'width': [],
|
|
@@ -18,19 +18,19 @@ const optspec = {
|
|
|
18
18
|
} as const;
|
|
19
19
|
Object.setPrototypeOf(optspec, null);
|
|
20
20
|
|
|
21
|
-
export const media: MediaParser = lazy(() => validate(['![', '!{'],
|
|
21
|
+
export const media: MediaParser = lazy(() => validate(['![', '!{'], open(
|
|
22
22
|
'!',
|
|
23
23
|
constraint(State.media, false,
|
|
24
24
|
syntax(Syntax.media, 2, 10,
|
|
25
|
-
tails([
|
|
25
|
+
bind(verify(fmap(tails([
|
|
26
26
|
dup(surround(
|
|
27
27
|
'[',
|
|
28
28
|
some(union([unsafehtmlentity, bracket, txt]), ']', [[/^\\?\n/, 9]]),
|
|
29
29
|
']',
|
|
30
30
|
true)),
|
|
31
31
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
32
|
-
])
|
|
33
|
-
([as, bs]) => bs ? [[as.join('').trim() || as.join('')],
|
|
32
|
+
]),
|
|
33
|
+
([as, bs]) => bs ? [[as.join('').trim() || as.join('')], bs] : [[''], as]),
|
|
34
34
|
([[text]]) => text === '' || text.trim() !== ''),
|
|
35
35
|
([[text], params], rest, context) => {
|
|
36
36
|
assert(text === text.trim());
|
|
@@ -54,12 +54,13 @@ export const media: MediaParser = lazy(() => validate(['![', '!{'], bind(verify(
|
|
|
54
54
|
if (el.hasAttribute('aspect-ratio')) {
|
|
55
55
|
el.style.aspectRatio = el.getAttribute('aspect-ratio')!;
|
|
56
56
|
}
|
|
57
|
-
if (context.state! & State.link
|
|
57
|
+
if (context.state! & State.link) return [[el], rest];
|
|
58
|
+
if (cache && cache.tagName !== 'IMG') return creation(10, (..._) => [[el!], rest])('!', context);
|
|
58
59
|
return fmap(
|
|
59
|
-
|
|
60
|
+
unsafelink as MediaParser,
|
|
60
61
|
([link]) => [define(link, { target: '_blank' }, [el])])
|
|
61
62
|
(`{ ${INSECURE_URI}${params.join('')} }${rest}`, context);
|
|
62
|
-
})));
|
|
63
|
+
}))))));
|
|
63
64
|
|
|
64
65
|
const bracket: MediaParser.TextParser.BracketParser = lazy(() => creation(union([
|
|
65
66
|
surround(str('('), some(union([unsafehtmlentity, bracket, txt]), ')'), str(')'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
package/src/parser/inline.ts
CHANGED
|
@@ -34,7 +34,6 @@ export import MathParser = InlineParser.MathParser;
|
|
|
34
34
|
export import ExtensionParser = InlineParser.ExtensionParser;
|
|
35
35
|
export import RubyParser = InlineParser.RubyParser;
|
|
36
36
|
export import LinkParser = InlineParser.LinkParser;
|
|
37
|
-
export import TextLinkParser = InlineParser.TextLinkParser;
|
|
38
37
|
export import HTMLParser = InlineParser.HTMLParser;
|
|
39
38
|
export import InsertionParser = InlineParser.InsertionParser;
|
|
40
39
|
export import DeletionParser = InlineParser.DeletionParser;
|