-
Notifications
You must be signed in to change notification settings - Fork 15
feat: mdx TOC #883
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
feat: mdx TOC #883
Changes from 1 commit
185ebec
904e422
f5f71e1
b081058
ec84364
2b2f1a5
d410092
43d4e60
6638a27
c6f8bea
1b5007e
59391a0
b130325
1f56ecb
cc39a1f
fd0611f
091fa57
3dcd595
0ad42b5
5683eca
17dce04
e997e0e
876a53e
5e58822
664b1c9
e9e0b9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import React from 'react'; | ||
|
|
||
| export type Depth = 1 | 2 | 3 | 4 | 5 | 6; | ||
|
|
||
| const CreateHeading = (depth: Depth) => { | ||
| const Tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' = `h${depth}`; | ||
|
|
||
| const Heading = ({ id, children, ...attrs }: React.PropsWithChildren<HTMLHeadingElement>) => { | ||
| if (!children) return ''; | ||
|
|
||
| return ( | ||
| // @ts-expect-error | ||
| <Tag {...attrs} className={`heading heading-${depth} header-scroll`}> | ||
| <div key={`heading-anchor-${id}`} className="heading-anchor anchor waypoint" id={id} /> | ||
| <div key={`heading-text-${id}`} className="heading-text"> | ||
| {children} | ||
| </div> | ||
| <a | ||
| key={`heading-anchor-icon-${id}`} | ||
| aria-label={`Skip link to ${children[1]}`} | ||
| className="heading-anchor-icon fa fa-anchor" | ||
| href={`#${id}`} | ||
| /> | ||
| </Tag> | ||
| ); | ||
| }; | ||
|
|
||
| return Heading; | ||
| }; | ||
kellyjosephprice marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| export default CreateHeading; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,18 @@ | ||
| --- | ||
| title: "Headings" | ||
| title: 'Headings' | ||
| category: 5fdf7610134322007389a6ed | ||
| hidden: false | ||
| --- | ||
|
|
||
| ## Examples | ||
|
|
||
| > ### Heading Block 3 | ||
| > | ||
| > #### Heading Block 4 | ||
| > | ||
| > ##### Heading Block 5 | ||
| > | ||
| > ###### Heading Block 6 | ||
| > #### Heading Block 4 | ||
| > | ||
| > ##### Heading Block 5 | ||
| > | ||
| > ###### Heading Block 6 | ||
|
|
||
| ## Edge Cases | ||
|
|
||
|
|
@@ -20,33 +21,40 @@ hidden: false | |
| ####Compact Notation | ||
|
|
||
| Headers are denoted using a space-separated `#` prefix. While the space is technically required in most standard Markdown implementations, some processors allow for a compact notation as well. ReadMe supports this style, so writing this | ||
|
|
||
| ###A Valid Heading | ||
|
|
||
| Lorem ipsum dolor etc. | ||
|
|
||
| > 🛑 | ||
| ``` | ||
| ###A Valid Heading | ||
|
|
||
| Lorem ipsum dolor etc. | ||
| ``` | ||
|
Comment on lines
+25
to
+29
Contributor
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. (Not to be picky since I know this isn't technically within the scope of this PR, but I did notice that this compact header notation isn't working with the new MDX processor!)
Collaborator
Author
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. |
||
|
|
||
| > 🛑 | ||
| > Compact headings must be followed by two line breaks before the following block. | ||
|
|
||
| #### ATX-Style Notation #### | ||
|
|
||
| If you prefer, you can "wrap" headers with hashes rather than simply prefixing them: | ||
|
|
||
| ## ATX Headings are Valid ## | ||
| ``` | ||
| ## ATX Headings are Valid ## | ||
| ``` | ||
|
|
||
| #### Underline Notation | ||
|
|
||
| For top-level headings, the underline notation is valid: | ||
|
|
||
| Heading One | ||
| =========== | ||
|
|
||
| Heading Two | ||
| --- | ||
| ``` | ||
| Heading One | ||
| =========== | ||
|
|
||
| Heading Two | ||
| --- | ||
| ``` | ||
|
|
||
| ### Incremented Anchors | ||
|
|
||
| Occasionally, a single doc might contain multiple headings with the same text, which can cause the generated anchor links to conflict. ReadMe's new markdown processor normalizes heading anchors by auto-incrementing similar heading's IDs. Try it out by clicking on this section header _or_ the following sub-section title: | ||
|
|
||
| #### Incremented Heading Anchors | ||
|
|
||
| #### Incremented Heading Anchors | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Not sure this
children[1]logic still makes sense now that we're getting rid of theshowAnchorIconsoption?1Maybe it should just be:
Footnotes
side note: why are we getting rid of this? is it just not used anywhere? ↩
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 didn't see it used anywhere, so I didn't bother porting it?