From bf80444375987e59158dd3144464a57b11b64791 Mon Sep 17 00:00:00 2001 From: Xavier Stouder Date: Sat, 9 May 2026 18:02:15 +0200 Subject: [PATCH 1/3] fix: allow to override h1 to h6 through discovered components Fixes: https://github.com/edge-js/edge-markdown/issues/1 Signed-off-by: Xavier Stouder --- src/utils.ts | 5 ++--- tests/fixtures/views/components/markdown/h6.edge | 4 ++++ tests/markdown.spec.ts | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/views/components/markdown/h6.edge diff --git a/src/utils.ts b/src/utils.ts index c6da8bc..39bb86b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -9,7 +9,6 @@ import { type VFile } from 'vfile' import { type Edge } from 'edge.js' -import string from '@poppinss/string' import { htmlEscape } from 'escape-goat' import { find, html } from 'property-information' import { type VoidHtmlTags, voidHtmlTags } from 'html-tags' @@ -112,8 +111,8 @@ export function discoverMarkdownComponents(edge: Edge, prefix: string) { /** * Collect components with the tagName. */ - const tagName = componentName.replace(new RegExp(componentsBasePath), '') - result[string.dashCase(tagName)] = componentName + const tagName = componentName.replace(new RegExp(componentsBasePath), '').replace(/_/g, '-') + result[tagName] = componentName return result }, {}) } diff --git a/tests/fixtures/views/components/markdown/h6.edge b/tests/fixtures/views/components/markdown/h6.edge new file mode 100644 index 0000000..b473097 --- /dev/null +++ b/tests/fixtures/views/components/markdown/h6.edge @@ -0,0 +1,4 @@ +

+ @markdownSlot() +

+ diff --git a/tests/markdown.spec.ts b/tests/markdown.spec.ts index cede005..ef2e700 100644 --- a/tests/markdown.spec.ts +++ b/tests/markdown.spec.ts @@ -350,6 +350,22 @@ Here is a paragraph with a [link](./foo)\` assert.notInclude(result.content, 'Section content') }) + test('use h6 component to override h6 rendering', async ({ assert }) => { + const edge = new Edge() + edge.mount(join(import.meta.dirname, 'fixtures/views')) + edge.use(edgeMarkdown, {}) + + const renderer = edge.share({}) + const result = await renderer.getState().$markdown.render({ + content: dedent` + ###### Section title + `, + }) + + assert.include(result.content, 'class="custom-h6"') + assert.notMatch(result.content, / { const edge = new Edge() edge.mount(join(import.meta.dirname, 'fixtures/views')) From 14418e771fe0e98b3177a4d09b7323cbd16f51bd Mon Sep 17 00:00:00 2001 From: Xavier Stouder Date: Sat, 9 May 2026 18:08:59 +0200 Subject: [PATCH 2/3] chore: remove unused dependency --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 064a52b..d2f3286 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "typescript": "^6.0.2" }, "dependencies": { - "@poppinss/string": "^1.7.1", "@shikijs/rehype": "^4.0.2", "@shikijs/transformers": "^4.0.2", "escape-goat": "^4.0.0", From c92ba3fcb05945e06f2a64d83c9e0aab11de35a4 Mon Sep 17 00:00:00 2001 From: Xavier Stouder Date: Sun, 31 May 2026 20:34:26 +0200 Subject: [PATCH 3/3] fix: handle h1 to h6 a special case when discovering components --- package.json | 1 + src/utils.ts | 7 +++++-- tests/fixtures/views/components/markdown/H5.edge | 4 ++++ tests/markdown.spec.ts | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/views/components/markdown/H5.edge diff --git a/package.json b/package.json index d2f3286..064a52b 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "typescript": "^6.0.2" }, "dependencies": { + "@poppinss/string": "^1.7.1", "@shikijs/rehype": "^4.0.2", "@shikijs/transformers": "^4.0.2", "escape-goat": "^4.0.0", diff --git a/src/utils.ts b/src/utils.ts index 39bb86b..a79f247 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -9,6 +9,7 @@ import { type VFile } from 'vfile' import { type Edge } from 'edge.js' +import string from '@poppinss/string' import { htmlEscape } from 'escape-goat' import { find, html } from 'property-information' import { type VoidHtmlTags, voidHtmlTags } from 'html-tags' @@ -111,8 +112,10 @@ export function discoverMarkdownComponents(edge: Edge, prefix: string) { /** * Collect components with the tagName. */ - const tagName = componentName.replace(new RegExp(componentsBasePath), '').replace(/_/g, '-') - result[tagName] = componentName + const tagName = componentName.replace(new RegExp(componentsBasePath), '') + const lowerTagName = tagName.toLowerCase() + const isHeadingTag = /^h[1-6]$/.test(lowerTagName) + result[isHeadingTag ? lowerTagName : string.dashCase(tagName)] = componentName return result }, {}) } diff --git a/tests/fixtures/views/components/markdown/H5.edge b/tests/fixtures/views/components/markdown/H5.edge new file mode 100644 index 0000000..7c0754f --- /dev/null +++ b/tests/fixtures/views/components/markdown/H5.edge @@ -0,0 +1,4 @@ +

+ @markdownSlot() +

+ diff --git a/tests/markdown.spec.ts b/tests/markdown.spec.ts index ef2e700..2cf5df7 100644 --- a/tests/markdown.spec.ts +++ b/tests/markdown.spec.ts @@ -366,6 +366,22 @@ Here is a paragraph with a [link](./foo)\` assert.notMatch(result.content, / { + const edge = new Edge() + edge.mount(join(import.meta.dirname, 'fixtures/views')) + edge.use(edgeMarkdown, {}) + + const renderer = edge.share({}) + const result = await renderer.getState().$markdown.render({ + content: dedent` + ##### Section title + `, + }) + + assert.include(result.content, 'class="custom-h5"') + assert.notMatch(result.content, / { const edge = new Edge() edge.mount(join(import.meta.dirname, 'fixtures/views'))