From 206c284b5bf308c48e43e203d779fe2e3b4c80f7 Mon Sep 17 00:00:00 2001 From: sandypockets Date: Sun, 17 Dec 2023 01:32:12 -0500 Subject: [PATCH] Feat: Add debug mode for verbose handling, improve overall test coverage --- __tests__/addHeadingIds.integration.test.js | 14 -- __tests__/processMarkdown.frontmatter.test.js | 25 +++ __tests__/processMarkdown.gfm.test.js | 18 ++ .../processMarkdown.sanitization.test.js | 9 + __tests__/processMarkdown.test.js | 191 ++++++++++++++++++ dist/index.cjs | 2 +- dist/index.esm.js | 2 +- package.json | 2 +- src/helpers/getOptionsArray.js | 15 ++ src/processMarkdown.js | 108 ++++++---- 10 files changed, 328 insertions(+), 58 deletions(-) delete mode 100644 __tests__/addHeadingIds.integration.test.js create mode 100644 __tests__/processMarkdown.frontmatter.test.js create mode 100644 __tests__/processMarkdown.gfm.test.js create mode 100644 __tests__/processMarkdown.sanitization.test.js create mode 100644 __tests__/processMarkdown.test.js create mode 100644 src/helpers/getOptionsArray.js diff --git a/__tests__/addHeadingIds.integration.test.js b/__tests__/addHeadingIds.integration.test.js deleted file mode 100644 index 486ae4a..0000000 --- a/__tests__/addHeadingIds.integration.test.js +++ /dev/null @@ -1,14 +0,0 @@ -import { processMarkdown } from '../dist/index.cjs'; - -describe('addHeadingIds with actual Markdown', () => { - it('should add IDs to headings in Markdown content', async () => { - const markdown = `# First Heading\n## Second Heading`; - const options = { addHeadingIds: true }; - - const result = await processMarkdown(markdown, options); - const htmlOutput = result.contentHtml; - - expect(htmlOutput).toContain('

First Heading

'); - expect(htmlOutput).toContain('

Second Heading

'); - }); -}); diff --git a/__tests__/processMarkdown.frontmatter.test.js b/__tests__/processMarkdown.frontmatter.test.js new file mode 100644 index 0000000..793946d --- /dev/null +++ b/__tests__/processMarkdown.frontmatter.test.js @@ -0,0 +1,25 @@ +import { processMarkdown } from '../dist/index.cjs'; + +describe('front matter processing', () => { + it('should extract various data types in front matter', async () => { + const markdown = `--- +title: "Title" +number: 123 +array: [1, 2, 3] +object: { key: 'value' } +--- +Content`; + const result = await processMarkdown(markdown); + expect(result.frontMatter).toEqual({ title: "Title", number: 123, array: [1, 2, 3], object: { key: 'value' } }); + }); + + it('should correctly extract front matter', async () => { + const markdown = `--- +title: "Test Title" +--- +Content goes here.`; + const result = await processMarkdown(markdown); + expect(result.frontMatter).toEqual({ title: "Test Title" }); + expect(result.contentHtml).toContain('

Content goes here.

'); + }); +}) \ No newline at end of file diff --git a/__tests__/processMarkdown.gfm.test.js b/__tests__/processMarkdown.gfm.test.js new file mode 100644 index 0000000..3b84d5e --- /dev/null +++ b/__tests__/processMarkdown.gfm.test.js @@ -0,0 +1,18 @@ +import { processMarkdown } from '../dist/index.cjs'; + +describe('github flavoured markdown plugin (gfm)', () => { + it('should convert markdown tables to HTML tables', async () => { + const markdown = `| Header1 | Header2 |\n| ------- | ------- |\n| Cell1 | Cell2 |`; + const result = await processMarkdown(markdown); + expect(result.contentHtml).toContain(''); + expect(result.contentHtml).toContain(''); + expect(result.contentHtml).toContain(''); + }); + + it('should process GFM correctly', async () => { + const markdown = `This is ~~strikethrough~~ and **bold HTML**`; + const result = await processMarkdown(markdown); + expect(result.contentHtml).toContain('strikethrough'); + expect(result.contentHtml).toContain('bold HTML'); + }); +}) \ No newline at end of file diff --git a/__tests__/processMarkdown.sanitization.test.js b/__tests__/processMarkdown.sanitization.test.js new file mode 100644 index 0000000..96d7eb2 --- /dev/null +++ b/__tests__/processMarkdown.sanitization.test.js @@ -0,0 +1,9 @@ +import { processMarkdown } from '../dist/index.cjs'; + +describe('processMarkdown sanitization', () => { + it('should sanitize script tags in HTML', async () => { + const markdown = ``; + const result = await processMarkdown(markdown); + expect(result.contentHtml).not.toContain('
Header1Cell1