fix package issue with absolute links
This commit is contained in:
parent
7cf67ddb52
commit
132c7799e5
1 changed files with 7 additions and 2 deletions
|
@ -320,15 +320,20 @@ export class MarkdownProcessor extends BaseProcessor {
|
||||||
|
|
||||||
const markdownPathRegex = /(!?)\[([^\]\[]+|!\[[^\]\[]+]\([^\)]+\))\]\(([^\)]+)\)/g;
|
const markdownPathRegex = /(!?)\[([^\]\[]+|!\[[^\]\[]+]\([^\)]+\))\]\(([^\)]+)\)/g;
|
||||||
const urlReplace = (all, isImage, title, link) => {
|
const urlReplace = (all, isImage, title, link) => {
|
||||||
|
const isLinkRelative = !/^\w+:\/\//.test(link) && link[0] !== '#';
|
||||||
|
|
||||||
if (!this.baseContentUrl && !this.baseImagesUrl) {
|
if (!this.baseContentUrl && !this.baseImagesUrl) {
|
||||||
const asset = isImage ? 'image' : 'link';
|
const asset = isImage ? 'image' : 'link';
|
||||||
throw new Error(`Couldn't detect the repository where this extension is published. The ${asset} '${link}' will be broken in ${this.name}. Please provide the repository URL in package.json or use the --baseContentUrl and --baseImagesUrl options.`);
|
|
||||||
|
if (isLinkRelative) {
|
||||||
|
throw new Error(`Couldn't detect the repository where this extension is published. The ${asset} '${link}' will be broken in ${this.name}. Please provide the repository URL in package.json or use the --baseContentUrl and --baseImagesUrl options.`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
title = title.replace(markdownPathRegex, urlReplace);
|
title = title.replace(markdownPathRegex, urlReplace);
|
||||||
const prefix = isImage ? this.baseImagesUrl : this.baseContentUrl;
|
const prefix = isImage ? this.baseImagesUrl : this.baseContentUrl;
|
||||||
|
|
||||||
if (!prefix || /^\w+:\/\//.test(link) || link[0] === '#') {
|
if (!prefix || !isLinkRelative) {
|
||||||
return `${isImage}[${title}](${link})`;
|
return `${isImage}[${title}](${link})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue