hsml 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Christopher Quadflieg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ <p>
2
+ <a href="https://github.com/Shinigami92/hsml/actions/workflows/ci.yml">
3
+ <img alt="Build Status" src="https://github.com/Shinigami92/hsml/actions/workflows/ci.yml/badge.svg?branch=main">
4
+ </a>
5
+ <a href="https://github.com/Shinigami92/hsml/blob/main/LICENSE">
6
+ <img alt="License: MIT" src="https://img.shields.io/github/license/Shinigami92/hsml.svg">
7
+ </a>
8
+ <a href="https://www.paypal.com/donate?hosted_button_id=L7GY729FBKTZY" target="_blank">
9
+ <img alt="Donate: PayPal" src="https://img.shields.io/badge/Donate-PayPal-blue.svg">
10
+ </a>
11
+ </p>
12
+
13
+ # UNDER CONSTRUCTION
14
+
15
+ Right now there is no usable version of `hsml` available. I'm just working on it.
16
+
17
+ <img src="https://chronicle-brightspot.s3.amazonaws.com/6a/c4/00e4ab3143f7e0cf4d9fd33aa00b/constructocat2.jpg" width="400px" />
18
+
19
+ # HSML - Hyper Short Markup Language
20
+
21
+ `hsml` is a hyper short markup language that is inspired by [pug](https://pugjs.org) (aka jade).
22
+
23
+ ## What is it?
24
+
25
+ - `hsml` is written in [Rust](https://www.rust-lang.org) and compiles to HTML.
26
+ - There will be a binary that can take CLI arguments to compile a `.hsml` file to a `.html` file, but also there will be some other arguments to e.g. format a `.hsml` file.
27
+ - There will be also a library that can parse a `.hsml` file and return an AST for it. It is planned that this AST can be used in the JS ecosystem as well, so tools like ESLint and Prettier can work with it.
28
+ - There are two major differences between `pug` and `hsml`
29
+ - `hsml` will support TailwindCSS and similar CSS frameworks out of the box, even with arbitrary values like `.bg-[#1da1f2]` or `lg:[&:nth-child(3)]:hover:underline`
30
+ - `hsml` will **not** support template engine syntax. It is _just_ an HTML preprocessor.
31
+
32
+ ## Why doing it?
33
+
34
+ - I want to learn Rust
35
+ - I use `pug` for my projects but sadly `pug`'s goal mismatches my preferences and comes with a lot of overhead I don't need
package/hsml.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * @param {string} source
5
+ * @returns {string}
6
+ */
7
+ export function compile_content(source: string): string;
package/hsml.js ADDED
@@ -0,0 +1,116 @@
1
+ let imports = {};
2
+ let wasm;
3
+ const { TextEncoder, TextDecoder } = require(`util`);
4
+
5
+ let WASM_VECTOR_LEN = 0;
6
+
7
+ let cachedUint8Memory0 = null;
8
+
9
+ function getUint8Memory0() {
10
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
11
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
12
+ }
13
+ return cachedUint8Memory0;
14
+ }
15
+
16
+ let cachedTextEncoder = new TextEncoder('utf-8');
17
+
18
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
19
+ ? function (arg, view) {
20
+ return cachedTextEncoder.encodeInto(arg, view);
21
+ }
22
+ : function (arg, view) {
23
+ const buf = cachedTextEncoder.encode(arg);
24
+ view.set(buf);
25
+ return {
26
+ read: arg.length,
27
+ written: buf.length
28
+ };
29
+ });
30
+
31
+ function passStringToWasm0(arg, malloc, realloc) {
32
+
33
+ if (realloc === undefined) {
34
+ const buf = cachedTextEncoder.encode(arg);
35
+ const ptr = malloc(buf.length) >>> 0;
36
+ getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
37
+ WASM_VECTOR_LEN = buf.length;
38
+ return ptr;
39
+ }
40
+
41
+ let len = arg.length;
42
+ let ptr = malloc(len) >>> 0;
43
+
44
+ const mem = getUint8Memory0();
45
+
46
+ let offset = 0;
47
+
48
+ for (; offset < len; offset++) {
49
+ const code = arg.charCodeAt(offset);
50
+ if (code > 0x7F) break;
51
+ mem[ptr + offset] = code;
52
+ }
53
+
54
+ if (offset !== len) {
55
+ if (offset !== 0) {
56
+ arg = arg.slice(offset);
57
+ }
58
+ ptr = realloc(ptr, len, len = offset + arg.length * 3) >>> 0;
59
+ const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
60
+ const ret = encodeString(arg, view);
61
+
62
+ offset += ret.written;
63
+ }
64
+
65
+ WASM_VECTOR_LEN = offset;
66
+ return ptr;
67
+ }
68
+
69
+ let cachedInt32Memory0 = null;
70
+
71
+ function getInt32Memory0() {
72
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
73
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
74
+ }
75
+ return cachedInt32Memory0;
76
+ }
77
+
78
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
79
+
80
+ cachedTextDecoder.decode();
81
+
82
+ function getStringFromWasm0(ptr, len) {
83
+ ptr = ptr >>> 0;
84
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
85
+ }
86
+ /**
87
+ * @param {string} source
88
+ * @returns {string}
89
+ */
90
+ module.exports.compile_content = function(source) {
91
+ let deferred2_0;
92
+ let deferred2_1;
93
+ try {
94
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
95
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
96
+ const len0 = WASM_VECTOR_LEN;
97
+ wasm.compile_content(retptr, ptr0, len0);
98
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
99
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
100
+ deferred2_0 = r0;
101
+ deferred2_1 = r1;
102
+ return getStringFromWasm0(r0, r1);
103
+ } finally {
104
+ wasm.__wbindgen_add_to_stack_pointer(16);
105
+ wasm.__wbindgen_free(deferred2_0, deferred2_1);
106
+ }
107
+ };
108
+
109
+ const path = require('path').join(__dirname, 'hsml_bg.wasm');
110
+ const bytes = require('fs').readFileSync(path);
111
+
112
+ const wasmModule = new WebAssembly.Module(bytes);
113
+ const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
114
+ wasm = wasmInstance.exports;
115
+ module.exports.__wasm = wasm;
116
+
package/hsml_bg.wasm ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "hsml",
3
+ "collaborators": [
4
+ "Christopher Quadflieg <chrissi92@hotmail.de>"
5
+ ],
6
+ "description": "A pug-inspired HTML preprocessor",
7
+ "version": "0.1.0",
8
+ "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/Shinigami92/hsml"
12
+ },
13
+ "files": [
14
+ "hsml_bg.wasm",
15
+ "hsml.js",
16
+ "hsml.d.ts"
17
+ ],
18
+ "main": "hsml.js",
19
+ "types": "hsml.d.ts",
20
+ "keywords": [
21
+ "hsml",
22
+ "html",
23
+ "preprocessor"
24
+ ]
25
+ }