diff --git a/README.md b/README.md index 93588de..03d27a3 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ transform(readFileSync('README.md', { // closingComment: ' ', // checkOpeningComments: [' +# Hello, world! + +> You can make code blocks with three back ticks: +> +> ``` + +# Add this header + +

And also this one

+ +> ``` + + diff --git a/__tests__/params.test.ts b/__tests__/params.test.ts index dc815f4..d85e5cf 100644 --- a/__tests__/params.test.ts +++ b/__tests__/params.test.ts @@ -1,7 +1,7 @@ /* eslint-disable no-magic-numbers */ import { describe, expect, it } from 'vitest'; -import { CLOSING_COMMENT, OPENING_COMMENT } from '../src'; -import { extractParams, getStartSection, getParamsSection } from '../src/lib/params'; +import { CLOSING_COMMENT, OPENING_COMMENT } from '../src/index.js'; +import { extractParams, getStartSection, getParamsSection } from '../src/lib/params.js'; describe('extractParams', () => { const opening = OPENING_COMMENT.replace('\n', ' '); diff --git a/__tests__/transform-custom-mode.test.ts b/__tests__/transform-custom-mode.test.ts index 504f76a..f8c1f92 100644 --- a/__tests__/transform-custom-mode.test.ts +++ b/__tests__/transform-custom-mode.test.ts @@ -2,7 +2,7 @@ import { readFileSync } from 'fs'; import { resolve } from 'path'; import { describe, expect, it } from 'vitest'; -import { transform } from '../src'; +import { transform } from '../src/index.js'; describe('transform', () => { it('run in html mode', () => { diff --git a/__tests__/transform-footer.test.ts b/__tests__/transform-footer.test.ts index 663f219..6361c66 100644 --- a/__tests__/transform-footer.test.ts +++ b/__tests__/transform-footer.test.ts @@ -2,7 +2,7 @@ import { readFileSync } from 'fs'; import { resolve } from 'path'; import { describe, expect, it } from 'vitest'; -import { transform } from '../src'; +import { transform } from '../src/index.js'; describe('transform', () => { it('add footer', () => { diff --git a/__tests__/transform-html.test.ts b/__tests__/transform-html.test.ts index 9b257a1..249f556 100644 --- a/__tests__/transform-html.test.ts +++ b/__tests__/transform-html.test.ts @@ -2,7 +2,7 @@ import { readFileSync } from 'fs'; import { resolve } from 'path'; import { describe, expect, it } from 'vitest'; -import { transform } from '../src'; +import { transform } from '../src/index.js'; describe('transform', () => { it('given a file that includes html with header tags and maxHeaderLevel 8', () => { diff --git a/__tests__/transform-nested-markdown.test.ts b/__tests__/transform-nested-markdown.test.ts index 3bcc996..ff9e75f 100644 --- a/__tests__/transform-nested-markdown.test.ts +++ b/__tests__/transform-nested-markdown.test.ts @@ -2,7 +2,7 @@ import { readFileSync } from 'fs'; import { resolve } from 'path'; import { describe, expect, it } from 'vitest'; -import { transform } from '../src'; +import { transform } from '../src/index.js'; describe('transform', () => { it('\nhandle inline links and images', () => { diff --git a/__tests__/transform-not-transformed.test.ts b/__tests__/transform-not-transformed.test.ts index 54e6ab8..54d3580 100644 --- a/__tests__/transform-not-transformed.test.ts +++ b/__tests__/transform-not-transformed.test.ts @@ -2,7 +2,7 @@ import { readFileSync } from 'fs'; import { resolve } from 'path'; import { describe, expect, it } from 'vitest'; -import { transform } from '../src'; +import { transform } from '../src/index.js'; describe('transform', () => { it('update only', () => { @@ -20,4 +20,12 @@ describe('transform', () => { expect(headers.transformed).toBe(false); expect(headers.reason).toBe('not updated'); }); + + it('skipped', () => { + const content = readFileSync(resolve(__dirname, 'fixtures/readme-skipped.md'), 'utf8'); + const headers = transform(content); + + expect(headers.transformed).toBe(false); + expect(headers.reason).toBe('skipped'); + }); }); diff --git a/__tests__/transform-override-params.test.ts b/__tests__/transform-override-params.test.ts index 4796621..63f1e11 100644 --- a/__tests__/transform-override-params.test.ts +++ b/__tests__/transform-override-params.test.ts @@ -2,7 +2,7 @@ import { readFileSync } from 'fs'; import { resolve } from 'path'; import { describe, expect, it } from 'vitest'; -import { transform } from '../src'; +import { transform } from '../src/index.js'; describe('transform', () => { it('override params (empty toc)', () => { diff --git a/__tests__/transform-title.test.ts b/__tests__/transform-title.test.ts index 00743ba..5bc5cb3 100644 --- a/__tests__/transform-title.test.ts +++ b/__tests__/transform-title.test.ts @@ -2,7 +2,7 @@ import { readFileSync } from 'fs'; import { resolve } from 'path'; import { describe, expect, it } from 'vitest'; -import { transform } from '../src'; +import { transform } from '../src/index.js'; describe('transform', () => { it('overwrite existing title', () => { diff --git a/__tests__/transform-weird-headers.test.ts b/__tests__/transform-weird-headers.test.ts index 38104d8..a8ca696 100644 --- a/__tests__/transform-weird-headers.test.ts +++ b/__tests__/transform-weird-headers.test.ts @@ -2,7 +2,7 @@ import { readFileSync } from 'fs'; import { resolve } from 'path'; import { describe, expect, it } from 'vitest'; -import { transform } from '../src'; +import { transform } from '../src/index.js'; describe('transform', () => { it('given a file with edge-case header names', () => { diff --git a/__tests__/transform.test.ts b/__tests__/transform.test.ts index bab1b1e..740bba7 100644 --- a/__tests__/transform.test.ts +++ b/__tests__/transform.test.ts @@ -1,8 +1,8 @@ /* eslint-disable no-magic-numbers */ import { describe, expect, it } from 'vitest'; -import { transform } from '../src'; -import { OPENING_COMMENT, CLOSING_COMMENT } from '../src'; -import { getLinesToToc, matchesStart, matchesEnd } from '../src/lib/transform'; +import { transform } from '../src/index.js'; +import { OPENING_COMMENT, CLOSING_COMMENT } from '../src/index.js'; +import { getLinesToToc, matchesStart, matchesEnd, matchesSkip } from '../src/lib/transform.js'; const check = ( name: string, @@ -620,3 +620,15 @@ describe('matchesEnd', () => { expect(matchesEnd(['')).toBe(false); }); }); + +describe('matchesSkip', () => { + it('should return true', () => { + expect(matchesSkip()('')).toBe(true); + expect(matchesSkip(['')).toBe(true); + }); + + it('should return false', () => { + expect(matchesSkip()('')).toBe(false); + expect(matchesSkip(['')).toBe(false); + }); +}); diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index f315e3f..3641f38 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -1,6 +1,6 @@ /* eslint-disable no-magic-numbers */ import { describe, expect, it } from 'vitest'; -import { replaceVariables } from '../src/lib/utils'; +import { replaceVariables } from '../src/lib/utils.js'; describe('replaceVariables', () => { it('should replace variables', () => { diff --git a/package.json b/package.json index c251563..711fecc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@technote-space/doctoc", - "version": "2.5.2", + "version": "2.6.0", "description": "Generates TOC for markdown files of local git repo.", "keywords": [ "github", @@ -49,28 +49,28 @@ "update": "npm_config_yes=true npx npm-check-updates -u --timeout 100000 && yarn install && yarn upgrade && yarn audit" }, "dependencies": { - "@technote-space/anchor-markdown-header": "^1.1.38", - "@textlint/markdown-to-ast": "^12.2.2", + "@technote-space/anchor-markdown-header": "^1.1.39", + "@textlint/markdown-to-ast": "^12.2.3", "htmlparser2": "^8.0.1", "update-section": "^0.3.3" }, "devDependencies": { - "@commitlint/cli": "^17.2.0", - "@commitlint/config-conventional": "^17.2.0", - "@rollup/plugin-typescript": "^9.0.2", + "@commitlint/cli": "^17.3.0", + "@commitlint/config-conventional": "^17.3.0", + "@rollup/plugin-typescript": "^10.0.1", "@sindresorhus/tsconfig": "^3.0.1", "@textlint/ast-node-types": "^12.2.2", - "@types/node": "^18.11.9", - "@typescript-eslint/eslint-plugin": "^5.42.0", - "@typescript-eslint/parser": "^5.42.0", - "@vitest/coverage-c8": "^0.24.5", - "eslint": "^8.26.0", + "@types/node": "^18.11.11", + "@typescript-eslint/eslint-plugin": "^5.46.0", + "@typescript-eslint/parser": "^5.46.0", + "@vitest/coverage-c8": "^0.25.6", + "eslint": "^8.29.0", "eslint-plugin-import": "^2.26.0", - "husky": "^8.0.1", - "lint-staged": "^13.0.3", - "rollup": "^3.2.5", - "typescript": "^4.8.4", - "vitest": "^0.24.5" + "husky": "^8.0.2", + "lint-staged": "^13.1.0", + "rollup": "^3.7.0", + "typescript": "^4.9.4", + "vitest": "^0.25.6" }, "publishConfig": { "access": "public" diff --git a/src/constant.ts b/src/constant.ts index bc94200..6766908 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -3,6 +3,7 @@ export const OPENING_COMMENT = ''; export const CHECK_OPENING_COMMENT = '