docs: establish marqdo-lint architecture and examples
This commit is contained in:
1 parent
326c9bb119
commit
68b14db095
19 files changed
+1338
No files matched your search
@@ -0,0 +1,23 @@
|
||||
# @knowledge 反例
|
||||
|
||||
## @exec 计算会员价格
|
||||
|
||||
根据用户的会员身份计算最终支付金额。
|
||||
|
||||
`params(原价: Int, 是否会员: Bool)`
|
||||
|
||||
1. 首先判断用户是否有会员资格。
|
||||
|
||||
`if 是否会员`
|
||||
|
||||
**最终价格 = 原价 * 9 // 10**
|
||||
|
||||
`else`
|
||||
|
||||
**最终价格 = 原价**
|
||||
|
||||
`end`
|
||||
|
||||
返回最终应付金额。
|
||||
|
||||
*return 最终价格*
|
||||
@@ -0,0 +1,24 @@
|
||||
# @knowledge 定价示例
|
||||
|
||||
## @exec 计算会员价格
|
||||
|
||||
根据用户的会员身份计算最终支付金额。会员享受九折优惠,
|
||||
非会员维持原价。采用整数运算,避免金额处理中的浮点误差。
|
||||
|
||||
`params(原价: Int, 是否会员: Bool)`
|
||||
|
||||
1. `if 是否会员`:会员享受九折优惠。
|
||||
|
||||
为保持金额计算的确定性,先乘以九,再进行整数除法。
|
||||
|
||||
**最终价格 = 原价 * 9 // 10**
|
||||
|
||||
2. `else`:其余用户保留原价。
|
||||
|
||||
**最终价格 = 原价**
|
||||
|
||||
`end`
|
||||
|
||||
计算结束后返回以最小货币单位表示的最终应付金额。
|
||||
|
||||
*return 最终价格*
|
||||
@@ -0,0 +1,24 @@
|
||||
# @knowledge 定价文档
|
||||
|
||||
## @exec 计算折后价格
|
||||
|
||||
按[折扣设计](#折扣设计)计算金额。输入和输出都使用最小货币单位。
|
||||
|
||||
`params(原价: Int, 分子: Int, 分母: Int)`
|
||||
|
||||
先乘后除可以保持整数计算的确定性;调用者必须提供非零分母。
|
||||
|
||||
**折后价格 = 原价 * 分子 // 分母**
|
||||
|
||||
返回整数折后价格,除法向下截断。
|
||||
|
||||
*return 折后价格*
|
||||
|
||||
## @knowledge 折扣设计
|
||||
|
||||
这里可以自由使用**加粗**、*斜体*和 `code` 解释设计,不会产生执行语句。
|
||||
|
||||
| 约束 | 原因 |
|
||||
|---|---|
|
||||
| 使用最小货币单位 | 避免浮点金额误差 |
|
||||
| 先乘后除 | 明确整数截断位置 |
|
||||
@@ -0,0 +1,32 @@
|
||||
# @knowledge 库存示例
|
||||
|
||||
## @exec 检查库存并累计可用量
|
||||
|
||||
只在仓库启用时统计库存;对每个未统计条目进行累计。
|
||||
位置从零下标开始,返回最小计量单位的总量。
|
||||
|
||||
`params(仓库启用: Bool, 数量列表: List)`
|
||||
|
||||
**总量 = 0**
|
||||
|
||||
**位置 = 0**
|
||||
|
||||
1. `if 仓库启用`:仅在启用状态下统计库存。
|
||||
|
||||
- `while 位置 < 长度(数量列表)`:按位置依次统计,到达列表末尾时终止。
|
||||
|
||||
**总量 = 总量 + 数量列表[位置]**
|
||||
|
||||
**位置 = 位置 + 1**
|
||||
|
||||
`end`
|
||||
|
||||
2. `else`:仓库未启用时,总量保持为零。
|
||||
|
||||
不执行任何库存统计。
|
||||
|
||||
`end`
|
||||
|
||||
返回累计总量;本函数不会修改库存来源。
|
||||
|
||||
*return 总量*
|
||||
@@ -0,0 +1,30 @@
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use comrak::{markdown_to_html, Options};
|
||||
|
||||
fn main() {
|
||||
let manifest = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let fixtures = [
|
||||
("examples/good/branches.mq.md", "examples/rendered/branches.html"),
|
||||
("examples/bad/branch-single-item.mq.md", "examples/rendered/branch-single-item.html"),
|
||||
("examples/nested/inventory.mq.md", "examples/rendered/inventory.html"),
|
||||
("examples/knowledge/discount.mq.md", "examples/rendered/discount.html"),
|
||||
];
|
||||
let mut options = Options::default();
|
||||
options.extension.table = true;
|
||||
options.extension.strikethrough = true;
|
||||
options.extension.tasklist = true;
|
||||
options.extension.math_dollars = true;
|
||||
options.extension.math_dollars_block = true;
|
||||
options.extension.front_matter_delimiter = Some("---".to_string());
|
||||
|
||||
for (source, target) in fixtures {
|
||||
let source_path = manifest.join(source);
|
||||
let markdown = fs::read_to_string(&source_path).expect("读取渲染 Fixture");
|
||||
let body = markdown_to_html(&markdown, &options);
|
||||
let html = format!("<!doctype html>\n<html lang=\"zh-CN\">\n<meta charset=\"utf-8\">\n<title>Marqdo Lint Review Fixture</title>\n<body>\n{body}</body>\n</html>\n");
|
||||
let target = manifest.join(target);
|
||||
fs::create_dir_all(target.parent().expect("Fixture 父目录")).expect("创建渲染目录");
|
||||
fs::write(target, html).expect("写入渲染 Fixture");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<meta charset="utf-8">
|
||||
<title>Marqdo Lint Review Fixture</title>
|
||||
<body>
|
||||
<h1>@knowledge 反例</h1>
|
||||
<h2>@exec 计算会员价格</h2>
|
||||
<p>根据用户的会员身份计算最终支付金额。</p>
|
||||
<p><code>params(原价: Int, 是否会员: Bool)</code></p>
|
||||
<ol>
|
||||
<li>
|
||||
<p>首先判断用户是否有会员资格。</p>
|
||||
<p><code>if 是否会员</code></p>
|
||||
<p><strong>最终价格 = 原价 * 9 // 10</strong></p>
|
||||
<p><code>else</code></p>
|
||||
<p><strong>最终价格 = 原价</strong></p>
|
||||
<p><code>end</code></p>
|
||||
</li>
|
||||
</ol>
|
||||
<p>返回最终应付金额。</p>
|
||||
<p><em>return 最终价格</em></p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,26 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<meta charset="utf-8">
|
||||
<title>Marqdo Lint Review Fixture</title>
|
||||
<body>
|
||||
<h1>@knowledge 定价示例</h1>
|
||||
<h2>@exec 计算会员价格</h2>
|
||||
<p>根据用户的会员身份计算最终支付金额。会员享受九折优惠,
|
||||
非会员维持原价。采用整数运算,避免金额处理中的浮点误差。</p>
|
||||
<p><code>params(原价: Int, 是否会员: Bool)</code></p>
|
||||
<ol>
|
||||
<li>
|
||||
<p><code>if 是否会员</code>:会员享受九折优惠。</p>
|
||||
<p>为保持金额计算的确定性,先乘以九,再进行整数除法。</p>
|
||||
<p><strong>最终价格 = 原价 * 9 // 10</strong></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>else</code>:其余用户保留原价。</p>
|
||||
<p><strong>最终价格 = 原价</strong></p>
|
||||
</li>
|
||||
</ol>
|
||||
<p><code>end</code></p>
|
||||
<p>计算结束后返回以最小货币单位表示的最终应付金额。</p>
|
||||
<p><em>return 最终价格</em></p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,35 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<meta charset="utf-8">
|
||||
<title>Marqdo Lint Review Fixture</title>
|
||||
<body>
|
||||
<h1>@knowledge 定价文档</h1>
|
||||
<h2>@exec 计算折后价格</h2>
|
||||
<p>按<a href="#%E6%8A%98%E6%89%A3%E8%AE%BE%E8%AE%A1">折扣设计</a>计算金额。输入和输出都使用最小货币单位。</p>
|
||||
<p><code>params(原价: Int, 分子: Int, 分母: Int)</code></p>
|
||||
<p>先乘后除可以保持整数计算的确定性;调用者必须提供非零分母。</p>
|
||||
<p><strong>折后价格 = 原价 * 分子 // 分母</strong></p>
|
||||
<p>返回整数折后价格,除法向下截断。</p>
|
||||
<p><em>return 折后价格</em></p>
|
||||
<h2>@knowledge 折扣设计</h2>
|
||||
<p>这里可以自由使用<strong>加粗</strong>、<em>斜体</em>和 <code>code</code> 解释设计,不会产生执行语句。</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>约束</th>
|
||||
<th>原因</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>使用最小货币单位</td>
|
||||
<td>避免浮点金额误差</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>先乘后除</td>
|
||||
<td>明确整数截断位置</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,34 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<meta charset="utf-8">
|
||||
<title>Marqdo Lint Review Fixture</title>
|
||||
<body>
|
||||
<h1>@knowledge 库存示例</h1>
|
||||
<h2>@exec 检查库存并累计可用量</h2>
|
||||
<p>只在仓库启用时统计库存;对每个未统计条目进行累计。
|
||||
位置从零下标开始,返回最小计量单位的总量。</p>
|
||||
<p><code>params(仓库启用: Bool, 数量列表: List)</code></p>
|
||||
<p><strong>总量 = 0</strong></p>
|
||||
<p><strong>位置 = 0</strong></p>
|
||||
<ol>
|
||||
<li>
|
||||
<p><code>if 仓库启用</code>:仅在启用状态下统计库存。</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p><code>while 位置 < 长度(数量列表)</code>:按位置依次统计,到达列表末尾时终止。</p>
|
||||
<p><strong>总量 = 总量 + 数量列表[位置]</strong></p>
|
||||
<p><strong>位置 = 位置 + 1</strong></p>
|
||||
<p><code>end</code></p>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>else</code>:仓库未启用时,总量保持为零。</p>
|
||||
<p>不执行任何库存统计。</p>
|
||||
</li>
|
||||
</ol>
|
||||
<p><code>end</code></p>
|
||||
<p>返回累计总量;本函数不会修改库存来源。</p>
|
||||
<p><em>return 总量</em></p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user