Commit f2c431b9 authored by Fred Chasen's avatar Fred Chasen

Added hyper ignore, only, and encoding options

parent e927d9b4
Pipeline #683 skipped
......@@ -27,7 +27,10 @@ vivliostyle-electron ./path/to/index.html -o result.pdf
-w, --width [size] Print to Page Width [width]
-h --height [size] Print to Page Height [weight]
-m, --page-margin [margin] Print with margin [margin]
-n, --hyphenate [lang] Hyphenate with language [language] such as "en-us"
-n, --hyphenate [lang] Hyphenate with language [language], defaults to "en-us"
-hi, --hypher_ignore [str] Ignore passed element selectors, such as ".class_to_ignore, h1"
-ho, --hypher_only [str] Only hyphenate passed elements selector, such as ".hyphenate, aside"
-e, --encoding [type] Set the encoding of the input html, defaults to "utf-8"
-t, --timeout [ms] Set a max timeout of [ms]
```
......
......@@ -17,7 +17,10 @@ program
.option('-w, --width [size]', 'Print to Page Width [width]')
.option('-h --height [size]', 'Print to Page Height [weight]')
.option('-m, --page-margin [margin]', 'Print with margin [margin]')
.option('-n, --hyphenate [lang]', 'Hyphenate with language [language] such as "en-us"')
.option('-n, --hyphenate [lang]', 'Hyphenate with language [language], defaults to "en-us"')
.option('-hi, --hypher_ignore [str]', 'Ignore passed element selectors, such as ".class_to_ignore, h1"')
.option('-ho, --hypher_only [str]', 'Only hyphenate passed elements selector, such as ".hyphenate, aside"')
.option('-e, --encoding [type]', 'Set the encoding of the input html, defaults to "utf-8"')
.option('-t, --timeout [ms]', 'Set a max timeout of [ms]')
.parse(process.argv);
......@@ -35,6 +38,7 @@ var output = program.output ? path.resolve(dir, program.output) : './' + path.ba
var render;
var hyphenate;
var hyphenateOptions;
var tmpPath;
......@@ -43,9 +47,14 @@ if (path.extname(relativePath) != ('.html' || '.xhtml')) {
}
if (program.hyphenate) {
hyphenateOptions = {
ignore: program.hypher_ignore || undefined,
only: program.hypher_only || undefined,
encoding: program.encoding || undefined
}
tmpPath = relativePath.replace(".xhtml", ".hyphenated.xhtml").replace(".html", ".hyphenated.html");
hyphenate = new Hyphenate(program.hyphenate);
hyphenate.process(relativePath, tmpPath);
hyphenate.process(relativePath, tmpPath, hyphenateOptions);
}
......
......@@ -18,9 +18,9 @@ Hyphenate.prototype.hyphenateText = function (text) {
}).join('');
};
Hyphenate.prototype.process = function (input, output, encoding) {
var contents = fs.readFileSync(input, encoding || 'utf8');
var hyphenated = eachTextNode(contents, this.hyphenateText.bind(this));
Hyphenate.prototype.process = function (input, output, encoding, options) {
var contents = fs.readFileSync(input, options.encoding || 'utf8');
var hyphenated = eachTextNode(contents, this.hyphenateText.bind(this), options);
if (output) {
fs.writeFileSync(output, hyphenated, encoding || 'utf8');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment