fix package issue with absolute links

This commit is contained in:
Joao Moreno 2017-06-23 11:14:48 +02:00
parent 7cf67ddb52
commit 132c7799e5

View file

@ -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})`;
} }