-
Notifications
You must be signed in to change notification settings - Fork 783
feat(markdown): Add support for details tag #609
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
Conversation
6b0329b
to
db4390e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! 👏 👏
@@ -24,11 +24,21 @@ export class ToggleView extends Component { | |||
this.setState({ collapsed: !this.state.collapsed }); | |||
} | |||
|
|||
renderTochableView() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Touchable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, typo.
if (child.type === 'tag' && child.name === 'summary') { | ||
const summaryChild = child.children[0] || {}; | ||
|
||
summaryText = summaryChild.data || 'details'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. 👍
@@ -290,6 +297,48 @@ export class GithubHtmlView extends Component { | |||
|
|||
return undefined; | |||
}, | |||
details: (node, index, siblings, parent, defaultRenderer) => { | |||
const detailsChildren = node.children || []; | |||
const childrendComponent = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name is unclear to me. What about hiddenChildren
?
return ( | ||
<ToggleView | ||
TouchableView={collapse => { | ||
const prefixNotation = collapse ? '▸' : '▾'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -294,6 +303,32 @@ export class GithubHtmlView extends Component { | |||
|
|||
return undefined; | |||
}, | |||
details: (node, index, siblings, parent, defaultRenderer) => { | |||
const tags = onlyTagsChildren(node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't really happen I think, but I'm ok with your suggestion
The goal is to avoid a crash on [1]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What [1]
means?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 🥇 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
ToggleView
component for supporting state-based render