Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #794 decode section title in outline #795

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
})
})
})