From ab1e611fccb7362503783fa1821e67c44e5d591a Mon Sep 17 00:00:00 2001 From: Keith Chu Date: Wed, 12 Apr 2023 05:05:22 +0800 Subject: [PATCH] feat: enable ==mark== syntax (#79) --- .github/workflows/test.yml | 2 ++ package-lock.json | 11 +++++++++++ package.json | 1 + src/markdownHeaders.test.ts | 14 ++++++++++++++ src/markdownHeaders.ts | 3 ++- test/markdownHeaders_79.md | 1 + 6 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/markdownHeaders_79.md diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f000ee4..debf6c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,6 +23,8 @@ jobs: - name: Setup Node uses: actions/setup-node@v3 + with: + node-version: '16.x' - run: npm install diff --git a/package-lock.json b/package-lock.json index c3d4fb2..ebb8054 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "dependencies": { "katex": "^0.16.2", "markdown-it": "^13.0.1", + "markdown-it-mark": "^3.0.1", "uslug": "git+https://github.com/laurent22/uslug.git#emoji-support" }, "devDependencies": { @@ -6743,6 +6744,11 @@ "markdown-it": "bin/markdown-it.js" } }, + "node_modules/markdown-it-mark": { + "version": "3.0.1", + "resolved": "https://registry.npmmirror.com/markdown-it-mark/-/markdown-it-mark-3.0.1.tgz", + "integrity": "sha512-HyxjAu6BRsdt6Xcv6TKVQnkz/E70TdGXEFHRYBGLncRE9lBFwDNLVtFojKxjJWgJ+5XxUwLaHXy+2sGBbDn+4A==" + }, "node_modules/markdown-it/node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -16579,6 +16585,11 @@ } } }, + "markdown-it-mark": { + "version": "3.0.1", + "resolved": "https://registry.npmmirror.com/markdown-it-mark/-/markdown-it-mark-3.0.1.tgz", + "integrity": "sha512-HyxjAu6BRsdt6Xcv6TKVQnkz/E70TdGXEFHRYBGLncRE9lBFwDNLVtFojKxjJWgJ+5XxUwLaHXy+2sGBbDn+4A==" + }, "md5.js": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", diff --git a/package.json b/package.json index 5a401ce..6e72f3f 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "dependencies": { "katex": "^0.16.2", "markdown-it": "^13.0.1", + "markdown-it-mark": "^3.0.1", "uslug": "git+https://github.com/laurent22/uslug.git#emoji-support" }, "files": [ diff --git a/src/markdownHeaders.test.ts b/src/markdownHeaders.test.ts index 28af469..0fc3404 100644 --- a/src/markdownHeaders.test.ts +++ b/src/markdownHeaders.test.ts @@ -51,3 +51,17 @@ test('headers after code highlighting', () => { slug: 'header-3', }); }); + +test('headers after code highlighting', () => { + const headers = markdownHeaders( + readFileSync('./test/markdownHeaders_79.md', 'utf-8'), + ); + expect(headers.length).toBe(1); + expect(headers[0]).toEqual({ + html: 'Like this', + level: 1, + lineno: 0, + number: '1', + slug: 'like-this', + }); +}); diff --git a/src/markdownHeaders.ts b/src/markdownHeaders.ts index 429c5ae..b256277 100644 --- a/src/markdownHeaders.ts +++ b/src/markdownHeaders.ts @@ -1,7 +1,8 @@ import getSlug from './markdownSlug'; const katex = require('katex'); -const markdownit = require('markdown-it')({ html: true }); +const markdownit = require('markdown-it')({ html: true }) + .use(require('markdown-it-mark')); function isHeader(line: string, context: any) { // check code block diff --git a/test/markdownHeaders_79.md b/test/markdownHeaders_79.md new file mode 100644 index 0000000..976ff32 --- /dev/null +++ b/test/markdownHeaders_79.md @@ -0,0 +1 @@ +# ==Like **this**==