Minor improvements to link markdown handling [#54]

This commit is contained in:
David Evans 2018-05-07 01:00:17 +01:00
parent 3e4110193a
commit 4d4b22aa91
5 changed files with 55 additions and 10 deletions

View File

@ -4163,6 +4163,10 @@
return pattern;
}
/* eslint-disable no-control-regex */ // Removing control characters is the aim
const CONTROL_CHARS$1 = /[\x00-\x08\x0E-\x1F]/g;
/* eslint-enable no-control-regex */
const STYLES = [
{
attrs: {'font-style': 'italic'},
@ -4225,9 +4229,12 @@
begin: {matcher: /<highlight>/g, skip: 0},
end: {matcher: /<\/highlight>/g, skip: 0},
}, {
all: {matcher: /\[([^\]]+)\]\(([^)]+)\)/g, skip: 0},
attrs: (m) => ({'href': m[2], 'text-decoration': 'underline'}),
text: (m) => m[1],
all: {matcher: /\[([^\]]+)\]\(([^)]+?)(?: "([^"]+)")?\)/g, skip: 0},
attrs: (m) => ({
'href': m[2].replace(CONTROL_CHARS$1, ''),
'text-decoration': 'underline',
}),
text: (m) => m[1].replace(CONTROL_CHARS$1, ''),
},
];

File diff suppressed because one or more lines are too long

View File

@ -4163,6 +4163,10 @@
return pattern;
}
/* eslint-disable no-control-regex */ // Removing control characters is the aim
const CONTROL_CHARS$1 = /[\x00-\x08\x0E-\x1F]/g;
/* eslint-enable no-control-regex */
const STYLES = [
{
attrs: {'font-style': 'italic'},
@ -4225,9 +4229,12 @@
begin: {matcher: /<highlight>/g, skip: 0},
end: {matcher: /<\/highlight>/g, skip: 0},
}, {
all: {matcher: /\[([^\]]+)\]\(([^)]+)\)/g, skip: 0},
attrs: (m) => ({'href': m[2], 'text-decoration': 'underline'}),
text: (m) => m[1],
all: {matcher: /\[([^\]]+)\]\(([^)]+?)(?: "([^"]+)")?\)/g, skip: 0},
attrs: (m) => ({
'href': m[2].replace(CONTROL_CHARS$1, ''),
'text-decoration': 'underline',
}),
text: (m) => m[1].replace(CONTROL_CHARS$1, ''),
},
];

View File

@ -1,3 +1,7 @@
/* eslint-disable no-control-regex */ // Removing control characters is the aim
const CONTROL_CHARS = /[\x00-\x08\x0E-\x1F]/g;
/* eslint-enable no-control-regex */
const STYLES = [
{
attrs: {'font-style': 'italic'},
@ -60,9 +64,12 @@ const STYLES = [
begin: {matcher: /<highlight>/g, skip: 0},
end: {matcher: /<\/highlight>/g, skip: 0},
}, {
all: {matcher: /\[([^\]]+)\]\(([^)]+)\)/g, skip: 0},
attrs: (m) => ({'href': m[2], 'text-decoration': 'underline'}),
text: (m) => m[1],
all: {matcher: /\[([^\]]+)\]\(([^)]+?)(?: "([^"]+)")?\)/g, skip: 0},
attrs: (m) => ({
'href': m[2].replace(CONTROL_CHARS, ''),
'text-decoration': 'underline',
}),
text: (m) => m[1].replace(CONTROL_CHARS, ''),
},
];

View File

@ -215,6 +215,30 @@ describe('Markdown Parser', () => {
]]);
});
it('silently ignores link titles', () => {
// SVG has no concept of titles, so these serve no purpose
const formatted = parser('a [b](c "d") e');
expect(formatted).toEqual([[
{attrs: null, text: 'a '},
{attrs: {'href': 'c', 'text-decoration': 'underline'}, text: 'b'},
{attrs: null, text: ' e'},
]]);
});
it('removes escapes from link text and destination', () => {
// SVG has no concept of titles, so these serve no purpose
const formatted = parser('a [b\u001Bc](d\u001Be) f');
expect(formatted).toEqual([[
{attrs: null, text: 'a '},
{attrs: {'href': 'de', 'text-decoration': 'underline'}, text: 'bc'},
{attrs: null, text: ' f'},
]]);
});
it('allows dots around monospace styling', () => {
const formatted = parser('a.`b`.c');