marked-gfm-heading-id
Advanced tools
Comparing version 3.1.3 to 3.2.0
@@ -87,7 +87,7 @@ (function (global, factory) { | ||
let slugger; | ||
let slugger = new BananaSlug(); | ||
let headings = []; | ||
function gfmHeadingId({ prefix = '' } = {}) { | ||
function gfmHeadingId({ prefix = '', globalSlugs = false } = {}) { | ||
return { | ||
@@ -97,4 +97,5 @@ headerIds: false, // prevent deprecation warning; remove this once headerIds option is removed | ||
preprocess(src) { | ||
headings = []; | ||
slugger = new BananaSlug(); | ||
if (!globalSlugs) { | ||
resetHeadings(); | ||
} | ||
return src; | ||
@@ -123,5 +124,11 @@ } | ||
function resetHeadings() { | ||
headings = []; | ||
slugger = new BananaSlug(); | ||
} | ||
exports.getHeadingList = getHeadingList; | ||
exports.gfmHeadingId = gfmHeadingId; | ||
exports.resetHeadings = resetHeadings; | ||
})); |
{ | ||
"name": "marked-gfm-heading-id", | ||
"version": "3.1.3", | ||
"version": "3.2.0", | ||
"description": "marked GFM heading ids", | ||
@@ -48,23 +48,23 @@ "main": "./lib/index.cjs", | ||
"devDependencies": { | ||
"@babel/core": "^7.23.9", | ||
"@babel/preset-env": "^7.23.9", | ||
"@babel/core": "^7.24.6", | ||
"@babel/preset-env": "^7.24.6", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@semantic-release/changelog": "^6.0.3", | ||
"@semantic-release/commit-analyzer": "^11.1.0", | ||
"@semantic-release/commit-analyzer": "^13.0.0", | ||
"@semantic-release/git": "^10.0.1", | ||
"@semantic-release/github": "^9.2.6", | ||
"@semantic-release/npm": "^11.0.2", | ||
"@semantic-release/release-notes-generator": "^12.1.0", | ||
"@semantic-release/github": "^10.0.5", | ||
"@semantic-release/npm": "^12.0.1", | ||
"@semantic-release/release-notes-generator": "^14.0.0", | ||
"babel-jest": "^29.7.0", | ||
"eslint": "^8.56.0", | ||
"eslint": "^8.57.0", | ||
"eslint-config-standard": "^17.1.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-n": "^16.6.2", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"eslint-plugin-promise": "^6.2.0", | ||
"jest-cli": "^29.7.0", | ||
"marked": "^12.0.0", | ||
"rollup": "^4.9.6", | ||
"semantic-release": "^23.0.0", | ||
"tsd": "^0.30.4" | ||
"marked": "^12.0.2", | ||
"rollup": "^4.18.0", | ||
"semantic-release": "^24.0.0", | ||
"tsd": "^0.31.0" | ||
} | ||
} |
@@ -59,6 +59,12 @@ # marked-gfm-heading-id | ||
## Clear Heading List | ||
`resetHeadings` is a function to purge the stored list of headings and reset the Slugger. This is only needed when the globalSlugs option ( see below) is set to true and you wish to reset the slugger and exportable Headers list. | ||
## `options` | ||
| option | type | default | description | | ||
|--------|--------|---------|:--------------------------------| | ||
| prefix | string | `""` | A string to prepend to all ids. | | ||
| option | type | default | description | | ||
|-------------|--------|---------|:----------------------------------------------| | ||
| prefix | string | `""` | A string to prepend to all ids. | | ||
| globalSlugs | bool | `false` | Track ids from one use of marked to the next. This ensures unique headers when parsing multiple markdown fragments and rendering the results as a single document. When set to false, the slugger and headers lists are cleared on every marked run. | ||
@@ -30,6 +30,9 @@ import type {MarkedExtension, marked} from 'marked'; | ||
* | ||
* @param tokens a lexer output | ||
* @param options Options for the extension | ||
* @returns A string formatted the same as what would {@link gfmHeadingId} do. | ||
* @returns An array of HeadingData with level, text and id. | ||
*/ | ||
export function getHeadingList(): HeadingData[]; | ||
/** | ||
* Clears the stored list of Headings as computed by gfmHeadingId | ||
*/ | ||
export function resetHeadings(): void; |
import GithubSlugger from 'github-slugger'; | ||
let slugger; | ||
let slugger = new GithubSlugger(); | ||
let headings = []; | ||
export function gfmHeadingId({ prefix = '' } = {}) { | ||
export function gfmHeadingId({ prefix = '', globalSlugs = false } = {}) { | ||
return { | ||
@@ -11,4 +11,5 @@ headerIds: false, // prevent deprecation warning; remove this once headerIds option is removed | ||
preprocess(src) { | ||
headings = []; | ||
slugger = new GithubSlugger(); | ||
if (!globalSlugs) { | ||
resetHeadings(); | ||
} | ||
return src; | ||
@@ -36,1 +37,6 @@ } | ||
} | ||
export function resetHeadings() { | ||
headings = []; | ||
slugger = new GithubSlugger(); | ||
} |
Sorry, the diff of this file is not supported yet
29871
350
70