Skip to content

Commit

Permalink
add doc role when the asciidoc page is used in an antora context (#845)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Grossetie <[email protected]>
Co-authored-by: Lasse Knudsen <[email protected]>
  • Loading branch information
3 people authored Feb 8, 2024
1 parent 72cc696 commit 595fc27
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/asciidoctorWebViewConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class AsciidoctorWebViewConverter {
<body${node.getId() ? ` id="${node.getId()}"` : ''} class="${this.getBodyCssClasses(node)}">
${headerDocinfo}
${this.getDocumentHeader(node)}
<div id="content">
<div id="content"${this.antoraDocumentContext ? ' class="doc"' : ''}>
${node.getContent()}
</div>
${this.generateFootnotes(node)}
Expand Down
47 changes: 46 additions & 1 deletion src/test/asciidoctorWebViewConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ async function testAsciidoctorWebViewConverter (
assert.strictEqual(html, expected)
}

async function testAsciidoctorWebViewConverterStandalone (
input: string,
antoraDocumentContext: AntoraDocumentContext | undefined,
expected: string,
root: vscode.Uri,
pathSegments: string[]
) {
const file = await vscode.workspace.openTextDocument(vscode.Uri.joinPath(root, ...pathSegments))
const asciidoctorWebViewConverter = new AsciidoctorWebViewConverter(
file,
new TestWebviewResourceProvider(),
2,
false,
new TestAsciidocContributions(),
new AsciidocPreviewConfigurationManager().loadAndCacheConfiguration(file.uri),
antoraDocumentContext,
undefined
)
const html = processor.convert(input, { converter: asciidoctorWebViewConverter, standalone: true })
html.includes(expected)
}

suite('AsciidoctorWebViewConverter', async () => {
const createdFiles: vscode.Uri[] = []
suiteSetup(async () => {
Expand Down Expand Up @@ -124,9 +146,32 @@ link:help.adoc[]
<p><a href="full.adoc" class="bare action button" data-href="full.adoc">full.adoc</a></p>
</div>`,
},
{
title: 'Should not add role doc to content when no Antora context is provided',
filePath: ['asciidoctorWebViewConverterTest.adoc'],
input: '= Test Document',
antoraDocumentContext: undefined, // Antora not enabled
expected: '<div id="content">',
standalone: true,
},
{
title: 'Add role doc to content when Antora context is provided',
filePath: ['docs', 'modules', 'ROOT', 'pages', 'dummy.adoc'],
input: '= Test Document',
antoraDocumentContext: createAntoraDocumentContextStub(undefined),
expected: '<div id="content" class="doc">',
standalone: true,
},

]

for (const testCase of testCases) {
test(testCase.title, async () => testAsciidoctorWebViewConverter(testCase.input, testCase.antoraDocumentContext, testCase.expected, workspaceUri, testCase.filePath))
if (testCase.standalone) {
test(testCase.title, async () => testAsciidoctorWebViewConverterStandalone(
testCase.input, testCase.antoraDocumentContext, testCase.expected, workspaceUri, testCase.filePath
))
} else {
test(testCase.title, async () => testAsciidoctorWebViewConverter(testCase.input, testCase.antoraDocumentContext, testCase.expected, workspaceUri, testCase.filePath))
}
}
})

0 comments on commit 595fc27

Please sign in to comment.