feat(markdown): Add support for details tag#609
feat(markdown): Add support for details tag#609ArvinH wants to merge 3 commits intogitpoint:masterfrom
Conversation
6b0329b to
db4390e
Compare
machour
left a comment
There was a problem hiding this comment.
Wow, that's an awesome start @ArvinH!
I still need to pull down this PR and see if we can simplify and bullet proof childrendComponent construction, but this seems really promissing.
Left you some comments for things that needs fixing.
Markdown rendering is a quiet complicated stuff to work on. While it may work for you on the exact markdown sample you test on, it can break as soon as someone add a space in their markdown 😢
Could you try setting up some more markdown cases? Try using an image/list/code section as summary and see how your PR handles them.
Again, can't thank you enough for diving into this component! 👏 👏
| this.setState({ collapsed: !this.state.collapsed }); | ||
| } | ||
|
|
||
| renderTochableView() { |
| if (child.type === 'tag' && child.name === 'summary') { | ||
| const summaryChild = child.children[0] || {}; | ||
|
|
||
| summaryText = summaryChild.data || 'details'; |
There was a problem hiding this comment.
The default is redundant with summaryText declaration.
Also, summaryChild may need additional treatment (if it's an image for example). It needs to be rendered()
There was a problem hiding this comment.
I guess I was too hasty, didn't consider other cases of summaryChild. Thank you so much for your patient 😄
There was a problem hiding this comment.
No problems, I did make the same mistake quiet a few times before getting on pace :)
I'm available in gitter today if you need some help!
|
|
||
| detailsChildren.forEach((child, childIdx) => { | ||
| if (child.type === 'tag' && child.name === 'summary') { | ||
| const summaryChild = child.children[0] || {}; |
There was a problem hiding this comment.
from experience, I know that using .children[x] is bad. Imagine if the first child is a space for example.
You may want to use the onlyTagsChildren here.
There was a problem hiding this comment.
Yeah, I'm not familiar with markdown, I basically keep switching to http://astexplorer.net/ to check the AST parsing result :p
I didn't notice we may have space in first children 😭
Should use onlyTagsChildren here. 👍
| }, | ||
| details: (node, index, siblings, parent, defaultRenderer) => { | ||
| const detailsChildren = node.children || []; | ||
| const childrendComponent = []; |
There was a problem hiding this comment.
The variable name is unclear to me. What about hiddenChildren ?
| return ( | ||
| <ToggleView | ||
| TouchableView={collapse => { | ||
| const prefixNotation = collapse ? '▸' : '▾'; |
There was a problem hiding this comment.
Those little babies (▸ / ▾) need some style to be bigger.
prefix could be a simpler & better variable name
| const { TouchableView } = this.props; | ||
|
|
||
| if (TouchableView instanceof Function) { | ||
| return TouchableView(this.state.collapsed); |
There was a problem hiding this comment.
Really love what you did here ❤️
|
Paladin level 95:
top summary details
Summary as detail 😆nested summary details |
|
Hey @ArvinH, just checking on you to see if you're stuck on some technical difficulty for this PR. |
|
Yeah, I'm kind of busy these days, I'll come back this week! |
refactor(markdown): details tag support with arrow notation refactor(markdown): details tag support with image, nested summary feat(markdown): support code in summary refactor(markdown): defensive code & remove conosle refactor(markdown): neater way to construct details tag refactor(markdown): adjust prefix style
db4390e to
129e76e
Compare
| return undefined; | ||
| }, | ||
| details: (node, index, siblings, parent, defaultRenderer) => { | ||
| const tags = onlyTagsChildren(node); |
There was a problem hiding this comment.
Nice nice nice 🎉
Let's check that there are indeed two tags and that they are indeed summary and hidden.
Define them here with consts for later use
There was a problem hiding this comment.
hmm, I'm thinking how we should handle the case of no summary or no hidden tags in details tag.
May need a default summary and empty hidden for this case.
There was a problem hiding this comment.
This shouldn't really happen I think, but I'm ok with your suggestion
The goal is to avoid a crash on [1]
| details: (node, index, siblings, parent, defaultRenderer) => { | ||
| const tags = onlyTagsChildren(node); | ||
| const firstTag = tags[0] || {}; | ||
| const secondTag = tags[1] || {}; |
There was a problem hiding this comment.
@vitalkanev I was referring to these calls that were in the middle of the jsx
|
@ArvinH thank you so much for your work on this PR homie 🥇 |
machour
left a comment
There was a problem hiding this comment.
@ArvinH sorry for not getting back to you earlier, I was too busy :/
I tested this PR against #528 and it crashes with "Views nested in <Text> must have a height and width".
This is due to the hidden section containing a heading, which produces a <View>
And it made me realize that as we can include any kind of element in the hidden section, we will have this problem with blockquote, hr, and maybe some other tags.
I know this is outside the scope of this PR, and I'm unsure how to address those issues.
Maybe we need to completely change the way we produce those tags, measure them before rendering then set height/width everywhere to be safe.
@housseindjirdeh This was originally supposed to be part of 1.4 (to fix #636) but it turns out to be rather complicated and revealing of deep problems with our current markdown rendering. Are you okay to drop this feat/fix from 1.4?
| ); | ||
| }, | ||
| summary: (node, index, siblings, parent, defaultRenderer) => { | ||
| return <View>{defaultRenderer(node.children, parent)}</View>; |
There was a problem hiding this comment.
The <View> wrapper is not needed here
|
Sorry I was too busy these days, didn't have the chance to come back here. |
|
@ArvinH no worries, we all get busy from time to time :) I'm currently thinking of completely changing one's ground on markdown: We currently rely on Github to transform the markdown, and we're dealing with HTML. I'd like to get back to real markdown parsing, and extract this component into its own repo/lib (like gitpoint/react-native-markdown-view). Features:
I've been experimenting with this on my side, but nothing really working for now. I'd love it if you could join next week to dive with me in this :) (cc @gitpoint/maintainers for feedback) |
feat(markdown): Add support for details tag
Screenshots
More test cases in here:
Description
Add support for github
<details>markdown tag.Modify
ToggleViewcomponent for supporting state-based render