Skip to content

Commit

Permalink
Support .asciidoctorconfig at root of the workspace
Browse files Browse the repository at this point in the history
part of asciidoctor#380

TODO in this PR:
- provide test

TODO in other iteration:
- support other places
- support `.asciidoctorconfig.adoc`
- provide cache mechanism
  • Loading branch information
apupier committed Sep 30, 2022
1 parent 605433b commit a188efb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Improvements

- support .asciidoctorconfig at root of the workspace by @apupier (#380)

### Bug fixes

- fix the logic that detects if `asciidoctor-pdf` and/or `bundler` are available in the `PATH`
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ Here's an example of how to use the [asciidoctor-emoji](https://github.com/mogzt
![Asciidoctor.js Emoji extension enabled!](images/asciidoctor-vscode-emoji-ext.png)

### Asciidoctor Config File

To provide a common set of variables when rendering the preview, the extension reads an `.asciidoctorconfig` configuration file. Use this to optimize the preview when the project contains a document that is split out to multiple include-files.

It is inspired by the implementation provided in [IntelliJ AsciiDoc Plugin](https://intellij-asciidoc-plugin.ahus1.de/docs/users-guide/features/advanced/asciidoctorconfig-file.html) and reused in [Eclipse AsciiDoc plugin](https://github.com/de-jcup/eclipse-asciidoctor-editor/wiki/Asciidoctor-configfiles).

The current scope is limited to an `.asciidoctorconfig` configuration file provided at the root of the workspace.

## Extension Settings

This extension contributes the following settings:
Expand Down
12 changes: 12 additions & 0 deletions src/asciidocParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from 'vscode'
import * as fs from 'fs'
import * as path from 'path'
import { AsciidoctorWebViewConverter } from './asciidoctorWebViewConverter'
import { Asciidoctor } from '@asciidoctor/core'
Expand Down Expand Up @@ -172,6 +173,17 @@ export class AsciidocParser {
}

try {
const workspaceFolder = vscode.workspace.getWorkspaceFolder(doc.uri)
if (workspaceFolder !== undefined) {
const asciiDoctorConfig = vscode.Uri.joinPath(workspaceFolder.uri, '.asciidoctorconfig')
if (fs.existsSync(asciiDoctorConfig.fsPath)) {
const asciiDoctorConfigContent = await vscode.workspace.fs.readFile(asciiDoctorConfig)
text =
':asciidoctorconfigdir: ' + asciiDoctorConfig.fsPath + '\n\n' +
asciiDoctorConfigContent + '\n\n' +
text
}
}
const document = processor.load(text, options)
const blocksWithLineNumber = document.findBy(function (b) {
return typeof b.getLineNumber() !== 'undefined'
Expand Down

0 comments on commit a188efb

Please sign in to comment.