Skip to content

Commit 084fe4a

Browse files
committed
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
1 parent e108d4d commit 084fe4a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/ace-core/src/scripts/ace-extraction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ ace.getHeadings = function() {
137137

138138
hxElems.forEach(function(hx) {
139139
headings.push({
140-
html: hx.innerHTML,
140+
html: hx.textContent,
141141
level: +hx.localName.slice(1)
142142
});
143143
});

packages/ace-core/src/scripts/ace-extraction.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ describe('extracting headings', () => {
194194
expect(results[0].html).toBe('title 1');
195195
expect(results[0].level).toBe(1);
196196
});
197+
198+
test('complex h1', async () => {
199+
const results = await run('getHeadings', '<h1>title 1 <a href="#foo">link</a></h1>');
200+
expect(results.length).toBe(1);
201+
expect(results[0].html).toBe('title 1 link');
202+
expect(results[0].level).toBe(1);
203+
});
197204
});
198205

199206
describe('extracting iframes', () => {

0 commit comments

Comments
 (0)