Skip to content

Commit 6600764

Browse files
committed
issues #1, #2
1 parent 5e66039 commit 6600764

File tree

5 files changed

+57
-18
lines changed

5 files changed

+57
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11+
## [0.3.0] - 2018-12-02
12+
13+
- Added support for Azure DevOps Wiki style `[[_TOC_]]` token - [Issue #2](https://github.com/wibblemonkey/vscode-markdown-auto-toc/issues/2)
14+
- Fixed issue with HTML/Markdown tokens leaking into table of contents items - [Issue #1](https://github.com/wibblemonkey/vscode-markdown-auto-toc/issues/1)
15+
1116
## [0.2.0] - 2018-11-28
1217

1318
### Changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@ for the table of contents itself and override the default HTML class applied to
1414
the `<div/>` container elements for both the table of contents and the title
1515
header.
1616

17+
The extension also supports the Azure DevOps Wiki style table of contents token
18+
`[[_TOC_]]`. This is enabled by default but can be turned off if desired.
19+
1720
## Extension Settings
1821

1922
This extension contributes the following settings:
2023

21-
Name | Default Value | Description
22-
--------------------------------------|----------------------|------------------------------------------------------------------------------------
23-
`markdownAutoTOC.maximumHeadingLevel` | 2 | The maximum heading level to include in the generated table of contents
24-
`markdownAutoTOC.containerClass` | toc-container | The HTML class to apply to the generated `<div/>` for the table of contents.
25-
`markdownAutoTOC.header` | true | Include a heading above the generated table of contents.
26-
`markdownAutoTOC.headerClass` | toc-container-header | The HTML class to apply to the generated `<div/>` for the table of contents header.
27-
`markdownAutoTOC.headerContent` | Contents | The header text to display above the table of contents.
24+
Name | Default Value | Description
25+
-----------------------------------------------------|----------------------|------------------------------------------------------------------------------------
26+
`markdownAutoTOC.maximumHeadingLevel` | 2 | The maximum heading level to include in the generated table of contents
27+
`markdownAutoTOC.containerClass` | toc-container | The HTML class to apply to the generated `<div/>` for the table of contents.
28+
`markdownAutoTOC.header` | true | Include a heading above the generated table of contents.
29+
`markdownAutoTOC.headerClass` | toc-container-header | The HTML class to apply to the generated `<div/>` for the table of contents header.
30+
`markdownAutoTOC.headerContent` | Contents | The header text to display above the table of contents.
31+
`markdownAutoTOC.enableAzureDevOpsWikiCompatibility` | true | Allow `[[_TOC_]]` as the token to generate the table of contents.
2832

2933
## Known Issues
3034

extension.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
const vscode = require('vscode');
44
const htmlEncode = require('js-htmlencode').htmlEncode;
5+
const removeMarkdown = require('remove-markdown');
6+
const striptags = require('striptags');
57

68
const validHtmlClass = /^[a-z][a-z0-9_-]*$/i;
79

@@ -25,6 +27,8 @@ function buildMarkdownItTableOfContentsOptions(configuration) {
2527
options["includeLevel"] = buildIncludeLevelOptionFromConfiguration(configuration);
2628
options["containerClass"] = buildContainerClassOptionFromConfiguration(configuration);
2729
options["containerHeaderHtml"] = buildContainerHeaderHtmlOptionFromConfiguration(configuration);
30+
options["markerPattern"] = buildMarkerPatternOptionFromConfiguration(configuration);
31+
options["format"] = sanitizeHeading;
2832

2933
return options;
3034
}
@@ -45,3 +49,12 @@ function buildContainerHeaderHtmlOptionFromConfiguration(configuration) {
4549
}
4650
return option;
4751
}
52+
53+
function buildMarkerPatternOptionFromConfiguration(configuration) {
54+
var token = configuration.enableAzureDevOpsWikiCompatibility ? "(toc|_toc_)" : "toc";
55+
return new RegExp(`^\\[\\[${token}\\]\\]`, "im");
56+
}
57+
58+
function sanitizeHeading(heading) {
59+
return removeMarkdown(striptags(heading));
60+
}

package-lock.json

Lines changed: 19 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "markdown-auto-toc",
33
"displayName": "Markdown AutoTOC",
44
"description": "Adds support for inserting an auto-generated table of contents to VS Code's built-in markdown preview using the [[TOC]] syntax.",
5-
"version": "0.2.0",
5+
"version": "0.3.0",
66
"publisher": "wibblemonkey",
77
"keywords": [
88
"markdown",
@@ -75,6 +75,11 @@
7575
"type": "string",
7676
"default": "Contents",
7777
"description": "The header text to display above the table of contents."
78+
},
79+
"markdownAutoTOC.enableAzureDevOpsWikiCompatibility": {
80+
"type": "boolean",
81+
"default": true,
82+
"markdownDescription": "Allow `[[_TOC_]]` as the token to generate the table of contents."
7883
}
7984
}
8085
},
@@ -93,6 +98,8 @@
9398
},
9499
"dependencies": {
95100
"js-htmlencode": "^0.3.0",
96-
"markdown-it-table-of-contents": "^0.4.3"
101+
"markdown-it-table-of-contents": "^0.4.3",
102+
"remove-markdown": "^0.3.0",
103+
"striptags": "^3.1.1"
97104
}
98105
}

0 commit comments

Comments
 (0)