diff --git a/.gitignore b/.gitignore index a9c0d11..ef41b2d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ capsule/ gmi.js gmi.min.js +example/test.html diff --git a/Makefile b/Makefile index 15692a9..ff64252 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,9 @@ format: ./node_modules/prettier/bin-prettier.js --write gmi.css ./node_modules/prettier/bin-prettier.js --write *.js !*.min.js +example/test.html: example/test.gmi + ./test.sh + clean: rm -rf gmi.min.* gmi-web.1 node_modules diff --git a/README.md b/README.md index 17b9572..df6d9d7 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ The generated HTML document must have a `` tag with _at minimum_ the follo ```html - + ``` @@ -84,7 +84,7 @@ Currently approaching a v1 release 🎉 Would you like to help test the RC? _You Install the binary via npm. ```sh -npm install --global gmi-web-cli@1.0.4-rc.1 +npm install --global gmi-web-cli ``` Render .html for all the .gmi files in the current directory diff --git a/example/expected.html b/example/expected.html new file mode 100644 index 0000000..da9f28e --- /dev/null +++ b/example/expected.html @@ -0,0 +1,42 @@ + + + + + + + + +heading 1 + + +

heading 1

+

heading 2

+

heading 3

+

checkout this empty line:

+


+ +


+
here's what a blockquote is like
+


+
+preformatted text
+       means that it already has formatting
+  which means it should show
+
+
+
+                           as is
+
+


+

<b>watch out!</b> a gemtext line could have html in it that you'll need to escape!

+


+ + + + + diff --git a/example/test.gmi b/example/test.gmi new file mode 100644 index 0000000..8520bad --- /dev/null +++ b/example/test.gmi @@ -0,0 +1,26 @@ +# heading 1 +## heading 2 +### heading 3 +checkout this empty line: + +* and +* this +* list + +> here's what a blockquote is like + +```pre tags can have alt text +preformatted text + means that it already has formatting + which means it should show + + + + as is +``` + +watch out! a gemtext line could have html in it that you'll need to escape! + +=> https://www.learningcontainer.com/wp-content/uploads/2020/07/Large-Sample-Image-download-for-Testing.jpg JPG image that can render inline! +=> https://www.learningcontainer.com/wp-content/uploads/2020/02/Kalimba.mp3 MP3 audio that can render inline! +=> https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4 MP4 Video that can render inline! diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..9e1af98 --- /dev/null +++ b/test.sh @@ -0,0 +1,9 @@ +./cli.js --lang en --images --audio --video "example/*.gmi" +if cmp -s "example/test.html" "example/expected.html"; then + printf "PASS: test.html matches expected.html!\n" +else + printf "FAIL: test.html DOES NOT match expected.html!\n" + cmp "example/test.html" "example/expected.html" + diff "example/test.html" "example/expected.html" + exit 1 +fi diff --git a/to-html.js b/to-html.js index bea1a71..2e6a273 100644 --- a/to-html.js +++ b/to-html.js @@ -9,14 +9,17 @@ const AUDIO_EXT = (exports.AUDIO_EXT = /\.(mp3|wav|aac|aacp|mpeg|off|flac)$/); const VIDEO_EXT = (exports.VIDEO_EXT = /\.(mp4|webm)$/); const BASE_STYLE = (exports.BASE_STYLE = ""); +const GMI_CSS = fs.readFileSync( + path.resolve(__dirname, "./gmi.min.css"), + "utf8" +); const toHTML = (exports.toHTML = (file, options) => { const tokens = JSON.parse(file.contents.toString("utf8")); const title = tokens[0].h1; return ` -${head(file.path, title, options)} - +${head(file.path, title, options)} ${gemtext(tokens, options)} @@ -38,10 +41,7 @@ function head(file, title, options) { ${ !options.css ? BASE_STYLE - : `\n\n` + : `\n\n` }${ !options.canonical ? "" @@ -60,7 +60,7 @@ function gemtext(tokens, options) { let cursor = tokens.shift(); while (tokens.length) { if (cursor.pre) { - body.push(``); + body.push(``); const closing = tokens.findIndex((token) => token.pre); body = body.concat(tokens.slice(0, closing).map(({ text }) => text)); body.push(""); @@ -68,9 +68,11 @@ function gemtext(tokens, options) { } else if (cursor.li) { body.push(`"); - tokens = tokens.slice(closing + 1); + tokens = tokens.slice(closing); } else { body.push(line(cursor, options)); } @@ -82,7 +84,7 @@ function gemtext(tokens, options) { function line( { text, href, title, pre, alt, h1, h2, h3, li, quote }, - { images, audio, video } + { images, audio, video } = {} ) { if (text) return `

${escape(text)}

`; if (href) {