nattoppet 2.0.1 → 2.1.1
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 +7 -2
- 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 +9 -10
- package/ppt/ppt.less +1 -1
- package/readme.md +26 -3
- package/stdlib.js +3 -3
- 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
|
@@ -79,9 +79,14 @@ const interpret = (str, env, defs) => {
|
|
|
79
79
|
switch (def.type) {
|
|
80
80
|
case 'fn':
|
|
81
81
|
env.remaining = str.substring(p2 + name.length + 2)
|
|
82
|
-
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
|
+
}
|
|
83
88
|
const result = vm.runInContext('{' + def.content + '}', env)
|
|
84
|
-
return str.substring(0, p2) + result +
|
|
89
|
+
return str.substring(0, p2) + result + interpret(env.remaining, env, defs)
|
|
85
90
|
case 'ref':
|
|
86
91
|
return str.substring(0, p2) +
|
|
87
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.1",
|
|
5
6
|
"dependencies": {
|
|
6
|
-
"coffeescript": "^2.
|
|
7
|
+
"coffeescript": "^2.6.1",
|
|
7
8
|
"html-minifier": "^4.0.0",
|
|
8
|
-
"katex": "^0.
|
|
9
|
-
"less": "^
|
|
10
|
-
"marked": "^0.
|
|
9
|
+
"katex": "^0.15.0",
|
|
10
|
+
"less": "^4.1.2",
|
|
11
|
+
"marked": "^4.0.10"
|
|
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/readme.md
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
nattoppet
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
-
A tiny markup language and several themes for making documents
|
|
4
|
+
A tiny markup language and several themes for making documents, slides, or web apps as single-file bundled html or
|
|
5
|
+
executable.
|
|
5
6
|
|
|
6
|
-
### Usage
|
|
7
|
+
### Usage
|
|
8
|
+
|
|
9
|
+
compile a nattoppet file:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
$ npm exec nattoppet in.ymd > out.html
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
compile a nattoppet file but don't minimize (for debugging):
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
$ npm exec nattoppet in.ymd --dev > out.html
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
watch a nattoppet file and rebuild it whenever it changes; open a browser to view the compiled page
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
$ npm exec nattoppet-dev in.ymd
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
build a double-clickable executable for the page
|
|
7
28
|
|
|
8
29
|
```
|
|
9
|
-
$
|
|
30
|
+
$ npm exec nattoppet-native init
|
|
31
|
+
$ (edit the metadata as needed)
|
|
32
|
+
$ npm exec nattoppet-native build in.ymd
|
|
10
33
|
```
|
package/stdlib.js
CHANGED
|
@@ -88,8 +88,8 @@ module.exports = {
|
|
|
88
88
|
return path.basename(file)
|
|
89
89
|
},
|
|
90
90
|
|
|
91
|
-
render_coffee(str) {
|
|
92
|
-
return coffee.compile(str)
|
|
91
|
+
render_coffee(str, options) {
|
|
92
|
+
return coffee.compile(str, options)
|
|
93
93
|
},
|
|
94
94
|
|
|
95
95
|
render_less(str) {
|
|
@@ -99,7 +99,7 @@ module.exports = {
|
|
|
99
99
|
},
|
|
100
100
|
|
|
101
101
|
render_markdown(str) {
|
|
102
|
-
return marked(str)
|
|
102
|
+
return marked.parse(str)
|
|
103
103
|
},
|
|
104
104
|
|
|
105
105
|
render_katex(str, displayMode=false) {
|