Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

ArvinH
Copy link

@ArvinH ArvinH commented Oct 30, 2017

feat(markdown): Add support for details tag

Question Response
Version? v1.4.0
Devices tested? iPhone 6
Bug fix? no
New feature? yes
Includes tests? no
All Tests pass? yes
Related ticket? #528

Screenshots

Before After
before  after

More test cases in here:

demo

Description

Add support for github <details> markdown tag.
Modify ToggleView component for supporting state-based render

@ArvinH ArvinH force-pushed the feat-markupd-details branch from 6b0329b to db4390e Compare October 30, 2017 13:34
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 38.809% when pulling db4390e on ArvinH:feat-markupd-details into 753f60c on gitpoint:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 38.809% when pulling db4390e on ArvinH:feat-markupd-details into 753f60c on gitpoint:master.

Copy link
Member

@machour machour left a 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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Touchable

Copy link
Author

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';
Copy link
Member

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()

Copy link
Author

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 😄

Copy link
Member

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] || {};
Copy link
Member

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.

Copy link
Author

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 = [];
Copy link
Member

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 ? '▸' : '▾';
Copy link
Member

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);
Copy link
Member

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 ❤️

@ArvinH
Copy link
Author

ArvinH commented Oct 31, 2017

Fot test:

<code> in summary:

console.log('test'); try something for summary

<image> in summary:

@ArvinH try something for summary

<li> in summary:

  • test 1
  • test2
try something for summary

@machour
Copy link
Member

machour commented Oct 31, 2017

Paladin level 95:

Summary as detail 😆 nested summary details
top summary details

@machour
Copy link
Member

machour commented Nov 6, 2017

Hey @ArvinH, just checking on you to see if you're stuck on some technical difficulty for this PR.
No rush if you're busy with something else!

@ArvinH
Copy link
Author

ArvinH commented Nov 6, 2017

Yeah, I'm kind of busy these days, I'll come back this week!
And I actually had some progress on this one but still looking for a better way to organize my code.

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
@ArvinH ArvinH force-pushed the feat-markupd-details branch from db4390e to 129e76e Compare November 11, 2017 09:42
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 39.849% when pulling 129e76e on ArvinH:feat-markupd-details into 05c386e on gitpoint:master.

@@ -294,6 +303,32 @@ export class GithubHtmlView extends Component {

return undefined;
},
details: (node, index, siblings, parent, defaultRenderer) => {
const tags = onlyTagsChildren(node);
Copy link
Member

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

Copy link
Author

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.

Copy link
Member

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]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What [1] means?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 39.599% when pulling 567980e on ArvinH:feat-markupd-details into 05c386e on gitpoint:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 39.549% when pulling 35b7241 on ArvinH:feat-markupd-details into 05c386e on gitpoint:master.

details: (node, index, siblings, parent, defaultRenderer) => {
const tags = onlyTagsChildren(node);
const firstTag = tags[0] || {};
const secondTag = tags[1] || {};
Copy link
Member

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

@machour machour dismissed their stale review November 11, 2017 17:22

All remarks have been handled

@machour
Copy link
Member

machour commented Nov 11, 2017

@ArvinH thank you so much for your work on this PR homie 🥇
I'll give it a thorough review on Android and iOS as soon as I can

Copy link
Member

@machour machour left a 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>;
Copy link
Member

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

@ArvinH
Copy link
Author

ArvinH commented Dec 7, 2017

Sorry I was too busy these days, didn't have the chance to come back here.
Anyway, I'll have some spare time next week and I guess I'll have time to refactor this and discuss with you on gitter 😎

@machour
Copy link
Member

machour commented Dec 7, 2017

@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.
This is somehow a bad idea, because if Github changes anything at some point, the app can break.
We're also somehow crippled by react-native-htmlview.

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:

  • Use markdown-it for parsing
  • Ditch react-native-htmlview in favor of our own renderer, built on top of htmlparser2
  • Support Github markdown in priority, but also other flavours (bitbucket, gitlab, etc..)
  • Be GitPoint independant
  • Tests, Tests, Tests, Tests

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)

@chinesedfan
Copy link
Member

As #819 was merged, I will close this one. Thanks for @ArvinH's efforts all the same!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants