mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 21:01:31 +03:00
Merge pull request #737 from esteemapp/bugfix/621
fixed youtube link handle
This commit is contained in:
commit
f027bf9cc5
@ -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,177 +95,194 @@ export const markDown2Html = (input) => {
|
||||
return output;
|
||||
};
|
||||
|
||||
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 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) => {
|
||||
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 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) => {
|
||||
if (dTubeRegex.test(link)) {
|
||||
const dTubeMatch = link.match(dTubeRegex)[0];
|
||||
const execLink = dTubeRegex.exec(dTubeMatch);
|
||||
const handleATag = input =>
|
||||
input.replace(aTagRegex, link => {
|
||||
if (dTubeRegex.test(link)) {
|
||||
const dTubeMatch = link.match(dTubeRegex)[0];
|
||||
const execLink = dTubeRegex.exec(dTubeMatch);
|
||||
|
||||
if (execLink[2] && execLink[3]) {
|
||||
const embedLink = `https://emb.d.tube/#!/${execLink[2]}/${execLink[3]}`;
|
||||
if (execLink[2] && execLink[3]) {
|
||||
const embedLink = `https://emb.d.tube/#!/${execLink[2]}/${execLink[3]}`;
|
||||
|
||||
return iframeBody(embedLink);
|
||||
}
|
||||
if (dTubeMatch) {
|
||||
return iframeBody(dTubeMatch);
|
||||
}
|
||||
return link;
|
||||
}
|
||||
|
||||
if (imgRegex.test(link)) {
|
||||
const imgMatch = link.match(imgRegex)[0];
|
||||
|
||||
if (imgMatch) return `<a src="${imgMatch}">Image</a>`;
|
||||
}
|
||||
|
||||
return link;
|
||||
});
|
||||
|
||||
const handleHTag = input => input.replace(hTagRegex, tag => `<div>${tag}</div>`);
|
||||
|
||||
const handleMarkdownLink = input => input.replace(copiedPostRegex, (link) => {
|
||||
const postMatch = link.match(copiedPostRegex);
|
||||
|
||||
if (postMatch) {
|
||||
let tag = postMatch[1];
|
||||
|
||||
if (tag === '/busy.org') {
|
||||
tag = 'busy';
|
||||
}
|
||||
|
||||
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) => {
|
||||
if (link) {
|
||||
if (
|
||||
link
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.indexOf('https://steemitimages.com/0x0/') === 0
|
||||
|| imgRegex.test(link)
|
||||
) {
|
||||
const imageMatch = link.match(imgRegex);
|
||||
|
||||
if (imageMatch) {
|
||||
if (imageMatch[0].indexOf('.gif') > 0) {
|
||||
return gifBody(imageMatch[0]);
|
||||
}
|
||||
|
||||
if (imageMatch[0]) {
|
||||
return imageBody(imageMatch[0]);
|
||||
}
|
||||
} else if (link.trim().indexOf('ipfs.busy.org') > 0) {
|
||||
return imageBody(link);
|
||||
return iframeBody(embedLink);
|
||||
}
|
||||
if (dTubeMatch) {
|
||||
return iframeBody(dTubeMatch);
|
||||
}
|
||||
|
||||
return link;
|
||||
}
|
||||
if (link.trim().indexOf('ipfs.busy.org') > 0) {
|
||||
return imageBody(link);
|
||||
}
|
||||
|
||||
if (imgRegex.test(link)) {
|
||||
return imageBody(link);
|
||||
const imgMatch = link.match(imgRegex)[0];
|
||||
|
||||
if (imgMatch) return `<a src="${imgMatch}">Image</a>`;
|
||||
}
|
||||
}
|
||||
|
||||
return link;
|
||||
});
|
||||
return link;
|
||||
});
|
||||
|
||||
const changeMarkdownImage = input => input.replace(markdownImageRegex, (link) => {
|
||||
const markdownMatch = link.match(markdownImageRegex);
|
||||
if (markdownMatch[0]) {
|
||||
const firstMarkdownMatch = markdownMatch[0];
|
||||
const _link = firstMarkdownMatch.match(urlRegex)[0];
|
||||
const handleHTag = input => input.replace(hTagRegex, tag => `<div>${tag}</div>`);
|
||||
|
||||
return _link;
|
||||
}
|
||||
return link;
|
||||
});
|
||||
const handleMarkdownLink = input =>
|
||||
input.replace(copiedPostRegex, link => {
|
||||
const postMatch = link.match(copiedPostRegex);
|
||||
|
||||
const centerStyling = input => input.replace(
|
||||
centerRegex,
|
||||
() => '<center style="text-align: center; align-items: center; justify-content: center;">',
|
||||
);
|
||||
if (postMatch) {
|
||||
let tag = postMatch[1];
|
||||
|
||||
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];
|
||||
if (tag === '/busy.org') {
|
||||
tag = 'busy';
|
||||
}
|
||||
|
||||
return `<a class="markdown-post-link" href="${permlink}" data_tag={${tag}} data_author="${author}">/${permlink}</a>`;
|
||||
});
|
||||
const _permlink =
|
||||
postMatch[3].indexOf(')') > 0 ? postMatch[3].replace(')', '') : postMatch[3];
|
||||
|
||||
const handleImageTag = input => input.replace(imgTagRegex, (imgTag) => {
|
||||
const _imgTag = imgTag.trim();
|
||||
const match = _imgTag.match(imgRegex);
|
||||
return `<a class="markdown-post-link" href="${_permlink}" data_tag={${tag.trim()}} data_author="${postMatch[2].replace(
|
||||
'@',
|
||||
'',
|
||||
)}">/${_permlink}</a>`;
|
||||
}
|
||||
});
|
||||
|
||||
if (match && match[0]) {
|
||||
return match[0];
|
||||
}
|
||||
const handleLinks = input =>
|
||||
input.replace(linkRegex, link => {
|
||||
if (link) {
|
||||
if (
|
||||
link
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.indexOf('https://steemitimages.com/0x0/') === 0 ||
|
||||
imgRegex.test(link)
|
||||
) {
|
||||
const imageMatch = link.match(imgRegex);
|
||||
|
||||
return imgTag;
|
||||
});
|
||||
if (imageMatch) {
|
||||
if (imageMatch[0].indexOf('.gif') > 0) {
|
||||
return gifBody(imageMatch[0]);
|
||||
}
|
||||
|
||||
const createYoutubeIframe = input => input.replace(youTubeRegex, (link) => {
|
||||
const execVideo = youTubeRegex.exec(link);
|
||||
const match = link.match(youTubeRegex);
|
||||
if (imageMatch[0]) {
|
||||
return imageBody(imageMatch[0]);
|
||||
}
|
||||
} else if (link.trim().indexOf('ipfs.busy.org') > 0) {
|
||||
return imageBody(link);
|
||||
}
|
||||
|
||||
if (execVideo[1] && match) {
|
||||
const videoLink = execVideo[1];
|
||||
const embedLink = `https://www.youtube.com/embed/${videoLink}`;
|
||||
return link;
|
||||
}
|
||||
if (link.trim().indexOf('ipfs.busy.org') > 0) {
|
||||
return imageBody(link);
|
||||
}
|
||||
|
||||
if (imgRegex.test(link)) {
|
||||
return imageBody(link);
|
||||
}
|
||||
}
|
||||
|
||||
return link;
|
||||
});
|
||||
|
||||
const changeMarkdownImage = input =>
|
||||
input.replace(markdownImageRegex, link => {
|
||||
const markdownMatch = link.match(markdownImageRegex);
|
||||
if (markdownMatch[0]) {
|
||||
const firstMarkdownMatch = markdownMatch[0];
|
||||
const _link = firstMarkdownMatch.match(urlRegex)[0];
|
||||
|
||||
return _link;
|
||||
}
|
||||
return link;
|
||||
});
|
||||
|
||||
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 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 _imgTag = imgTag.trim();
|
||||
const match = _imgTag.match(imgRegex);
|
||||
|
||||
if (match && match[0]) {
|
||||
return match[0];
|
||||
}
|
||||
|
||||
return imgTag;
|
||||
});
|
||||
|
||||
const createYoutubeIframe = input =>
|
||||
input.replace(youTubeRegex, link => {
|
||||
if (link.indexOf(')') || link.indexOf('(')) {
|
||||
return link;
|
||||
}
|
||||
|
||||
const execVideo = youTubeRegex.exec(link);
|
||||
const match = link.match(youTubeRegex);
|
||||
|
||||
if (execVideo[1] && match) {
|
||||
const videoLink = execVideo[1];
|
||||
const embedLink = `https://www.youtube.com/embed/${videoLink}`;
|
||||
|
||||
return iframeBody(embedLink);
|
||||
}
|
||||
|
||||
return link;
|
||||
});
|
||||
|
||||
const handleIframe = input =>
|
||||
input.replace(iframeRegex, link => {
|
||||
const match = link.match(linkRegex);
|
||||
|
||||
if (match && match[0]) {
|
||||
return iframeBody(match[0]);
|
||||
}
|
||||
|
||||
return 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);
|
||||
}
|
||||
|
||||
return link;
|
||||
});
|
||||
|
||||
const handleIframe = input => input.replace(iframeRegex, (link) => {
|
||||
const match = link.match(linkRegex);
|
||||
|
||||
if (match && match[0]) {
|
||||
return iframeBody(match[0]);
|
||||
}
|
||||
|
||||
return 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;
|
||||
|
Loading…
Reference in New Issue
Block a user