From 30e5c0d71b51490d56f7300f0a9665de83148c2c Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Tue, 19 Mar 2024 14:58:33 +0700 Subject: [PATCH] fix: trim comments before generating index (#137) --- workspace/aubade/src/core/index.js | 2 +- workspace/aubade/src/core/index.spec.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/workspace/aubade/src/core/index.js b/workspace/aubade/src/core/index.js index 9ee2861..ec61cde 100644 --- a/workspace/aubade/src/core/index.js +++ b/workspace/aubade/src/core/index.js @@ -29,7 +29,7 @@ export function parse(source) { get table() { /** @type {import('../types.js').AubadeTable[]} */ const table = []; - for (const line of stuffed.split('\n')) { + for (const line of stuffed.replace(//g, '').split('\n')) { const match = line.trim().match(/^(#{2,4}) (.+)/); if (!match) continue; diff --git a/workspace/aubade/src/core/index.spec.js b/workspace/aubade/src/core/index.spec.js index af4b5cf..8027540 100644 --- a/workspace/aubade/src/core/index.spec.js +++ b/workspace/aubade/src/core/index.spec.js @@ -349,6 +349,29 @@ something here title: 'sub-plot', }); }); +suites['construct/table']('trim comments correctly', () => { + const { metadata } = core.parse( + ` +--- +title: headings inside comments +--- + +## simple heading + +### story + + + +### sub-story + +### sub-plot + `.trim(), + ); + + assert.equal(metadata.table.length, 4); +}); suites['parse/']('parse markdown contents', () => { const { body, metadata } = core.parse(