Merge pull request #737 from esteemapp/bugfix/621

fixed youtube link handle
This commit is contained in:
uğur erdal 2019-04-07 13:58:08 +03:00 committed by GitHub
commit 029a4ff01f

View File

@ -24,7 +24,7 @@ const imgTagRegex = /(<img[^>]*>)/g;
const iframeRegex = /(?:<iframe[^>]*)(?:(?:\/>)|(?:>.*?<\/iframe>))/g;
const hTagRegex = /(<h([1-6])>([^<]*)<\/h([1-6])>)/g;
export const markDown2Html = (input) => {
export const markDown2Html = input => {
if (!input) {
return '';
}
@ -95,22 +95,25 @@ export const markDown2Html = (input) => {
return output;
};
const replaceAuthorNames = input => input.replace(authorNameRegex, (match, preceeding1, preceeding2, user) => {
const replaceAuthorNames = input =>
input.replace(authorNameRegex, (match, preceeding1, preceeding2, user) => {
const userLower = user.toLowerCase();
const preceedings = (preceeding1 || '') + (preceeding2 || '');
return `${preceedings}<a class="markdown-author-link" href="${userLower}" data-author="${userLower}"> @${user}</a>`;
});
});
const replaceTags = input => input.replace(tagsRegex, (tag) => {
const replaceTags = input =>
input.replace(tagsRegex, tag => {
if (/#[\d]+$/.test(tag)) return tag;
const preceding = /^\s|>/.test(tag) ? tag[0] : '';
tag = tag.replace('>', '');
const tag2 = tag.trim().substring(1);
const tagLower = tag2.toLowerCase();
return `${preceding}<a class="markdown-tag-link" href="${tagLower}" data-tag="${tagLower}">${tag.trim()}</a>`;
});
});
const handleATag = input => input.replace(aTagRegex, (link) => {
const handleATag = input =>
input.replace(aTagRegex, link => {
if (dTubeRegex.test(link)) {
const dTubeMatch = link.match(dTubeRegex)[0];
const execLink = dTubeRegex.exec(dTubeMatch);
@ -133,11 +136,12 @@ const handleATag = input => input.replace(aTagRegex, (link) => {
}
return link;
});
});
const handleHTag = input => input.replace(hTagRegex, tag => `<div>${tag}</div>`);
const handleMarkdownLink = input => input.replace(copiedPostRegex, (link) => {
const handleMarkdownLink = input =>
input.replace(copiedPostRegex, link => {
const postMatch = link.match(copiedPostRegex);
if (postMatch) {
@ -147,23 +151,25 @@ const handleMarkdownLink = input => input.replace(copiedPostRegex, (link) => {
tag = 'busy';
}
const _permlink = postMatch[3].indexOf(')') > 0 ? postMatch[3].replace(')', '') : postMatch[3];
const _permlink =
postMatch[3].indexOf(')') > 0 ? postMatch[3].replace(')', '') : postMatch[3];
return `<a class="markdown-post-link" href="${_permlink}" data_tag={${tag.trim()}} data_author="${postMatch[2].replace(
'@',
'',
)}">/${_permlink}</a>`;
}
});
});
const handleLinks = input => input.replace(linkRegex, (link) => {
const handleLinks = input =>
input.replace(linkRegex, link => {
if (link) {
if (
link
.toLowerCase()
.trim()
.indexOf('https://steemitimages.com/0x0/') === 0
|| imgRegex.test(link)
.indexOf('https://steemitimages.com/0x0/') === 0 ||
imgRegex.test(link)
) {
const imageMatch = link.match(imgRegex);
@ -191,9 +197,10 @@ const handleLinks = input => input.replace(linkRegex, (link) => {
}
return link;
});
});
const changeMarkdownImage = input => input.replace(markdownImageRegex, (link) => {
const changeMarkdownImage = input =>
input.replace(markdownImageRegex, link => {
const markdownMatch = link.match(markdownImageRegex);
if (markdownMatch[0]) {
const firstMarkdownMatch = markdownMatch[0];
@ -202,23 +209,26 @@ const changeMarkdownImage = input => input.replace(markdownImageRegex, (link) =>
return _link;
}
return link;
});
});
const centerStyling = input => input.replace(
const centerStyling = input =>
input.replace(
centerRegex,
() => '<center style="text-align: center; align-items: center; justify-content: center;">',
);
);
const steemitUrlHandle = input => input.replace(postRegex, (link) => {
const steemitUrlHandle = input =>
input.replace(postRegex, link => {
const postMatch = link.match(postRegex);
const tag = postMatch[2];
const author = postMatch[3].replace('@', '');
const permlink = postMatch[4];
return `<a class="markdown-post-link" href="${permlink}" data_tag={${tag}} data_author="${author}">/${permlink}</a>`;
});
});
const handleImageTag = input => input.replace(imgTagRegex, (imgTag) => {
const handleImageTag = input =>
input.replace(imgTagRegex, imgTag => {
const _imgTag = imgTag.trim();
const match = _imgTag.match(imgRegex);
@ -227,9 +237,14 @@ const handleImageTag = input => input.replace(imgTagRegex, (imgTag) => {
}
return imgTag;
});
});
const createYoutubeIframe = input =>
input.replace(youTubeRegex, link => {
if (link.indexOf(')') || link.indexOf('(')) {
return link;
}
const createYoutubeIframe = input => input.replace(youTubeRegex, (link) => {
const execVideo = youTubeRegex.exec(link);
const match = link.match(youTubeRegex);
@ -241,9 +256,10 @@ const createYoutubeIframe = input => input.replace(youTubeRegex, (link) => {
}
return link;
});
});
const handleIframe = input => input.replace(iframeRegex, (link) => {
const handleIframe = input =>
input.replace(iframeRegex, link => {
const match = link.match(linkRegex);
if (match && match[0]) {
@ -251,21 +267,22 @@ const handleIframe = input => input.replace(iframeRegex, (link) => {
}
return link;
});
});
const createVimeoIframe = input => input.replace(vimeoRegex, (link) => {
const createVimeoIframe = input =>
input.replace(vimeoRegex, link => {
const execLink = vimeoRegex.exec(link);
const embedLink = `https://player.vimeo.com/video/${execLink[3]}`;
return iframeBody(embedLink);
});
const handleImageLink = input => input.replace(imgRegex, link => imageBody(link));
});
const iframeBody = link => `<iframe frameborder='0' allowfullscreen src='${link}'></iframe>`;
const imageBody = link => `<center style="text-align: center; align-items: center; justify-content: center;"><img src="${`https://steemitimages.com/600x0/${link}`}" /></center>`;
const imageBody = link =>
`<center style="text-align: center; align-items: center; justify-content: center;"><img src="${`https://steemitimages.com/600x0/${link}`}" /></center>`;
const gifBody = link => `<img src="${`https://steemitimages.com/0x0/${link}`}" />`;
const handleImageLink = input => input.replace(imgRegex, link => imageBody(link));
// const handleCodeTag = input => input.replace(codeTagRegex, (tag) => {
// const stringsRegex = /(?<=>)(.*)(?=<)/g;