From b48e8cd6ecc0de4817aa54be519d660561038ed8 Mon Sep 17 00:00:00 2001 From: NaitLee Date: Mon, 27 Feb 2023 21:45:49 +0800 Subject: [PATCH] initial help docs with dash markup --- TODO | 7 +- server.py | 4 + www/all_js.txt | 1 + www/dash-xml.js | 81 ++++++++++++++++++++ www/helps/0-mkcontent.sh | 9 +++ www/helps/en-US/content.txt | 2 + www/helps/en-US/frequently-asked-questions-- | 7 ++ www/helps/en-US/glossary-- | 36 +++++++++ www/index.html | 7 +- www/jslicense.html | 6 ++ www/lang/de-DE.json | 2 +- www/lang/en-US.json | 8 +- www/lang/lolcat.json | 6 +- www/lang/zh-CN.json | 7 +- www/lang/zh-HK.json | 7 +- www/lang/zh-Hant-CN.json | 7 +- www/lang/zh-TW.json | 7 +- www/loader.js | 2 +- www/main.css | 21 ++++- www/main.js | 50 +++++++++++- 20 files changed, 248 insertions(+), 29 deletions(-) create mode 100644 www/dash-xml.js create mode 100755 www/helps/0-mkcontent.sh create mode 100644 www/helps/en-US/content.txt create mode 100644 www/helps/en-US/frequently-asked-questions-- create mode 100644 www/helps/en-US/glossary-- diff --git a/TODO b/TODO index f9736b0..04e4b95 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,7 @@ Note: not ordered. do whatever I/you want + Cookbook of basic things -+ Write good help/manual ++ Write good help/manual, with Dash Markup/XML + Some sort of Wiki + Make error notice short while let users see detailed help/manual for what-to-do + Even better CUPS/IPP support @@ -16,6 +16,7 @@ Note: not ordered. do whatever I/you want + Service for other init systems (a systemd unit file is there) + ... +? DOM backend for Dash XML ? Optimize PF2 text printing? It seems a bit slow (in bit processing). ? Use something else as server part of backend? This can boost things up, and build some (essential) image manipulation in, quicker. And strip some way-too-big Python libs away (for smaller Windows/Android dist). ? Built-in PostScript (Even if very basic) @@ -24,6 +25,6 @@ Note: not ordered. do whatever I/you want It's usually messy. Try forking in your own way, at the moment. ? Process picture with WebAssembly? (Web frontend only) Tried, Not as efficient as pure JavaScript -? Put Android APP on F-Droid? But it needs automatic build system... - Android guys can help this! +? Put Android APP on F-Droid (official repository)? + But it needs automatic build system... Android guys can help this! ? ... Or put to APKPure? But make frontend well before doing all of these diff --git a/server.py b/server.py index d7ea124..f19f809 100644 --- a/server.py +++ b/server.py @@ -46,6 +46,7 @@ mime_type = { 'html': 'text/html;charset=utf-8', 'css': 'text/css;charset=utf-8', 'js': 'text/javascript;charset=utf-8', + 'mjs': 'text/javascript;charset=utf-8', 'txt': 'text/plain;charset=utf-8', 'json': 'application/json;charset=utf-8', 'png': 'image/png', @@ -55,6 +56,9 @@ mime_type = { } def mime(url: str): 'Get pre-defined MIME type of a certain url by extension name' + if url.endswith('--'): + # dash markup / dash xml + return 'text/plain;charset=utf-8' return mime_type.get(url.rsplit('.', 1)[-1], mime_type['octet-stream']) def concat_files(*paths, prefix_format='', buffer=4 * 1024 * 1024) -> bytes: diff --git a/www/all_js.txt b/www/all_js.txt index 4c34244..c6d8a1c 100644 --- a/www/all_js.txt +++ b/www/all_js.txt @@ -2,5 +2,6 @@ polyfill.js i18n-ext.js i18n.js image.js +dash-xml.js accessibility.js main.js diff --git a/www/dash-xml.js b/www/dash-xml.js new file mode 100644 index 0000000..2ef7859 --- /dev/null +++ b/www/dash-xml.js @@ -0,0 +1,81 @@ +// @license magnet:?xt=urn:btih:90dc5c0be029de84e523b9b3922520e79e0e6f08&dn=cc0.txt CC0-1.0 +// deno-fmt-ignore-file +// deno-lint-ignore-file + +var DashXml = (function() { +const SD = "-"; +const DD = "--"; +const SP = " "; +const SDSP = " - "; +const DDSP = " -- "; +const RE_WORD = "[^ ]+"; +const RE_INDENT = "[ \t]*"; +const RE_DMX = new RegExp(`^(${RE_INDENT})` + `(${RE_WORD})?` + `((?:${SDSP}.+?)*)?` + `(${DDSP}.+)?` + `(?:${SP}|^)(${SD}|${DD})$`); +const XmlEntities = { + "&": "&", + "<": "<", + ">": ">" +}; +class DashXml { + tags; + constructor(){ + this.tags = []; + } + translateLine(line) { + if (line.endsWith(SD) || /^[ \t]*<.+>$/.test(line)) Object.entries(XmlEntities).forEach(([__char, entity])=>line = line.replaceAll(__char, entity)); + if (!line.endsWith(SD)) return line; + const match = line.match(RE_DMX); + if (match === null) { + if (line.match(/^ *!-- (.+) --$/)) { + return line.replace("!", ""; + } + console.warn("Warning: failed to match this Dash Markup, probably this line is bad or current regexp is faulty"); + console.warn(">", line); + return ""; + } + if (!match[2]) { + const tag = this.tags.pop(); + if (tag === undefined) { + console.warn("Warning: no more tags to close, probably previous lines closed one too early, or this translator is faulty"); + console.warn("will leave out an '', please check result"); + } + return line.slice(0, -1) + ""; + } + const tag1 = match[2]; + let result = match[1] + "<" + tag1; + if (match[3]) { + const segs = match[3].split(SDSP).map((s)=>s.replaceAll("---", "-")); + segs.shift(); + for (const seg of segs){ + const space = seg.indexOf(SP); + if (space === -1) { + result += SP + seg; + } else { + result += SP + seg.slice(0, space) + '="' + seg.slice(space + 1) + '"'; + } + } + } + if (match[4]) { + result += ">" + match[4].slice(DDSP.length); + } + if (match[5] === SD) { + result += ">"; + this.tags.push(tag1); + } else if (match[5] === DD) { + if (match[4]) { + result += ""; + } else if (tag1[0] === "!") { + result += ">"; + } else if (tag1[0] === "?") { + result += "?>"; + } else { + result += " />"; + } + } + return result; + } +} + +return DashXml; +})(); +// @license-end diff --git a/www/helps/0-mkcontent.sh b/www/helps/0-mkcontent.sh new file mode 100755 index 0000000..0449417 --- /dev/null +++ b/www/helps/0-mkcontent.sh @@ -0,0 +1,9 @@ +#!/bin/sh +for dir in $(ls); do { + if [ -d $dir ]; then + rm "$dir/content.txt" + for file in $(ls $dir); do { + printf 'helps/%s/%s\t%s\n' $dir $file ${file%--} >> "$dir/content.txt" + }; done + fi +}; done diff --git a/www/helps/en-US/content.txt b/www/helps/en-US/content.txt new file mode 100644 index 0000000..010ee9c --- /dev/null +++ b/www/helps/en-US/content.txt @@ -0,0 +1,2 @@ +helps/en-US/frequently-asked-questions-- frequently-asked-questions +helps/en-US/glossary-- glossary diff --git a/www/helps/en-US/frequently-asked-questions-- b/www/helps/en-US/frequently-asked-questions-- new file mode 100644 index 0000000..d41ad71 --- /dev/null +++ b/www/helps/en-US/frequently-asked-questions-- @@ -0,0 +1,7 @@ + +h3 -- How do I scan & connect to a device? -- +p -- When you tap “Print”, the application will automatically connect to an available device (that is near you & powered on & waiting for connection), and print directly afterwards. -- +p -- The connection will persist until you close either the application or the printer. If the printer is shutdown after a connection, the application will automatically search for another one when requested to print. -- + +h3 -- What if I have multiple printers available and want to print to a specific one? -- +p -- Tap “Show More Options”, an option for manually scanning & selecting devices is there. -- diff --git a/www/helps/en-US/glossary-- b/www/helps/en-US/glossary-- new file mode 100644 index 0000000..63ff288 --- /dev/null +++ b/www/helps/en-US/glossary-- @@ -0,0 +1,36 @@ + +h3 -- Interesting ones: -- +dl - +dt -- Cat Face Upward -- +dd -- Flip the image data sent to printer, so that after printing both your picture and the printer itself faces upward, natually. -- +- + +h3 -- “Brightness”, “Strength”, and “Quality” -- +dl - +dt -- Brightness -- +dd -- directly affect how your picture is processed to pixels that fits the printer’s “black and white” color; -- +- +dl - +dt -- Strength -- +dd -- tell the printer how deep to print those resulting pixels, i.e. the thermal energy used; -- +- +dl - +dt -- Quality -- +dd -- indeed affect paper feeding speed, lower “Quality” means higher speed printing but unstable heating & visual quality. -- +- + +h3 -- “Picture”, “Pattern”, and “Text” Process -- +p -- Since the printer can only print black pixels (not even gray), ordinary pictures should be specifically processed with a algorithm that suits its use best. -- +p -- Pictures are first processed to grayscale (in a natual-for-eyes way), then processed as: -- +dl - +dt -- Picture -- +dd -- use black & white pixels in place of “gray” parts of original image, which is best for ordinary pictures; -- +- +dl - +dt -- Pattern -- +dd -- use variable sized dots in place of “gray” parts of original image, which may be good for simple shapes; -- +- +dl - +dt -- Text -- +dd -- simply determine black or white per-pixel by brightness, good for snapshots of text. -- +- diff --git a/www/index.html b/www/index.html index e80736f..fb698a0 100644 --- a/www/index.html +++ b/www/index.html @@ -70,7 +70,7 @@
-

Coming Soon...

+

    About

    +