-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,13 @@ const quotedEmailToggleStyle = { | |
marginTop: 3, | ||
}; | ||
|
||
const detailsSummaryPrefixStyle = { | ||
alignSelf: 'flex-start', | ||
lineHeight: normalize(20), | ||
fontSize: normalize(20), | ||
marginRight: 3, | ||
}; | ||
|
||
const styleSheet = StyleSheet.create(styles); | ||
|
||
const { width } = Dimensions.get('window'); | ||
|
@@ -197,6 +204,8 @@ export class GithubHtmlView extends Component { | |
/<span class="email-hidden-toggle"><a href="#">…<\/a><\/span>/g, | ||
'' | ||
) | ||
.replace(/<\/summary>/g, '</summary><hidden>') | ||
.replace(/<\/details>/g, '</hidden></details>') | ||
// Remove links & spans around images | ||
.replace(/<a[^>]+><img([^>]+)><\/a>/g, '<img$1>') | ||
.replace(/<span[^>]*><img([^>]+)><\/span>/g, '<img$1>') | ||
|
@@ -243,7 +252,7 @@ export class GithubHtmlView extends Component { | |
<View key={index}>{defaultRenderer(node.children, node)}</View> | ||
), | ||
code: (node, index, siblings, parent, defaultRenderer) => { | ||
if (parent.name === 'pre') { | ||
if (parent && parent.name === 'pre') { | ||
return ( | ||
<SyntaxHighlighter | ||
key={index} | ||
|
@@ -294,6 +303,39 @@ export class GithubHtmlView extends Component { | |
|
||
return undefined; | ||
}, | ||
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 commentThe 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 |
||
const summaryTag = | ||
firstTag.name === 'summary' | ||
? firstTag | ||
: { type: 'text', data: 'details' }; | ||
const hiddenTag = secondTag.name === 'hidden' ? secondTag : {}; | ||
|
||
return ( | ||
<ToggleView | ||
TouchableView={collapse => { | ||
const prefix = collapse ? '▸' : '▾'; | ||
|
||
return [ | ||
<Text style={detailsSummaryPrefixStyle}> {prefix}</Text>, | ||
defaultRenderer([summaryTag], node), | ||
]; | ||
}} | ||
TouchableStyle={{ | ||
flexDirection: 'row', | ||
justifyContent: 'flex-start', | ||
alignItems: 'center', | ||
}} | ||
> | ||
{defaultRenderer([hiddenTag], node)} | ||
</ToggleView> | ||
); | ||
}, | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
}, | ||
img: (node, index, siblings, parent, defaultRenderer) => { | ||
if (hasAncestor(node, ['ol', 'ul', 'span'])) { | ||
return ( | ||
|
@@ -385,7 +427,7 @@ export class GithubHtmlView extends Component { | |
</Text> | ||
); | ||
}, | ||
}; | ||
}; // end of renders object | ||
|
||
if (_node.type === 'text') { | ||
if (_node.data === '\n') { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 nohidden
tags indetails
tag.May need a default
summary
and emptyhidden
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?