From e21b7929744e83ee970aa1228138cec8eaca9451 Mon Sep 17 00:00:00 2001 From: Alexander Schwartz Date: Fri, 10 Feb 2023 15:44:48 +0100 Subject: [PATCH] Handle Markdown style section headings like regular AsciiDoc section headings Resolves #19 --- .../lib/produce-aggregate-document.js | 2 +- .../test/produce-aggregate-documents-test.js | 4 ++++ .../markdown-style-section-headings/data.yml | 12 ++++++++++ .../expects/the-component.adoc | 22 +++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 packages/assembler/test/scenarios/markdown-style-section-headings/data.yml create mode 100644 packages/assembler/test/scenarios/markdown-style-section-headings/expects/the-component.adoc diff --git a/packages/assembler/lib/produce-aggregate-document.js b/packages/assembler/lib/produce-aggregate-document.js index fc68563..3a4025a 100644 --- a/packages/assembler/lib/produce-aggregate-document.js +++ b/packages/assembler/lib/produce-aggregate-document.js @@ -315,7 +315,7 @@ function aggregateAsciiDoc ( return } let blockStyle = sectionMergeStrategy === 'discrete' ? 'discrete' : undefined - lines[idx] = lines[idx].replace(/^=+ (.+)/, (_, rest) => { + lines[idx] = lines[idx].replace(/^[=#]+ (.+)/, (_, rest) => { let targetMarkerLength = block.level + 1 + level + (enclosed ? 1 : 0) if (targetMarkerLength > 6) { targetMarkerLength = 6 diff --git a/packages/assembler/test/produce-aggregate-documents-test.js b/packages/assembler/test/produce-aggregate-documents-test.js index 9bd49ad..dc6572f 100644 --- a/packages/assembler/test/produce-aggregate-documents-test.js +++ b/packages/assembler/test/produce-aggregate-documents-test.js @@ -90,6 +90,10 @@ describe('produceAggregateDocuments()', () => { await runScenario('process-asciidoc-table-cell', __dirname) }) + it('should process markdown section headings', async () => { + await runScenario('markdown-style-section-headings', __dirname) + }) + it('should remove source-highlighter attribute on aggregate document if not specified', async () => { const { loadAsciiDoc, contentCatalog, assemblerConfig } = await loadScenario('insert-page', __dirname) const aggregateDocuments = await produceAggregateDocuments(loadAsciiDoc, contentCatalog, assemblerConfig) diff --git a/packages/assembler/test/scenarios/markdown-style-section-headings/data.yml b/packages/assembler/test/scenarios/markdown-style-section-headings/data.yml new file mode 100644 index 0000000..321a32d --- /dev/null +++ b/packages/assembler/test/scenarios/markdown-style-section-headings/data.yml @@ -0,0 +1,12 @@ +name: the-component +version: '1.0' +title: The Component +navigation: + items: + - content: xref:the-page.adoc[The Page Title] +files: +- relative: the-page.adoc + contents: |- + = The Page Title + + ## First Section diff --git a/packages/assembler/test/scenarios/markdown-style-section-headings/expects/the-component.adoc b/packages/assembler/test/scenarios/markdown-style-section-headings/expects/the-component.adoc new file mode 100644 index 0000000..ceab70c --- /dev/null +++ b/packages/assembler/test/scenarios/markdown-style-section-headings/expects/the-component.adoc @@ -0,0 +1,22 @@ += The Component +v1.0 +:doctype: book +:page-component-name: the-component +:page-component-version: 1.0 +:page-version: {page-component-version} +:page-component-display-version: 1.0 +:page-component-title: The Component + +:docname: the-page +:page-module: ROOT +:page-relative-src-path: the-page.adoc +:page-origin-url: https://github.com/acme/the-component +:page-origin-start-path: +:page-origin-refname: v1.0 +:page-origin-reftype: branch +:page-origin-refhash: a00000000000000000000000000000000000000z +[#the-page:::] +== The Page Title + +[discrete#the-page:::_first_section] +=== First Section -- GitLab