update: link markdown parser

This commit is contained in:
yanmao 2022-01-07 14:53:37 +08:00
parent 66065ce7c2
commit c587b0997e
2 changed files with 6 additions and 6 deletions

View File

@ -41,7 +41,7 @@ export default class<
markdown =
this.options.markdown === undefined
? '\\[(.+?)\\]\\(([\\S]+?)\\)$'
? '\\[(.+?)\\]\\(s*([\\S]+?)\\s*\\)$'
: this.options.markdown;
init() {
@ -149,7 +149,7 @@ export default class<
const text = node.text();
if (!text) return;
const reg = /(\[(.+?)\]\(([\S]+?)\))/;
const reg = /(\[(.+?)\]\(\s*([\S]+?)\s*\))/;
const match = reg.exec(text);
return {
reg,
@ -188,7 +188,7 @@ export default class<
const url = match[3];
const inlineNode = $(`<${this.tagName} />`);
this.setAttributes(inlineNode, '_blank', url);
this.setAttributes(inlineNode, '_blank', (url || '').trim());
inlineNode.html(!!text ? text : url);
newText += inlineNode.get<Element>()?.outerHTML;

View File

@ -43,7 +43,7 @@ export default class<T extends LinkOptions> extends InlinePlugin<T> {
markdown =
this.options.markdown === undefined
? '\\[(.+?)\\]\\(([\\S]+?)\\)$'
? '\\[(.+?)\\]\\(\\s*([\\S]+?)\\s*\\)$'
: this.options.markdown;
init() {
@ -151,7 +151,7 @@ export default class<T extends LinkOptions> extends InlinePlugin<T> {
const text = node.text();
if (!text) return;
const reg = /(\[(.+?)\]\(([\S]+?)\))/;
const reg = /(\[(.+?)\]\(\s*([\S]+?)\s*\))/;
const match = reg.exec(text);
return {
reg,
@ -190,7 +190,7 @@ export default class<T extends LinkOptions> extends InlinePlugin<T> {
const url = match[3];
const inlineNode = $(`<${this.tagName} />`);
this.setAttributes(inlineNode, '_blank', url);
this.setAttributes(inlineNode, '_blank', (url || '').trim());
inlineNode.html(!!text ? text : url);
newText += inlineNode.get<Element>()?.outerHTML;