Skip to content

Commit ec45b70

Browse files
lask79ggrossetielasse-knudsen
committed
add doc role when the asciidoc page is used in an antora context (asciidoctor#845)
Co-authored-by: Guillaume Grossetie <[email protected]> Co-authored-by: Lasse Knudsen <[email protected]>
1 parent 72cc696 commit ec45b70

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/asciidoctorWebViewConverter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class AsciidoctorWebViewConverter {
189189
<body${node.getId() ? ` id="${node.getId()}"` : ''} class="${this.getBodyCssClasses(node)}">
190190
${headerDocinfo}
191191
${this.getDocumentHeader(node)}
192-
<div id="content">
192+
<div id="content"${this.antoraDocumentContext ? ' class="doc"' : ''}>
193193
${node.getContent()}
194194
</div>
195195
${this.generateFootnotes(node)}

src/test/asciidoctorWebViewConverter.test.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ async function testAsciidoctorWebViewConverter (
5858
assert.strictEqual(html, expected)
5959
}
6060

61+
async function testAsciidoctorWebViewConverterStandalone (
62+
input: string,
63+
antoraDocumentContext: AntoraDocumentContext | undefined,
64+
expected: string,
65+
root: vscode.Uri,
66+
pathSegments: string[]
67+
) {
68+
const file = await vscode.workspace.openTextDocument(vscode.Uri.joinPath(root, ...pathSegments))
69+
const asciidoctorWebViewConverter = new AsciidoctorWebViewConverter(
70+
file,
71+
new TestWebviewResourceProvider(),
72+
2,
73+
false,
74+
new TestAsciidocContributions(),
75+
new AsciidocPreviewConfigurationManager().loadAndCacheConfiguration(file.uri),
76+
antoraDocumentContext,
77+
undefined
78+
)
79+
const html = processor.convert(input, { converter: asciidoctorWebViewConverter, standalone: true })
80+
html.includes(expected)
81+
}
82+
6183
suite('AsciidoctorWebViewConverter', async () => {
6284
const createdFiles: vscode.Uri[] = []
6385
suiteSetup(async () => {
@@ -124,9 +146,32 @@ link:help.adoc[]
124146
<p><a href="full.adoc" class="bare action button" data-href="full.adoc">full.adoc</a></p>
125147
</div>`,
126148
},
149+
{
150+
title: 'Should not add role doc to content when no Antora context is provided',
151+
filePath: ['asciidoctorWebViewConverterTest.adoc'],
152+
input: '= Test Document',
153+
antoraDocumentContext: undefined, // Antora not enabled
154+
expected: '<div id="content">',
155+
standalone: true,
156+
},
157+
{
158+
title: 'Add role doc to content when Antora context is provided',
159+
filePath: ['docs', 'modules', 'ROOT', 'pages', 'dummy.adoc'],
160+
input: '= Test Document',
161+
antoraDocumentContext: createAntoraDocumentContextStub(undefined),
162+
expected: '<div id="content" class="doc">',
163+
standalone: true,
164+
},
165+
127166
]
128167

129168
for (const testCase of testCases) {
130-
test(testCase.title, async () => testAsciidoctorWebViewConverter(testCase.input, testCase.antoraDocumentContext, testCase.expected, workspaceUri, testCase.filePath))
169+
if (testCase.standalone) {
170+
test(testCase.title, async () => testAsciidoctorWebViewConverterStandalone(
171+
testCase.input, testCase.antoraDocumentContext, testCase.expected, workspaceUri, testCase.filePath
172+
))
173+
} else {
174+
test(testCase.title, async () => testAsciidoctorWebViewConverter(testCase.input, testCase.antoraDocumentContext, testCase.expected, workspaceUri, testCase.filePath))
175+
}
131176
}
132177
})

0 commit comments

Comments
 (0)