diff options
author | Li Jin <dragon-fly@qq.com> | 2023-10-31 17:06:43 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-10-31 17:06:50 +0800 |
commit | 9908433cc0d493c6910d0aed5cdf263397cee87f (patch) | |
tree | 4a62db9fc0d49e9a05ce9cb1e35bb956c9b03b3b /spec/inputs/compile_doc.yue | |
parent | ca6f13ea62e1fb566a604a00176beb6dda0dcb1a (diff) | |
download | yuescript-9908433cc0d493c6910d0aed5cdf263397cee87f.tar.gz yuescript-9908433cc0d493c6910d0aed5cdf263397cee87f.tar.bz2 yuescript-9908433cc0d493c6910d0aed5cdf263397cee87f.zip |
add doc codes check.
Diffstat (limited to 'spec/inputs/compile_doc.yue')
-rw-r--r-- | spec/inputs/compile_doc.yue | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/inputs/compile_doc.yue b/spec/inputs/compile_doc.yue new file mode 100644 index 0000000..4ce2b13 --- /dev/null +++ b/spec/inputs/compile_doc.yue | |||
@@ -0,0 +1,24 @@ | |||
1 | outputFolder = ... | ||
2 | for [compiledFile, docFile] in *[ | ||
3 | ["codes_from_doc.lua", "doc/docs/doc/README.md"] | ||
4 | ["codes_from_doc_zh.lua", "doc/docs/zh/doc/README.md"] | ||
5 | ] | ||
6 | close input = with? io.open docFile | ||
7 | import "yue" as :to_lua | ||
8 | text = \read "*a" | ||
9 | codes = [] | ||
10 | for code in text\gmatch "```moonscript(.-)```" | ||
11 | if result, err = to_lua code, implicit_return_root: false, reserve_line_number: false | ||
12 | codes[] = result | ||
13 | elseif not err\match "macro exporting module only accepts macro definition" | ||
14 | print err | ||
15 | os.exit 1 | ||
16 | for code in text\gmatch "<pre>(.-)</pre>" | ||
17 | if result, err = to_lua code\gsub("<", "<")\gsub(">", ">"), implicit_return_root: false, reserve_line_number: false | ||
18 | codes[] = result | ||
19 | else | ||
20 | print err | ||
21 | os.exit 1 | ||
22 | close output = with io.open "#{outputFolder}/#{compiledFile}", "w+" | ||
23 | \write table.concat codes | ||
24 | |||