New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse HTML in news content #2
Comments
Hello Kennydee, I understand what you're trying to say. I will try to implement the functionality within comment cells and update the code. I will comment back here once I am done. |
Great :) thanks for your help |
Hello again, I have updated the code. Here is the link to the commit: 4a43178 You can see the changes I have made to comment cell in order to parse the code anchors. Here is a screenshot of how it looks now: http://i.imgur.com/kO1azLk.png |
First, thank you for your works, it help a lot. This is a good start, but i think, you're missing one point : your implementation if i'm right, work only for one What do you think ? i also will try something based on your work. Thanks you again |
Hello, I was thinking the same thing. Maybe there should be a view tag in react-native for parsing html code all together. Then a user can simply use the view like: |
Hmm maybe. The goal with React, i think, is to be able to do whatever you want after parsing :
I will digg on that and come back to you if i've got some ideas. Thanks |
I see, sounds fair. Okay. |
I think i found a solution, by generating an array with React Component (for parse element) or string for normal text. Here is the example (from my code, not the yours here sorry). Not really clean for now, but a good start : _parseContent: function() {
var content =this.props.news.content;
//First, make a big string with all the parse replace by @@<parse>|<text>@@
content = content.replace(/<b>(.*?)<\/b>/gmi, "@@bold|$1@@");
content = content.replace(/<center>(.*?)<\/center>/gmi, "@@center|$1@@");
content = content.replace(/<i>(.*?)<\/i>/gmi, "@@italic|$1@@");
// split the string and treat manually each line, and find the appropriate tag
return content.split('@@').map((text) => {
if(text.indexOf('|') > -1) {
var textWithoutTag = text.replace(/^(.*)\|/, '');
switch(text.split('|')[0]) {
case "bold":
return <Text style={styles.bold}>{textWithoutTag}</Text>;
break;
case "center":
return <Text style={styles.center}>{textWithoutTag}</Text>;
break;
case "italic":
return <Text style={styles.italic}>{textWithoutTag}</Text>;
default:
return text;
}
}
else {
return text;
}
});
}, and in the
WYT ? Edit : i think it is far from perfect and probably don't work with multiple embedded tag like |
This is awesome! Great start, I'm working on the HTMLCode element right now. |
Hello again, I have created a new component for such functionality, have a look: Let me know if this helps. |
Whaou ! Really nice ! I think you ended in the same problem. How do you deal with Is it possible to replace But the approach you have is excellent ! and a really good start ! It may even be enough for some use cases |
Also just seen this which sounds interesting too : https://gist.github.com/jsdf/7f983f2cd955fd75d6cc |
I'm still working on parsing nested tags like |
ParseHTML (https://github.com/iSimar/ParseHTML-React-Native) now supports nested tags. |
This is what I have implemented for rendering comment text in comment cells:
|
I have fixed the |
Hi,
Thanks for the great work on this HN RN apps :)
I look at your code to know how you deal with one problem i faced with RN, and i finally see that you didn't face it right now : If you look at the "Dot matrix printer playing "eye of the tiger" [video]" news, you will see html
<pre><code>
in the middle of the content.Did you have any idea, to transform those html code, in
<Text style='pre'>
or in other react componants like a<CodeHighlight>
for example ? This is not just string replacement but something more difficult by replacing some part of the text by React Components.It's difficult to explain why the problem seems difficult to resolve, but i hope you will understand me.
Thanks for sharing :)
The text was updated successfully, but these errors were encountered: