Skip to content

Commit

Permalink
fix(plugins/plugin-client-common): Markdown can fail for headings wit…
Browse files Browse the repository at this point in the history
…h nested links

Fixes #4468
  • Loading branch information
starpit committed May 5, 2020
1 parent b0fcd3e commit 995b129
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions plugins/plugin-client-common/src/components/Content/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,29 @@ export default class Markdown extends React.PureComponent<Props> {
</CodeSnippet>
),
heading: props => {
const anchor =
!props.children || !props.children[0].props
? undefined
: this.anchorFrom(props.children[0].props.value.toLowerCase().replace(/ /g, '-'))
const valueChild =
props.children && props.children.length === 1
? props.children[0]
: props.children.find(_ => _.props.value)
const anchor = !valueChild
? undefined
: this.anchorFrom(valueChild.props.value.toLowerCase().replace(/ /g, '-'))
return React.createElement(
`h${props.level}`,
Object.assign({}, props, { 'data-markdown-anchor': anchor }),
props.children
)
},
image: props => {
const isLocal = !/^http/i.test(props.src)
if (isLocal && this.props.fullpath) {
const absoluteSrc = join(dirname(this.props.fullpath), props.src)
const relativeToCWD = relative(process.cwd() || process.env.PWD, absoluteSrc)
return <img src={relativeToCWD} />
} else {
return <img {...props} />
}
},
list: props => {
return React.createElement(
props.ordered ? OrderedList : UnorderedList,
Expand Down

0 comments on commit 995b129

Please sign in to comment.