Skip to content

Commit

Permalink
resolves #794 decode section title in outline
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Oct 3, 2023
1 parent 15b4562 commit 3efd131
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
20 changes: 18 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@
"@asciidoctor/docbook-converter": "2.0.0",
"@orcid/bibtex-parse-js": "0.0.25",
"asciidoctor-kroki": "^0.17.0",
"html-entities": "^2.4.0",
"js-yaml": "^4.1.0",
"querystring": "^0.2.1",
"tty-browserify": "^0.0.1",
Expand Down
3 changes: 2 additions & 1 deletion src/tableOfContentsProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from 'vscode'
import { decode as htmlEntitiesDecode } from 'html-entities'
import { githubSlugifier, Slug } from './slugify'
import { SkinnyTextDocument } from './util/document'
import { AsciidocLoader } from './asciidocLoader'
Expand Down Expand Up @@ -48,7 +49,7 @@ export class TableOfContentsProvider {
}
return {
slug: new Slug(section.getId()),
text: section.getTitle(),
text: htmlEntitiesDecode(section.getTitle()),
level: section.getLevel(),
line: lineNumber,
location: new vscode.Location(textDocument.uri,
Expand Down
34 changes: 34 additions & 0 deletions src/test/tableOfContentsProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,38 @@ content`
const documentTitleEntry = toc.find((entry) => entry.text === 'test' && entry.line === 0)
assert.deepStrictEqual(documentTitleEntry !== undefined, true, 'should include the document title in the TOC')
})

test('Should properly decode HTML entities', async () => {
const doc = new InMemoryDocument(vscode.Uri.file('test.adoc'), `= Title
== Dungeons & Dragons
== Let's do it!`)
const provider = new TableOfContentsProvider(doc, new AsciidocLoader(
new AsciidoctorConfig(),
new AsciidoctorExtensions(AsciidoctorExtensionsSecurityPolicyArbiter.activate(extensionContext)),
new AsciidoctorDiagnostic('test')
))

const toc = await provider.getToc()
const ddEntry = toc.find((t) => t.text === 'Dungeons & Dragons')
assert.strictEqual(ddEntry !== null, true, 'should find an entry with title: Dungeons & Dragons')
assert.deepStrictEqual({
text: ddEntry.text,
slug: ddEntry.slug.value,
}, {
text: 'Dungeons & Dragons',
slug: '_dungeons_dragons',
})
console.log(toc.map((t) => t.text))
const ldiEntry = toc.find((t) => t.text === 'Let’s do it!')
assert.strictEqual(ldiEntry !== null, true, 'should find an entry with title: Let’s do it!')
assert.deepStrictEqual({
text: ldiEntry.text,
slug: ldiEntry.slug.value,
}, {
text: 'Let’s do it!',
slug: '_lets_do_it',
})
})
})

0 comments on commit 3efd131

Please sign in to comment.