Fixed Markdown links when SiteURL isn't configured (#1650)

This commit is contained in:
Harrison Healey 2018-05-03 09:08:36 -04:00 committed by Saturnino Abril
parent b2b554d40c
commit 29d015bd32

View file

@ -43,23 +43,28 @@ export default class MarkdownLink extends PureComponent {
return;
}
const pattern = new RegExp('^' + escapeRegex(serverURL) + '\\/([^\\/]+)\\/pl\\/(\\w+)');
const sitePattern = new RegExp('^' + escapeRegex(siteURL) + '\\/([^\\/]+)\\/pl\\/(\\w+)');
const match = url.match(pattern) || url.match(sitePattern);
const match = this.matchPermalink(url, serverURL) || this.matchPermalink(url, siteURL);
if (!match) {
if (match) {
const teamName = match[1];
const postId = match[2];
onPermalinkPress(postId, teamName);
} else {
Linking.canOpenURL(url).then((supported) => {
if (supported) {
Linking.openURL(url);
}
});
return;
}
});
matchPermalink = (link, rootURL) => {
if (!rootURL) {
return null;
}
const teamName = match[1];
const postId = match[2];
onPermalinkPress(postId, teamName);
});
return new RegExp('^' + escapeRegex(rootURL) + '\\/([^\\/]+)\\/pl\\/(\\w+)').exec(link);
}
parseLinkLiteral = (literal) => {
let nextLiteral = literal;