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/outputs/compile_doc.lua | |
| parent | ca6f13ea62e1fb566a604a00176beb6dda0dcb1a (diff) | |
| download | yuescript-9908433cc0d493c6910d0aed5cdf263397cee87f.tar.gz yuescript-9908433cc0d493c6910d0aed5cdf263397cee87f.tar.bz2 yuescript-9908433cc0d493c6910d0aed5cdf263397cee87f.zip | |
add doc codes check.
Diffstat (limited to 'spec/outputs/compile_doc.lua')
| -rw-r--r-- | spec/outputs/compile_doc.lua | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/outputs/compile_doc.lua b/spec/outputs/compile_doc.lua new file mode 100644 index 0000000..7597cb8 --- /dev/null +++ b/spec/outputs/compile_doc.lua | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | local outputFolder = ... | ||
| 2 | local _list_0 = { | ||
| 3 | { | ||
| 4 | "codes_from_doc.lua", | ||
| 5 | "doc/docs/doc/README.md" | ||
| 6 | }, | ||
| 7 | { | ||
| 8 | "codes_from_doc_zh.lua", | ||
| 9 | "doc/docs/zh/doc/README.md" | ||
| 10 | } | ||
| 11 | } | ||
| 12 | for _index_0 = 1, #_list_0 do | ||
| 13 | local _des_0 = _list_0[_index_0] | ||
| 14 | local compiledFile, docFile = _des_0[1], _des_0[2] | ||
| 15 | local input <close> = (function() | ||
| 16 | local _with_0 = io.open(docFile) | ||
| 17 | if _with_0 ~= nil then | ||
| 18 | local to_lua = require("yue").to_lua | ||
| 19 | local text = _with_0:read("*a") | ||
| 20 | local codes = { } | ||
| 21 | for code in text:gmatch("```moonscript(.-)```") do | ||
| 22 | do | ||
| 23 | local result, err = to_lua(code, { | ||
| 24 | implicit_return_root = false, | ||
| 25 | reserve_line_number = false | ||
| 26 | }) | ||
| 27 | if result then | ||
| 28 | codes[#codes + 1] = result | ||
| 29 | elseif not err:match("macro exporting module only accepts macro definition") then | ||
| 30 | print(err) | ||
| 31 | os.exit(1) | ||
| 32 | end | ||
| 33 | end | ||
| 34 | end | ||
| 35 | for code in text:gmatch("<pre>(.-)</pre>") do | ||
| 36 | do | ||
| 37 | local result, err = to_lua(code:gsub("<", "<"):gsub(">", ">"), { | ||
| 38 | implicit_return_root = false, | ||
| 39 | reserve_line_number = false | ||
| 40 | }) | ||
| 41 | if result then | ||
| 42 | codes[#codes + 1] = result | ||
| 43 | else | ||
| 44 | print(err) | ||
| 45 | os.exit(1) | ||
| 46 | end | ||
| 47 | end | ||
| 48 | end | ||
| 49 | local output <close> = (function() | ||
| 50 | local _with_1 = io.open(tostring(outputFolder) .. "/" .. tostring(compiledFile), "w+") | ||
| 51 | _with_1:write(table.concat(codes)) | ||
| 52 | return _with_1 | ||
| 53 | end)() | ||
| 54 | end | ||
| 55 | return _with_0 | ||
| 56 | end)() | ||
| 57 | end | ||
