-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
71 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as std from 'std'; | ||
import Asciidoctor from "build/asciidoctor-quickjs.js"; | ||
|
||
const _ = scriptArgs.shift(); | ||
const USAGE = `USAGE: ${_} [OPTIONS] [FILE|-] | ||
EXAMPLE: ${_} --safe=0 --doctype=\\"article\\" <<< include::partial.adoc[]` | ||
const die = (msg) => console.log(msg) + std.exit(1); | ||
const [file = ""] = scriptArgs.filter(arg => !arg.startsWith('-')); | ||
const options = Object.fromEntries(scriptArgs.filter(arg => arg.startsWith('-')) | ||
.map(arg => arg.split('=')).map(([k, ...v]) => [k.replace(/^-+/, ''), std.parseExtJSON(v.join('=') || '1')])); | ||
if (options.help) die(USAGE); | ||
std.err.puts(`converting ${file ? "file:" + file : 'stdin'} options:${JSON.stringify(options)}\n`); | ||
const body = file ? std.loadFile(file) : std.in.readAsString(); | ||
if (!body) die(USAGE); | ||
try { | ||
console.log(Asciidoctor().convert(body, options)); | ||
} catch (e) { | ||
console.log(e) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
/* global Asciidoctor */ | ||
import Asciidoctor from '../../build/asciidoctor-quickjs.js' | ||
const asciidoctor = Asciidoctor() | ||
// poor man mocha since QuickJS don't rely on NPM | ||
const expect = (obj) => ({to:{include(str){if(!obj.includes(str))throw `${obj} does not contain ${str}`}}}); | ||
const describe = (title, todo) => todo(console.log(`${title}`)); | ||
const it = (title, todo) => todo(console.log(` ${title}`)); | ||
|
||
const asciidoctor = Asciidoctor() | ||
const data = '= asciidoctor.js, AsciiDoc in JavaScript\n' + | ||
'Doc Writer <[email protected]>\n\n' + | ||
'Asciidoctor and Opal come together to bring\n' + | ||
'http://asciidoc.org[AsciiDoc] to the browser!.\n\n' + | ||
'== Technologies\n\n' + | ||
'* AsciiDoc\n' + | ||
'* Asciidoctor\n' + | ||
'* Opal\n\n' + | ||
'NOTE: That\'s all she wrote!!!\n\n' + | ||
'include::spec/fixtures/include.adoc[]' | ||
'Doc Writer <[email protected]>\n\n' + | ||
'Asciidoctor and Opal come together to bring\n' + | ||
'http://asciidoc.org[AsciiDoc] to the browser!.\n\n' + | ||
'== Technologies\n\n' + | ||
'* AsciiDoc\n' + | ||
'* Asciidoctor\n' + | ||
'* Opal\n\n' + | ||
'NOTE: That\'s all she wrote!!!\n\n' | ||
|
||
const options = { safe: 0, header_footer: true, attributes: { stylesheet: "spec/fixtures/css/simple.css", showtitle: true } } | ||
const html = asciidoctor.convert(data, options) | ||
console.log(html) | ||
describe('QuickJS', function () { | ||
it('should convert as HTML', function () { | ||
const opts = { } | ||
const html = asciidoctor.convert(data, opts); | ||
expect(html).to.include('<ul>'); | ||
}) | ||
it('should include stylesheet', function () { | ||
const opts = { safe: 0, header_footer: true, attributes: { stylesheet: "spec/fixtures/css/simple.css", showtitle: true } }; | ||
const html = asciidoctor.convert(data, opts); | ||
expect(html).to.include('4078c0'); | ||
}) | ||
it('should include file', function () { | ||
const opts = { safe: 0 }; | ||
const html = asciidoctor.convert('include::spec/fixtures/include.adoc[]', opts) | ||
expect(html).to.include('include content'); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters