mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-24 08:55:14 +03:00
created post url handle
This commit is contained in:
parent
33ddbf388e
commit
4288c2c971
@ -23,10 +23,14 @@ class PostBody extends Component {
|
||||
// Component Functions
|
||||
|
||||
_handleOnLinkPress = (evt, href, hrefatr) => {
|
||||
const { handleOnUserPress } = this.props;
|
||||
const { handleOnUserPress, handleOnPostPress } = this.props;
|
||||
|
||||
if (hrefatr.class === 'markdown-author-link') {
|
||||
!handleOnUserPress ? this._handleOnUserPress(href) : handleOnUserPress(href);
|
||||
} else if (hrefatr.class === 'markdown-post-link') {
|
||||
!handleOnPostPress
|
||||
? this._handleOnPostPress(href, hrefatr.data_author)
|
||||
: handleOnPostPress(href);
|
||||
} else {
|
||||
Linking.canOpenURL(href).then((supported) => {
|
||||
if (supported) {
|
||||
@ -38,6 +42,19 @@ class PostBody extends Component {
|
||||
}
|
||||
};
|
||||
|
||||
_handleOnPostPress = (permlink, author) => {
|
||||
const { navigation } = this.props;
|
||||
|
||||
navigation.navigate({
|
||||
routeName: ROUTES.SCREENS.POST,
|
||||
params: {
|
||||
author,
|
||||
permlink,
|
||||
},
|
||||
key: permlink,
|
||||
});
|
||||
};
|
||||
|
||||
_handleOnUserPress = (username) => {
|
||||
const { navigation } = this.props;
|
||||
|
||||
|
@ -13,6 +13,7 @@ const dTubeRegex = /(https?:\/\/d.tube.#!\/v\/)(\w+)\/(\w+)/g;
|
||||
const authorNameRegex = /(^|[^a-zA-Z0-9_!#$%&*@@\/]|(^|[^a-zA-Z0-9_+~.-\/]))[@@]([a-z][-\.a-z\d]+[a-z\d])/gi;
|
||||
const tagsRegex = /(^|\s|>)(#[-a-z\d]+)/gi;
|
||||
const centerRegex = /(<center>)/g;
|
||||
const steemitRegex = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[steemit]+[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/gm;
|
||||
|
||||
export const markDown2Html = (input) => {
|
||||
if (!input) {
|
||||
@ -60,6 +61,10 @@ export const markDown2Html = (input) => {
|
||||
output = centerStyling(output);
|
||||
}
|
||||
|
||||
if (postRegex.test(output)) {
|
||||
output = steemitUrlHandle(output);
|
||||
}
|
||||
|
||||
output = md.render(output);
|
||||
|
||||
return output;
|
||||
@ -92,6 +97,15 @@ const createCenterImage = input => input.replace(imgCenterRegex, (link) => {
|
||||
return `><img data-href="${_link}" src="${_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 createImage = input => input.replace(onlyImageLinkRegex, link => `<img data-href="${link}" src="${link}">`);
|
||||
|
||||
const createFromDoubleImageLink = input => input.replace(onlyImageDoubleLinkRegex, (link) => {
|
||||
|
Loading…
Reference in New Issue
Block a user