nattoppet 2.0.0 → 2.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/common.ymd +1 -1
- package/compiler.js +10 -3
- package/native/Cargo.toml +13 -0
- package/native/build.rs +12 -0
- package/native/src/main.rs +22 -0
- package/nattoppet-dev.js +1 -1
- package/nattoppet-native.js +49 -0
- package/nattoppet.js +2 -1
- package/package.json +8 -9
- package/ppt/ppt.less +1 -1
- package/stdlib.js +2 -2
- package/vue/vue.less +4 -1
package/common.ymd
CHANGED
|
@@ -7,7 +7,7 @@ switch (extname(file)) {
|
|
|
7
7
|
case 'css':
|
|
8
8
|
`<style>${content}</style>`; break
|
|
9
9
|
case 'coffee':
|
|
10
|
-
`<script>${render_coffee(content)}</script>`; break
|
|
10
|
+
`<script>${render_coffee(content, { bare: true })}</script>`; break
|
|
11
11
|
case 'js':
|
|
12
12
|
`<script>${content}</script>`; break
|
|
13
13
|
case 'md':
|
package/compiler.js
CHANGED
|
@@ -64,9 +64,11 @@ const interpret = (str, env, defs) => {
|
|
|
64
64
|
if (p1 < 0 && p2 < 0) return str
|
|
65
65
|
|
|
66
66
|
if (p2 < 0 || (p1 >= 0 && p1 < p2)) {
|
|
67
|
+
const head = str.substring(0, p1)
|
|
68
|
+
str = str.substring(p1+2)
|
|
67
69
|
let p = str.indexOf('\n\n')
|
|
68
70
|
if (p < 0) p = str.length
|
|
69
|
-
return
|
|
71
|
+
return head + '<p>' + interpret(str.substring(0, p), env, defs) + '</p>' + interpret(str.substring(p+1), env, defs)
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
const name = str.match(/\[(.+?)\]/)[1]
|
|
@@ -77,9 +79,14 @@ const interpret = (str, env, defs) => {
|
|
|
77
79
|
switch (def.type) {
|
|
78
80
|
case 'fn':
|
|
79
81
|
env.remaining = str.substring(p2 + name.length + 2)
|
|
80
|
-
env.interpret = str =>
|
|
82
|
+
env.interpret = str => { // a "scoped" interpret function capable for interpreting substrings. We preserve the "remaining" property outside.
|
|
83
|
+
const remaining = env.remaining
|
|
84
|
+
const result = interpret(str, env, defs) // We gaved full defs available on the call site (dynamic scoping) as the text to be interpreted is part of the call site text.
|
|
85
|
+
env.remaining = remaining
|
|
86
|
+
return result
|
|
87
|
+
}
|
|
81
88
|
const result = vm.runInContext('{' + def.content + '}', env)
|
|
82
|
-
return str.substring(0, p2) + result +
|
|
89
|
+
return str.substring(0, p2) + result + interpret(env.remaining, env, defs)
|
|
83
90
|
case 'ref':
|
|
84
91
|
return str.substring(0, p2) +
|
|
85
92
|
interpret(def.content, env, defs.slice(i+1)) + // However for ref we use lexical scoping. Exclude self to prevent recusion
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "nattoppet_native"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
|
|
6
|
+
[dependencies]
|
|
7
|
+
web-view = { version = "0.7", features = ["edge"] }
|
|
8
|
+
|
|
9
|
+
[target.'cfg(windows)'.build-dependencies]
|
|
10
|
+
winres = "0.1"
|
|
11
|
+
|
|
12
|
+
[package.metadata.winres]
|
|
13
|
+
ProductName = "A nattoppet native app"
|
package/native/build.rs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#![windows_subsystem = "windows"]
|
|
2
|
+
|
|
3
|
+
use web_view::*;
|
|
4
|
+
|
|
5
|
+
fn main() {
|
|
6
|
+
static HTML_CONTENT: &str = include_str!("../target/bundle.html");
|
|
7
|
+
|
|
8
|
+
web_view::builder()
|
|
9
|
+
.title("Nattoppet Native")
|
|
10
|
+
.content(Content::Html(HTML_CONTENT))
|
|
11
|
+
.size(600, 480)
|
|
12
|
+
.resizable(false)
|
|
13
|
+
.debug(cfg!(debug_assertions))
|
|
14
|
+
.user_data(())
|
|
15
|
+
.invoke_handler(handler)
|
|
16
|
+
.run()
|
|
17
|
+
.unwrap();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fn handler(webview: &mut WebView<()>, arg: &str) -> WVResult {
|
|
21
|
+
Ok(())
|
|
22
|
+
}
|
package/nattoppet-dev.js
CHANGED
|
@@ -22,7 +22,7 @@ const done = () => {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const start = (init=false) => {
|
|
25
|
-
const child = cp.spawn(__dirname + '/nattoppet.js', [file])
|
|
25
|
+
const child = cp.spawn(__dirname + '/nattoppet.js', [file, '--dev'])
|
|
26
26
|
let buffer = ''
|
|
27
27
|
child.stdout.on('data', chunk => buffer += chunk)
|
|
28
28
|
child.on('close', code => {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict'
|
|
4
|
+
|
|
5
|
+
const fs = require('fs')
|
|
6
|
+
const cp = require('child_process')
|
|
7
|
+
const path = require('path')
|
|
8
|
+
|
|
9
|
+
const init = () => {
|
|
10
|
+
fs.mkdirSync('native')
|
|
11
|
+
fs.mkdirSync('native/src')
|
|
12
|
+
fs.mkdirSync('native/target')
|
|
13
|
+
fs.copyFileSync(path.join(__dirname, 'native', 'src', 'main.rs'), 'native/src/main.rs')
|
|
14
|
+
fs.copyFileSync(path.join(__dirname, 'native', 'build.rs'), 'native/build.rs')
|
|
15
|
+
fs.copyFileSync(path.join(__dirname, 'native', 'Cargo.toml'), 'native/Cargo.toml')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const bundle = () => {
|
|
19
|
+
const child = cp.spawnSync(__dirname + '/nattoppet.js', [process.argv[3]])
|
|
20
|
+
if (child.stderr.length) {
|
|
21
|
+
console.error(child.stderr.toString())
|
|
22
|
+
}
|
|
23
|
+
fs.writeFileSync('native/target/bundle.html', child.stdout)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const build = () => {
|
|
27
|
+
bundle()
|
|
28
|
+
const child = cp.spawn('cargo', ['build', '--release'], { cwd: 'native' })
|
|
29
|
+
child.stdout.pipe(process.stdout)
|
|
30
|
+
child.stderr.pipe(process.stderr)
|
|
31
|
+
child.on('exit', (code) => {
|
|
32
|
+
if (code != 0) {
|
|
33
|
+
console.error("Cargo exit with code: " + code)
|
|
34
|
+
} else {
|
|
35
|
+
console.log("building finished. Check native/target/release/")
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const help = () => {
|
|
41
|
+
console.log("Usage: nattoppet-native [init|bundle|build]")
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
switch (process.argv[2]) {
|
|
45
|
+
case 'init': return init()
|
|
46
|
+
case 'bundle': return bundle()
|
|
47
|
+
case 'build': return build()
|
|
48
|
+
default: return help()
|
|
49
|
+
}
|
package/nattoppet.js
CHANGED
|
@@ -12,7 +12,8 @@ const file = process.argv[2] || 0
|
|
|
12
12
|
const dir = file ? path.dirname(path.resolve(file)) : process.cwd()
|
|
13
13
|
const str = fs.readFileSync(file, 'utf8')
|
|
14
14
|
const env = { ...stdlib, base_dir: dir }
|
|
15
|
-
const
|
|
15
|
+
const raw = compiler.compile(str, env)
|
|
16
|
+
const out = process.argv.includes('--dev', 1) ? raw : minifier.minify(raw, {
|
|
16
17
|
collapseWhitespace: true,
|
|
17
18
|
removeAttributeQuotes: true,
|
|
18
19
|
removeComments: true,
|
package/package.json
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nattoppet",
|
|
3
3
|
"description": "A tiny macro-based markup language for blogging",
|
|
4
|
-
"
|
|
4
|
+
"author": "Shiwei Zhang <ylxdzsw@gmail.com>",
|
|
5
|
+
"version": "2.1.0",
|
|
5
6
|
"dependencies": {
|
|
6
7
|
"coffeescript": "^2.5.1",
|
|
7
8
|
"html-minifier": "^4.0.0",
|
|
8
|
-
"katex": "^0.
|
|
9
|
-
"less": "^
|
|
10
|
-
"marked": "^0.
|
|
9
|
+
"katex": "^0.13.0",
|
|
10
|
+
"less": "^4.1.1",
|
|
11
|
+
"marked": "^2.0.1"
|
|
11
12
|
},
|
|
12
13
|
"bin": {
|
|
13
14
|
"nattoppet": "./nattoppet.js",
|
|
14
|
-
"nattoppet-dev": "./nattoppet-dev.js"
|
|
15
|
+
"nattoppet-dev": "./nattoppet-dev.js",
|
|
16
|
+
"nattoppet-native": "./nattoppet-native.js"
|
|
15
17
|
},
|
|
16
18
|
"license": "MIT",
|
|
17
|
-
"repository":
|
|
18
|
-
"type": "git",
|
|
19
|
-
"url": "https://github.com/ylxdzsw/nattoppet.git"
|
|
20
|
-
}
|
|
19
|
+
"repository": "https://github.com/ylxdzsw/nattoppet.git"
|
|
21
20
|
}
|
package/ppt/ppt.less
CHANGED
package/stdlib.js
CHANGED