Support custom CSS for preview.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
d0cd0f8fcd
commit
6fef748039
|
@ -179,6 +179,11 @@
|
|||
"type": "boolean",
|
||||
"default": false,
|
||||
"markdownDescription": "Display images in in preview.\n\nIf image display is not needed, turn off this option to improve preview performance."
|
||||
},
|
||||
"texinfo.preview.customCSS": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"markdownDescription": "URI of custom CSS for preview.\n\nA good example is https://www.gnu.org/software/gnulib/manual.css"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -64,6 +64,10 @@ export default class Options implements vscode.Disposable {
|
|||
return Options.instance.getBoolean('preview.displayImage');
|
||||
}
|
||||
|
||||
static get customCSS() {
|
||||
return Options.instance.getString('preview.customCSS');
|
||||
}
|
||||
|
||||
static clear() {
|
||||
Options.singleton = undefined;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
* @license MIT
|
||||
*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import Logger from '../logger';
|
||||
import Options from '../options';
|
||||
import DOM from './dom';
|
||||
import { exec } from './misc';
|
||||
|
@ -20,6 +22,25 @@ export default class Converter {
|
|||
*/
|
||||
private readonly options = ['-o', '-', '--no-split', '--html'];
|
||||
|
||||
private includeCustomCSS(cssFileURI: string) {
|
||||
try {
|
||||
const uri = vscode.Uri.parse(cssFileURI, true);
|
||||
switch (uri.scheme) {
|
||||
case 'file':
|
||||
this.options.push(`--css-include=${uri.path}`);
|
||||
break;
|
||||
case 'http':
|
||||
case 'https':
|
||||
this.options.push(`--css-ref=${uri.toString()}`);
|
||||
break;
|
||||
default:
|
||||
throw URIError;
|
||||
}
|
||||
} catch (e) {
|
||||
Logger.log(`Cannot load custom CSS. Invalid URI: '${cssFileURI}'`);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly path: string,
|
||||
private readonly imgTransformer?: Operator<string>,
|
||||
|
@ -29,6 +50,7 @@ export default class Converter {
|
|||
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}`);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue