Skip to content

Commit 23891d9

Browse files
Merge pull request #18 from technote-space/release/next-v2.2.1
release: v2.2.2
2 parents 9cf0607 + 5f62cd5 commit 23891d9

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ transform(readFileSync('README.md', {
4747
// closingComment: '<!-- tocstop --> ',
4848
// checkOpeningComments: ['<!-- toc '],
4949
// checkClosingComments: ['<!-- tocstop '],
50+
// isCustomMode: false,
51+
// customTemplate: '<p align="center">${ITEMS}</p>',
52+
// itemTemplate: '<a href="${LINK}">${TEXT}</a>',
53+
// separator: '<span>|</span>',
5054
}));
5155
```
5256

__tests__/transform-html-mode.test.ts renamed to __tests__/transform-custom-mode.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {transform} from '../src';
66
describe('transform', () => {
77
it('run in html mode', () => {
88
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-html.md'), 'utf8');
9-
const headers = transform(content, {mode: 'github.com', isHtml: true});
9+
const headers = transform(content, {mode: 'github.com', isCustomMode: true});
1010

1111
expect(headers.toc.split('\n')).toEqual(
1212
['**Table of Contents** *generated with [DocToc](https://github.com/technote-space/doctoc)*',
@@ -26,8 +26,8 @@ describe('transform', () => {
2626
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-html.md'), 'utf8');
2727
const headers = transform(content, {
2828
mode: 'github.com',
29-
isHtml: true,
30-
htmlTemplate: '<ul>${ITEMS}</ul>',
29+
isCustomMode: true,
30+
customTemplate: '<ul>${ITEMS}</ul>',
3131
itemTemplate: '<li><a href="${LINK}" target="_blank">${TEXT}</a></li>',
3232
separator: '',
3333
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@technote-space/doctoc",
3-
"version": "2.2.1",
3+
"version": "2.2.2",
44
"description": "Generates TOC for markdown files of local git repo.",
55
"keywords": [
66
"github",

src/lib/transform.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const getHeaderItem = (header: HeaderWithAnchor, indentation: string, lowestRank
126126
return `${indentation.repeat(header.rank - lowestRank)}${entryPrefix} ${header.anchor}`;
127127
};
128128

129-
const getHtmlHeaderContents = (headers: Array<HeaderWithAnchor>, lowestRank: number, htmlTemplate: string | undefined, itemTemplate: string | undefined, separator: string | undefined): string => replaceVariables(htmlTemplate ?? DEFAULT_HTML_TEMPLATE, [{
129+
const getHtmlHeaderContents = (headers: Array<HeaderWithAnchor>, lowestRank: number, customTemplate: string | undefined, itemTemplate: string | undefined, separator: string | undefined): string => replaceVariables(customTemplate ?? DEFAULT_HTML_TEMPLATE, [{
130130
key: 'ITEMS',
131131
replace: `\n${headers.filter(header => header.rank === lowestRank).map(header => getHeaderItemHtml(header, itemTemplate)).join(`\n${separator ?? DEFAULT_SEPARATOR}\n`)}\n`,
132132
}]);
@@ -154,8 +154,8 @@ export const transform = (
154154
closingComment,
155155
checkOpeningComments,
156156
checkClosingComments,
157-
isHtml,
158-
htmlTemplate,
157+
isCustomMode,
158+
customTemplate,
159159
itemTemplate,
160160
separator,
161161
}: TransformOptions = {},
@@ -197,7 +197,7 @@ export const transform = (
197197
const toc =
198198
inferredTitle +
199199
titleSeparator +
200-
(isHtml ? getHtmlHeaderContents(linkedHeaders, lowestRank, htmlTemplate, itemTemplate, separator) : getHeaderContents(linkedHeaders, indentation, lowestRank, _entryPrefix)) +
200+
(isCustomMode ? getHtmlHeaderContents(linkedHeaders, lowestRank, customTemplate, itemTemplate, separator) : getHeaderContents(linkedHeaders, indentation, lowestRank, _entryPrefix)) +
201201
'\n';
202202
const wrappedToc = (openingComment ?? OPENING_COMMENT) + '\n' + wrapToc(toc, inferredTitle, isFolding) + '\n' + (closingComment ?? CLOSING_COMMENT);
203203
if (currentToc === wrappedToc) {

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export type TransformOptions = Partial<{
1414
closingComment: string;
1515
checkOpeningComments: Array<string>;
1616
checkClosingComments: Array<string>;
17-
isHtml: boolean;
18-
htmlTemplate: string;
17+
isCustomMode: boolean;
18+
customTemplate: string;
1919
itemTemplate: string;
2020
separator: string;
2121
}>

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,9 +1482,9 @@ copy-descriptor@^0.1.0:
14821482
integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=
14831483

14841484
core-js@^3.6.1:
1485-
version "3.7.0"
1486-
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.7.0.tgz#b0a761a02488577afbf97179e4681bf49568520f"
1487-
integrity sha512-NwS7fI5M5B85EwpWuIwJN4i/fbisQUwLwiSNUWeXlkAZ0sbBjLEvLvFLf1uzAUV66PcEPt4xCGCmOZSxVf3xzA==
1485+
version "3.8.0"
1486+
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.8.0.tgz#0fc2d4941cadf80538b030648bb64d230b4da0ce"
1487+
integrity sha512-W2VYNB0nwQQE7tKS7HzXd7r2y/y2SVJl4ga6oH/dnaLFzM0o2lB2P3zCkWj5Wc/zyMYjtgd5Hmhk0ObkQFZOIA==
14881488

14891489
[email protected], core-util-is@~1.0.0:
14901490
version "1.0.2"

0 commit comments

Comments
 (0)