-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
dfn
elements for defining terms (#1744)
* Use <dfn> elements for defining terms * Add internal link * Namespace dfn in rule * Accept internal links to HTML elements with id * Accept internal links to id of HTML elements * Accept links to IDs in glossary files * Accept links to IDs from one def to another
- Loading branch information
Showing
9 changed files
with
77 additions
and
30 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
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
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
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
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,19 @@ | ||
const getMarkdownAstNodesOfType = require('../utils/get-markdown-ast-nodes-of-type') | ||
|
||
/** | ||
* get the `id` of all html elements in the AST (notably the dfn elements) | ||
* -> eg: <dfn id="123456:anchor-name"> | ||
*/ | ||
function getIds(markdownAST) { | ||
return ( | ||
// Find all HTML elements in the markdown | ||
getMarkdownAstNodesOfType(markdownAST, 'html') | ||
// Keep the ones with an `id` attribute | ||
.map(({ value }) => value.match(/id="([^"]*)"/)) | ||
.filter(value => value !== null) | ||
// Only keep the matched group, aka the value of the `id` attribute | ||
.map(matches => matches[1]) | ||
) | ||
} | ||
|
||
module.exports = getIds |