From 084fe4a516f911f94f32072824b9e0e6324d62a0 Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Thu, 21 Dec 2017 01:40:42 +0100 Subject: [PATCH] fix(outlines): only use headings text content in the outline The headings extraction script now returns the elements `textContent` property instead of their `innerHTML`. A smarter processing could be devised in a future version: - detect an empty content and report a dummy text - trim long content Fixes #129 --- packages/ace-core/src/scripts/ace-extraction.js | 2 +- packages/ace-core/src/scripts/ace-extraction.test.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/ace-core/src/scripts/ace-extraction.js b/packages/ace-core/src/scripts/ace-extraction.js index 8857f08c..5671ad66 100644 --- a/packages/ace-core/src/scripts/ace-extraction.js +++ b/packages/ace-core/src/scripts/ace-extraction.js @@ -137,7 +137,7 @@ ace.getHeadings = function() { hxElems.forEach(function(hx) { headings.push({ - html: hx.innerHTML, + html: hx.textContent, level: +hx.localName.slice(1) }); }); diff --git a/packages/ace-core/src/scripts/ace-extraction.test.js b/packages/ace-core/src/scripts/ace-extraction.test.js index 7bce8e68..c8a08e1d 100644 --- a/packages/ace-core/src/scripts/ace-extraction.test.js +++ b/packages/ace-core/src/scripts/ace-extraction.test.js @@ -194,6 +194,13 @@ describe('extracting headings', () => { expect(results[0].html).toBe('title 1'); expect(results[0].level).toBe(1); }); + + test('complex h1', async () => { + const results = await run('getHeadings', '

title 1 link

'); + expect(results.length).toBe(1); + expect(results[0].html).toBe('title 1 link'); + expect(results[0].level).toBe(1); + }); }); describe('extracting iframes', () => {