-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby-transform-remark): populate id to headings from markdownA…
…ST (#23546) * feat(gatsby-transform-remark): populate id to headings from markdownAST * feat: check hProperties as well * test: add a test case with autolink-headers * fix: add more test cases * add get-heading-id.js * remove transpiled one * add working autolink-headers test case Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
- Loading branch information
Showing
5 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
1 change: 1 addition & 0 deletions
1
packages/gatsby-transformer-remark/src/create-schema-customization.js
This file contains 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
const typeDefs = ` | ||
type MarkdownHeading { | ||
id: String | ||
value: String | ||
depth: Int | ||
} | ||
|
This file contains 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
15 changes: 15 additions & 0 deletions
15
packages/gatsby-transformer-remark/src/utils/get-heading-id.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const getHeadingID = heading => { | ||
const data = heading.data | ||
if (data) { | ||
if (data.id) return data.id | ||
if (data.htmlAttributes && data.htmlAttributes.id) { | ||
return data.htmlAttributes.id | ||
} | ||
|
||
if (data.hProperties && data.hProperties.id) { | ||
return data.hProperties.id | ||
} | ||
} | ||
|
||
return null | ||
} |