Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes GH-6. Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com> Reviewed-by: Remco Haszing <remcohaszing@gmail.com> Reviewed-by: Titus Wormer <tituswormer@gmail.com>
- Loading branch information
Christian Ivicevic
committed
Nov 11, 2020
1 parent
ef02f86
commit 06ca90a
Showing
5 changed files
with
117 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Minimum TypeScript Version: 3.5 | ||
import {Plugin} from 'unified' | ||
import {Node, Properties} from 'hast' | ||
|
||
/** | ||
* Automatically add links to headings. | ||
*/ | ||
declare const autolinkHeadings: Plugin<[autolinkHeadings.Options?]> | ||
|
||
declare namespace autolinkHeadings { | ||
interface Options { | ||
/** | ||
* How to create links. | ||
* | ||
* @default 'prepend' | ||
*/ | ||
behavior?: 'prepend' | 'append' | 'wrap' | 'before' | 'after' | ||
|
||
/** | ||
* Extra properties to set on the link. | ||
* | ||
* @default {ariaHidden: true, tabIndex: -1} | ||
*/ | ||
properties?: Properties | Properties[] | ||
|
||
/** | ||
* `hast` nodes to insert in the link. | ||
* | ||
* @default { type: 'element', tagName: 'span', properties: {className: ['icon', 'icon-link']}, children: [] } | ||
*/ | ||
content?: Node | ((heading: Node) => Node[]) | ||
|
||
/** | ||
* `hast` node to wrap the heading and link with, if `behavior` is | ||
* `'before'` or `'after'`. There is no default. | ||
*/ | ||
group?: Node | ((heading: Node) => Node) | ||
} | ||
} | ||
|
||
export = autolinkHeadings |
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,47 @@ | ||
import unified = require('unified') | ||
import autolinkHeadings = require('rehype-autolink-headings') | ||
|
||
unified().use(autolinkHeadings) | ||
unified().use(autolinkHeadings, {behavior: 'prepend'}) | ||
unified().use(autolinkHeadings, {behavior: 'append'}) | ||
unified().use(autolinkHeadings, {behavior: 'wrap'}) | ||
unified().use(autolinkHeadings, {behavior: 'before'}) | ||
unified().use(autolinkHeadings, {behavior: 'after'}) | ||
unified().use(autolinkHeadings, {properties: {ariaHidden: true, tabIndex: -1}}) | ||
unified().use(autolinkHeadings, { | ||
properties: [{ariaHidden: true, tabIndex: -1}] | ||
}) | ||
unified().use(autolinkHeadings, { | ||
content: { | ||
type: 'element', | ||
tagName: 'span', | ||
properties: {className: ['icon', 'icon-link']}, | ||
children: [] | ||
} | ||
}) | ||
unified().use(autolinkHeadings, { | ||
content: (_currentHeading) => [ | ||
{ | ||
type: 'element', | ||
tagName: 'span', | ||
properties: {className: ['icon', 'icon-link']}, | ||
children: [] | ||
} | ||
] | ||
}) | ||
unified().use(autolinkHeadings, { | ||
group: { | ||
type: 'element', | ||
tagName: 'span', | ||
properties: {className: ['icon', 'icon-link']}, | ||
children: [] | ||
} | ||
}) | ||
unified().use(autolinkHeadings, { | ||
group: (_currentHeading) => ({ | ||
type: 'element', | ||
tagName: 'span', | ||
properties: {className: ['icon', 'icon-link']}, | ||
children: [] | ||
}) | ||
}) |
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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["es2015"], | ||
"strict": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"rehype-autolink-headings": ["index.d.ts"] | ||
} | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"no-redundant-jsdoc": false, | ||
"semicolon": false, | ||
"whitespace": false | ||
} | ||
} |