Skip to content
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

Add "id" to headings #709

Merged
merged 3 commits into from
Oct 9, 2018
Merged

Conversation

andresmgot
Copy link
Contributor

Fixes #702

Add the "id" property to the headings when parsing markdown. The approach to do that is specified here:
remarkjs/react-markdown#69

The logic to transform the heading text into a link is the same than GitHub: https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/toc_filter.rb#L42

: React.Children.toArray(child.props.children).reduce(flatten, text);
}

function HeadingRenderer(props: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I'm not a huge fan of having a Component inline in another component, even though this is small one. @Angelmmiguel what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @prydonius. If the component is specific to another one, I usually keep them in the same folder:

CommonComponent
  - CommonComponent.test.tsx
  - CommonComponent.tsx
  - CommonComponent.css
  - SpecificComponent
    - SpecificComponent.test.tsx
    - SpecificComponent.tsx
    - SpecificComponent.css

@@ -13,6 +13,23 @@ interface IChartReadmeProps {
version: string;
}

// Code from https://github.com/rexxars/react-markdown/issues/69
function flatten(text: string, child: any): any {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we keep this function in this class, we should probably name it better, or instead just have it as an anonymous function in the .reduce

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved it to a different component file. I prefer to leave it as it is to maintain fidelity to the linked issue.

Copy link
Contributor

@Angelmmiguel Angelmmiguel left a comment

Choose a reason for hiding this comment

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

The code LGTM in general, but we must keep 1 component per file :)

: React.Children.toArray(child.props.children).reduce(flatten, text);
}

function HeadingRenderer(props: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @prydonius. If the component is specific to another one, I usually keep them in the same folder:

CommonComponent
  - CommonComponent.test.tsx
  - CommonComponent.tsx
  - CommonComponent.css
  - SpecificComponent
    - SpecificComponent.test.tsx
    - SpecificComponent.tsx
    - SpecificComponent.css

Copy link
Contributor

@Angelmmiguel Angelmmiguel left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks

@andresmgot andresmgot merged commit 74f3fa6 into vmware-tanzu:master Oct 9, 2018
: React.Children.toArray(child.props.children).reduce(flatten, text);
}

const HeadingRenderer: React.SFC<{}> = (props: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we have written some tests for this btw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't add a test for this because it's only meant to be used with the ReactMarkdown component so I added the test there.

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

Successfully merging this pull request may close these issues.

3 participants