Make converter reentrant.
This commit is contained in:
parent
2d08ad4b88
commit
80674a20c3
|
@ -81,8 +81,8 @@ export default class PreviewContext {
|
||||||
this.pendingUpdate = false;
|
this.pendingUpdate = false;
|
||||||
// Inform the user that the preview is updating if `makeinfo` takes too long.
|
// Inform the user that the preview is updating if `makeinfo` takes too long.
|
||||||
setTimeout(() => this.updating && this.updateTitle(), 500);
|
setTimeout(() => this.updating && this.updateTitle(), 500);
|
||||||
const { data, error } = await new Converter(this.document.fileName, this.imageTransformer, this.script)
|
const { data, error } = await new Converter(this.document.fileName)
|
||||||
.convert();
|
.convertToHtml(this.imageTransformer, this.script);
|
||||||
if (error) {
|
if (error) {
|
||||||
Logger.log(error);
|
Logger.log(error);
|
||||||
Diagnosis.update(this.document, error);
|
Diagnosis.update(this.document, error);
|
||||||
|
|
|
@ -13,25 +13,20 @@ import { exec } from './misc';
|
||||||
import { Operator } from './types';
|
import { Operator } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Texinfo to HTML converter.
|
* Converter which converts file from Texinfo to other formats.
|
||||||
*/
|
*/
|
||||||
export default class Converter {
|
export default class Converter {
|
||||||
|
|
||||||
/**
|
private includeCustomCSS(cssFileURI: string, options: string[]) {
|
||||||
* The options to be passed to the `makeinfo` command.
|
|
||||||
*/
|
|
||||||
private readonly options = ['-o', '-', '--no-split', '--html'];
|
|
||||||
|
|
||||||
private includeCustomCSS(cssFileURI: string) {
|
|
||||||
try {
|
try {
|
||||||
const uri = vscode.Uri.parse(cssFileURI, true);
|
const uri = vscode.Uri.parse(cssFileURI, true);
|
||||||
switch (uri.scheme) {
|
switch (uri.scheme) {
|
||||||
case 'file':
|
case 'file':
|
||||||
this.options.push(`--css-include=${uri.path}`);
|
options.push(`--css-include=${uri.path}`);
|
||||||
break;
|
break;
|
||||||
case 'http':
|
case 'http':
|
||||||
case 'https':
|
case 'https':
|
||||||
this.options.push(`--css-ref=${uri.toString()}`);
|
options.push(`--css-ref=${uri.toString()}`);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw URIError;
|
throw URIError;
|
||||||
|
@ -41,26 +36,24 @@ export default class Converter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(private readonly path: string) {}
|
||||||
private readonly path: string,
|
|
||||||
private readonly imgTransformer?: Operator<string>,
|
|
||||||
private readonly insertScript?: string,
|
|
||||||
) {
|
|
||||||
Options.noHeaders && this.options.push('--no-headers');
|
|
||||||
Options.force && this.options.push('--force');
|
|
||||||
Options.noValidation && this.options.push('--no-validate');
|
|
||||||
Options.noWarnings && this.options.push('--no-warn');
|
|
||||||
Options.customCSS && this.includeCustomCSS(Options.customCSS);
|
|
||||||
this.options.push(`--error-limit=${Options.errorLimit}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
async convert() {
|
async convertToHtml(
|
||||||
const result = await exec(Options.makeinfo, this.options.concat(this.path), Options.maxSize);
|
imgTransformer?: Operator<string>,
|
||||||
|
insertScript?: string,
|
||||||
|
) {
|
||||||
|
const options = ['-o', '-', '--no-split', '--html', `--error-limit=${Options.errorLimit}`];
|
||||||
|
Options.noHeaders && options.push('--no-headers');
|
||||||
|
Options.force && options.push('--force');
|
||||||
|
Options.noValidation && options.push('--no-validate');
|
||||||
|
Options.noWarnings && options.push('--no-warn');
|
||||||
|
Options.customCSS && this.includeCustomCSS(Options.customCSS, options);
|
||||||
|
const result = await exec(Options.makeinfo, options.concat(this.path), Options.maxSize);
|
||||||
if (result.data !== undefined) {
|
if (result.data !== undefined) {
|
||||||
// No worry about performance here, as the DOM is lazily initialized.
|
// No worry about performance here, as the DOM is lazily initialized.
|
||||||
const dom = new DOM(result.data);
|
const dom = new DOM(result.data);
|
||||||
this.imgTransformer && dom.transformImageUri(this.imgTransformer);
|
imgTransformer && dom.transformImageUri(imgTransformer);
|
||||||
this.insertScript && dom.insertScript(this.insertScript);
|
insertScript && dom.insertScript(insertScript);
|
||||||
result.data = dom.outerHTML;
|
result.data = dom.outerHTML;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in New Issue