From 784818045460880c5705d159a74358d90ec62920 Mon Sep 17 00:00:00 2001 From: cflmy Date: Tue, 4 Aug 2026 16:03:10 +0800 Subject: [PATCH] Release v0.0.3: function end, paragraph comments, logo, and welcome polish. End nested functions with ---/***/empty return; blank-line comment paragraphs in lex and view; brand favicon/logo; bump crate to 0.0.3. Co-authored-by: Cursor --- Cargo.lock | 2 +- Cargo.toml | 2 +- doc/design/code-vs-comment.md | 13 +++- doc/design/markdown-mapping.md | 47 ++++++++----- doc/design/return-hr-and-code-surface.md | 11 +-- public/00-welcome.mq.md | 25 +++++-- public/keywords/print.mq.md | 2 + scripts/publish-release.py | 84 ++++++++++++----------- src/lex/mod.rs | 81 +++++++++++++++++++--- src/parse/mod.rs | 39 +++++++++-- src/view/html.rs | 48 +++++++++++-- src/view/render.rs | 42 +++++++++--- tests/gold.rs | 44 ++++++++++++ tests/structure/fn-end-empty-return.mq.md | 15 ++++ tests/structure/fn-end-hr.mq.md | 15 ++++ tests/structure/paragraph-comment.mq.md | 11 +++ 16 files changed, 380 insertions(+), 101 deletions(-) create mode 100644 tests/structure/fn-end-empty-return.mq.md create mode 100644 tests/structure/fn-end-hr.mq.md create mode 100644 tests/structure/paragraph-comment.mq.md diff --git a/Cargo.lock b/Cargo.lock index 7bd219b..7fc73a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -210,7 +210,7 @@ checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" [[package]] name = "marqdo" -version = "0.0.2" +version = "0.0.3" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 85f7f34..f49b399 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "marqdo" -version = "0.0.2" +version = "0.0.3" edition = "2021" license = "Apache-2.0" description = "Marqdo — Markdown markers as an interpreted programming language" diff --git a/doc/design/code-vs-comment.md b/doc/design/code-vs-comment.md index 125871b..1d3c0ee 100644 --- a/doc/design/code-vs-comment.md +++ b/doc/design/code-vs-comment.md @@ -2,7 +2,7 @@ | | | |---|---| -| 状态 | 与 mapping v0.1 / keywords 对齐 | +| 状态 | 与 mapping v0.1 / keywords 对齐(成段注释) | | 日期 | 2026-08-04 | --- @@ -11,12 +11,19 @@ | 层 | 形态 | 角色 | |----|------|------| -| **叙述面** | 无标记行 | 注释;内部标记无语义 | +| **叙述面** | 成段注释(空行分段) | 注释;段内任意标记无语义 | | **Marqdo 可执行面** | 结构标记 + `*语句*` + `**返回**` | 本语言程序 | | **外联面** | ` ```lang ` | 其它语言(FFI) | 输出属于可执行面里的**函数调用**(`> print …`),见 [keywords.md](keywords.md)。 +### 成段注释 + +- 以**空行**划分段落。 +- 段首行:首字符非标记 → 注释。 +- 段内续行:一律注释(即使以 `` ` `` / `-` 等开头)。 +- 叙述段与可执行代码之间**必须空一行**,否则 `> print` 等会被吞进注释段。 + --- ## 语句 vs 返回 vs 输出 @@ -25,4 +32,6 @@ |-----------|------|------------| | `*…*` | 程序语句 | 是 | | `**…**` | 返回值 | 是 | +| `****` / 空粗体 | 空返回 + 结束函数体 | 是 | | `> print …` | 打印副作用 | 否(内置函数) | +| 函数体 `---` / `***` | 结束函数体 | 是(边界) | diff --git a/doc/design/markdown-mapping.md b/doc/design/markdown-mapping.md index af364e7..77462ef 100644 --- a/doc/design/markdown-mapping.md +++ b/doc/design/markdown-mapping.md @@ -14,22 +14,24 @@ Markdown **标记即语法**。输出**不是**语言架构原语,而是内置 ## 1. 哲学 1. `.mq.md`:打开即文档,运行即程序。 -2. **无标记行 = 叙述注释**(内部任何标记无语义)。 +2. **叙述注释**以空行分段:段首无标记 → 注释;段内续行一律注释(见 §2)。 3. **可执行**靠标记:结构标记(`#` `>` `+` `-` 表…)与 **斜体语句** / **粗体返回**。 -4. 作用域 = `#` 层数;入口 = `index.mq.md`。 +4. 作用域 = `#` 层数;入口 = `index.mq.md`。函数体可用 `---` / `***` 或空返回收束(见 §11)。 --- -## 2. 行首判别 +## 2. 行首判别与成段注释 -跳过前导空白后: +跳过前导空白后,对**段首行**(空行之后的第一行,或文件起始): | 首字符 | 分类 | |--------|------| | 普通文字 / 空 | **注释** | | 标记字符 | **代码** | -标记含:`#` `*` `>` `+` `-` `` ` `` `|`、有序数字、围栏 `` ` ``、以及函数体内的分割线 `---` / `***`(见 §11)。 +标记含:`#` `*` `>` `+` `-` `` ` `` `|`、有序数字、围栏 `` ` ``、以及函数体内的结束分割线 `---` / `***`(见 §11)。 + +**成段注释(空行分段)**:段首一旦判定为注释,则直至下一空行之前的所有非空行一律为注释——即使续行以 `` ` `` / `-` / `*` 等开头也不升级为代码。叙述与可执行代码之间**必须空一行**。例外:单独一行的 `---` / `***` / `****`(函数结束或 frontmatter 闭合)始终为代码,并打断注释段。 --- @@ -46,10 +48,11 @@ Markdown **标记即语法**。输出**不是**语言架构原语,而是内置 | frontmatter `> path.mq.md` | 跨文件导入 | | `*…*` | **程序语句**(绑定、表达式句、可写的调用句等) | | `**…**` | **返回值**(架构级;函数结果) | -| 无标记行 | 注释 | +| `****` / `**` + 空白 + `**` | **空返回**(`None`),并结束本函数体 | +| 无标记行 / 成段续行 | 注释(空行分段,见 §2) | | GFM 表格 | 集合 | | ` ```lang ` | 外联异种代码 | -| `---` / `***` | **可选**:框住分支/循环块(美化/分组;v0.1 不强制,见 §11) | +| 函数体内 `---` / `***` | **结束本函数体**(无返回值函数的收束;见 §11) | ### 输出不是架构 @@ -176,32 +179,38 @@ v0.1 **推荐**绑定写在斜体语句内,以保持「语句=斜体」一致 --- -## 11. 分割线框住分支/循环(可选、非强制) +## 11. 函数体结束(`---` / `***` / 空返回) -允许用 `---` 或 `***` 将分支/循环块视觉框起来,便于阅读: +无返回值(或已写完副作用)的函数,在体末用分割线收束,避免后续同级语句被吞进嵌套函数: ```markdown ---- -+ `x` > 0 - > print text=正 -+ * - > print text=其它 +# main + +> 问候 谁=World + +## 问候 + - 谁 + +> print text=Hello `谁`! + --- ``` | 约定 | 说明 | |------|------| -| v0.1 | **不强制**;无框同样合法 | -| 语义 | 若使用,框内仍是原列表语义;分割线本身不产生控制流 | -| 保留 | 日后若缺「块」类关键语法,可升级分割线为强制块边界 | -| 消歧 | 仅文件开头的 `---` 对 = frontmatter;函数体内成对/成段的 `---`/`***` = 可选框 | +| `---` 或 `***` | 函数体**顶层**单独一行(长度 ≥ 3 且全为 `-` 或全为 `*`)→ **结束本函数**;后续语句属于外层 | +| `****` / 空粗体 | 空返回(值为 `None`),并同样结束本函数体 | +| 有值 `**expr**` | 普通返回;**不**自动截断后续兄弟句(仍可用分割线或下一同级/更浅标题收束) | +| Frontmatter | 仅**文件开头**成对 `---` = 元信息;与函数体内结束符消歧 | +| 分支/循环臂内 | 分割线仍可忽略(噪声),不截断外层函数 | + +曾设想的「可选框住分支/循环」废止,分割线专用于函数收束。 --- ## 12. v0.1 非目标 - break/continue、完整错误模型、静态类型、完整 FFI -- 强制分割线框 - 用 `*` 作无序列表符 --- diff --git a/doc/design/return-hr-and-code-surface.md b/doc/design/return-hr-and-code-surface.md index 77d0e5d..04f2a95 100644 --- a/doc/design/return-hr-and-code-surface.md +++ b/doc/design/return-hr-and-code-surface.md @@ -2,7 +2,7 @@ | | | |---|---| -| 状态 | 已决议(并入 mapping v0.1 + keywords) | +| 状态 | 已决议(并入 mapping v0.1 + keywords;2026-08-04 修订函数收束) | | 日期 | 2026-08-04 | --- @@ -10,9 +10,10 @@ ## 决议 1. **`*…*` = 程序语句**。 -2. **`**…**` = 返回值**(架构级)。 +2. **`**…**` = 返回值**(架构级);空粗体 `****` / `** **` = 空返回(`None`)并结束函数体。 3. **输出**用内置函数 **`print`**(英文),不是粗体,不是中文名。 -4. **`---` / `***`**:可选框住分支/循环,不强制。 -5. **否决**:无标记行 = 默认代码。 +4. **`---` / `***`(函数体顶层)**:结束本函数体(无返回值函数收束);**不是**分支/循环装饰框。 +5. **成段注释**:空行分段;段内续行不因首字符升级为代码。 +6. **否决**:无标记行 = 默认代码。 -详见 [keywords.md](keywords.md)、[markdown-mapping.md](markdown-mapping.md)。 +详见 [keywords.md](keywords.md)、[markdown-mapping.md](markdown-mapping.md)、[code-vs-comment.md](code-vs-comment.md)。 diff --git a/public/00-welcome.mq.md b/public/00-welcome.mq.md index 111a68b..39e51a3 100644 --- a/public/00-welcome.mq.md +++ b/public/00-welcome.mq.md @@ -5,12 +5,27 @@ description: 用户文档首页 — 代码即文档 # main -产品名 Marqdo = Marq(Markdown)+ do(执行)。 +阅读到这里的朋友你好!我是marqdo的开发者,很高兴你看到这个网站,marqdo是一个代码即文档的编程语言,作者想要做这个项目来源于一个小小的想法,AI输出的首选语言是markdown,为什么不能基于markdown创建一个新式的编程语言,不再区分文档和代码,代码写出来就是一份文档,文档也是代码(这个项目的野心实际更大些,项目立项之处就调研了谷歌OKF规范,计划自动生成YAML使得代码和文档能够自动的变成知识库,与此同时还有更多可能,例如规范化生成的PPT)。 -打开这份 .mq.md,你看到的是说明;用解释器运行它,同一份文件就是程序。 +所以marqdo产生了,为了确保我们的新语言能够百分百被markdown渲染,这门语言甚至采用了`.mq.md`的双层嵌套后缀,所以不需要有压力使用这门语言,就算出现了巨大的问题,就当让ai写文档好了,如果成功了,试想这样一种场景,你不再需要让ai生成代码的文档,ai写的代码能够便捷的被你读懂,至少能省点token,毕竟烧了太多,钱包容易饿瘦。 -无标记的段落是注释,不会执行。下面这一行才是真正的调用: +这门语言还是起步阶段,目前计划是制作一个解释型的语言,现在的marqdo支持一些特定的语法结构和关键字,并且允许自由的输出调试信息,以及直接通过前端预览各个代码块,生成静态文件,是的,没错,这个网站就是marqdo制作的,至少我相信marqdo会成为一个博客工具。 -> print text=欢迎来到 Marqdo:代码即文档,文档即代码。 +除了部分内置的关键字,marqdo并不限制必须使用英文编程,当然这并不意味着我要开发一个中文编程系统,事实上,这是由于文档即代码、代码即文档的结构决定的,如果只支持英文,那还有什么作用?还要掌握一门语言,这并不是让人愉悦的阅读体验,所以marqdo会长期支持多语言编程的可能。 -侧栏可浏览 structure(结构)、keywords(关键字)、features(特性迭代)。三者均可执行。 +欢迎各位加入开源库,共同建设和完成这个项目[marqdo的github仓库链接](https://github.com/cflmy/marqdo) + +最后,引用所有程序员的开始欢迎各位: + +> 问候 marqdo + +如果你是一个敏锐的程序员应该会察觉到一个小问题,这个问题的解决方案是像下面这样的,我其实并不知道这样解决是否正确,但是我暂且放在这里,欢迎你,敏锐的程序元朋友。 + +> 问候 谁=marqdo user + +## 问候 + - 谁 + +> print text=欢迎,`谁`! + +--- diff --git a/public/keywords/print.mq.md b/public/keywords/print.mq.md index 0e4f48f..0d28005 100644 --- a/public/keywords/print.mq.md +++ b/public/keywords/print.mq.md @@ -10,3 +10,5 @@ description: 具名与位置两种写法 > print text=named form > print positional + +这里的设计思路是具名实参允许空格的传入,位置实参则不允许。 \ No newline at end of file diff --git a/scripts/publish-release.py b/scripts/publish-release.py index 72d9770..4fa92cc 100644 --- a/scripts/publish-release.py +++ b/scripts/publish-release.py @@ -1,41 +1,23 @@ # -*- coding: utf-8 -*- -"""Create GitHub release v0.0.2 and upload Windows binaries using git credentials.""" +"""Create a GitHub release from Cargo.toml version and upload Windows binaries.""" from __future__ import annotations import json +import re import subprocess import urllib.error import urllib.request from pathlib import Path REPO = "cflmy/marqdo" -TAG = "v0.0.2" -TITLE = "v0.0.2" -NOTES = """## Marqdo v0.0.2 -User docs site, view polish, and project layout cleanup. -### Highlights -- User-facing executable docs in `public/`; static site on `gh-pages` -- Gold fixtures moved under `tests/{structure,keywords,errors}/` -- `marqdo view` / `view output` restyle; catalog CLI -- Default open first file; cleaner diagnostic paths on Windows - -### Assets -- `marqdo-0.0.2-x86_64-pc-windows-msvc.exe` — Windows x64 binary -- `marqdo-0.0.2-x86_64-pc-windows-msvc.zip` — same binary zipped - -```text -marqdo --version -marqdo run tests/structure/hello.mq.md -marqdo view public -``` -""" - -ASSETS = [ - Path("target/dist/marqdo-0.0.2-x86_64-pc-windows-msvc.exe"), - Path("target/dist/marqdo-0.0.2-x86_64-pc-windows-msvc.zip"), -] +def crate_version() -> str: + text = Path("Cargo.toml").read_text(encoding="utf-8") + m = re.search(r'(?m)^version\s*=\s*"([^"]+)"', text) + if not m: + raise SystemExit("version not found in Cargo.toml") + return m.group(1) def git_token() -> str: @@ -70,24 +52,48 @@ def api(method: str, url: str, token: str, data: bytes | None = None, content_ty def main() -> None: - for p in ASSETS: + ver = crate_version() + tag = f"v{ver}" + stem = f"marqdo-{ver}-x86_64-pc-windows-msvc" + assets = [ + Path(f"target/dist/{stem}.exe"), + Path(f"target/dist/{stem}.zip"), + ] + for p in assets: if not p.exists(): raise SystemExit(f"missing asset: {p}") + notes = f"""## Marqdo {tag} + +### Highlights +- Function body end via `---` / `***` or empty `****` return +- Blank-line paragraph comments (lex + view rendering) +- Brand logo / favicon from s3.cflmy.cn +- Welcome docs and call-arg spaced named values + +### Assets +- `{stem}.exe` — Windows x64 binary +- `{stem}.zip` — same binary zipped + +```text +marqdo --version +marqdo run public/00-welcome.mq.md +marqdo view public +``` +""" + token = git_token() - # If release already exists, reuse it; else create. - status, existing = 0, None + existing = None try: - status, existing = api( + _, existing = api( "GET", - f"https://api.github.com/repos/{REPO}/releases/tags/{TAG}", + f"https://api.github.com/repos/{REPO}/releases/tags/{tag}", token, ) except SystemExit as e: if "404" not in str(e): raise - existing = None if existing: release_id = existing["id"] @@ -96,9 +102,9 @@ def main() -> None: else: payload = json.dumps( { - "tag_name": TAG, - "name": TITLE, - "body": NOTES, + "tag_name": tag, + "name": tag, + "body": notes, "draft": False, "prerelease": False, } @@ -114,14 +120,14 @@ def main() -> None: upload_url = created["upload_url"].split("{", 1)[0] print(f"created release id={release_id}") - # Delete existing assets with same names (idempotent re-upload) _, rel = api( "GET", f"https://api.github.com/repos/{REPO}/releases/{release_id}", token, ) + want = {p.name for p in assets} for asset in rel.get("assets", []): - if asset["name"] in {p.name for p in ASSETS}: + if asset["name"] in want: api( "DELETE", f"https://api.github.com/repos/{REPO}/releases/assets/{asset['id']}", @@ -129,14 +135,14 @@ def main() -> None: ) print(f"deleted old asset {asset['name']}") - for path in ASSETS: + for path in assets: data = path.read_bytes() url = f"{upload_url}?name={path.name}" ctype = "application/zip" if path.suffix == ".zip" else "application/octet-stream" _, uploaded = api("POST", url, token, data=data, content_type=ctype) print(f"uploaded {path.name} -> {uploaded.get('browser_download_url')}") - print(f"OK https://github.com/{REPO}/releases/tag/{TAG}") + print(f"OK https://github.com/{REPO}/releases/tag/{tag}") if __name__ == "__main__": diff --git a/src/lex/mod.rs b/src/lex/mod.rs index 1f0ccff..fcd2976 100644 --- a/src/lex/mod.rs +++ b/src/lex/mod.rs @@ -1,7 +1,8 @@ //! Line classification (M1) — no Flex. //! -//! Unmarked lines are comments; lines whose first non-whitespace character -//! opens a Marqdo/Markdown marker are code. +//! Narrative comments are paragraph-scoped: blank lines separate paragraphs. +//! After a comment line, subsequent non-blank lines stay comments until a blank +//! (so mid-paragraph lines starting with `` ` `` are not treated as code). use std::fmt; @@ -40,6 +41,9 @@ fn is_code_starter(c: char) -> bool { } /// Classify a single logical line (no trailing newline required). +/// +/// This is the **paragraph-start** rule only. Prefer [`classify_source`] for +/// full-file classification (paragraph continuation). pub fn classify_line(text: &str) -> LineKind { let trimmed = text.trim_end_matches(['\r', '\n']); if trimmed.chars().all(|c| c.is_whitespace()) { @@ -53,7 +57,11 @@ pub fn classify_line(text: &str) -> LineKind { } } -/// Classify every line of a source file. +/// Classify every line of a source file (blank-line paragraph comments). +/// +/// Structural end markers (`---` / `***` / empty `****`) always stay Code and +/// break a comment paragraph, so frontmatter closers and function ends work +/// even when adjacent to narrative. pub fn classify_source(source: &str) -> Vec { let source = source.strip_prefix('\u{feff}').unwrap_or(source); let lines: Vec<&str> = if source.is_empty() { @@ -62,15 +70,46 @@ pub fn classify_source(source: &str) -> Vec { source.lines().collect() }; - lines - .into_iter() - .enumerate() - .map(|(i, text)| ClassifiedLine { + let mut out = Vec::with_capacity(lines.len()); + let mut in_comment_paragraph = false; + + for (i, text) in lines.into_iter().enumerate() { + let base = classify_line(text); + let trimmed = text.trim(); + let structural = is_structural_code_line(trimmed); + let kind = match base { + LineKind::Blank => { + in_comment_paragraph = false; + LineKind::Blank + } + LineKind::Comment => { + in_comment_paragraph = true; + LineKind::Comment + } + LineKind::Code if structural => { + in_comment_paragraph = false; + LineKind::Code + } + LineKind::Code if in_comment_paragraph => LineKind::Comment, + LineKind::Code => LineKind::Code, + }; + out.push(ClassifiedLine { line_no: (i + 1) as u32, - kind: classify_line(text), + kind, text: text.to_string(), - }) - .collect() + }); + } + out +} + +/// Function-end / frontmatter HR or empty bold return — never swallowed by paragraphs. +fn is_structural_code_line(trimmed: &str) -> bool { + if trimmed.len() >= 3 + && (trimmed.chars().all(|c| c == '-') || trimmed.chars().all(|c| c == '*')) + { + return true; + } + false } /// Human-readable dump for `--dump-lines`. @@ -120,11 +159,31 @@ mod tests { assert_eq!(classify_line("`x` = 1"), LineKind::Code); } + #[test] + fn paragraph_comment_keeps_backtick_continuation() { + let src = "采用了\n`.mq.md`的双层后缀\n\n> print text=ok\n"; + let lines = classify_source(src); + assert_eq!(lines[0].kind, LineKind::Comment); + assert_eq!(lines[1].kind, LineKind::Comment); + assert_eq!(lines[2].kind, LineKind::Blank); + assert_eq!(lines[3].kind, LineKind::Code); + } + + #[test] + fn frontmatter_closing_hr_stays_code() { + let src = "---\ntitle: x\n---\n\n# main\n"; + let lines = classify_source(src); + assert_eq!(lines[0].kind, LineKind::Code); + assert_eq!(lines[1].kind, LineKind::Comment); + assert_eq!(lines[2].kind, LineKind::Code); + assert_eq!(lines[2].text.trim(), "---"); + } + #[test] fn classify_hello_fixture() { let src = include_str!("../../tests/structure/hello.mq.md"); let lines = classify_source(src); - assert!(lines.iter().any(|l| l.kind == LineKind::Code && l.text.contains("print"))); assert!(lines.iter().any(|l| l.kind == LineKind::Comment)); + assert!(lines.iter().any(|l| l.kind == LineKind::Code)); } } diff --git a/src/parse/mod.rs b/src/parse/mod.rs index b047ff3..3f61f9e 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -144,14 +144,29 @@ impl<'a> Cursor<'a> { break; } - // Body until next heading at level <= ours. + // Body until next heading at level <= ours, or explicit end (--- / *** / empty **). while self.skip_noise() { let Some(l) = self.peek() else { break }; let trimmed = l.text.trim(); + // Empty bold return ends the function body. + if is_empty_bold_return(trimmed) { + let span = Span { + line: l.line_no, + col: 1, + }; + self.bump(); + fun.body.push(Stmt::Return { + value: Expr::Literal(Literal::None), + span, + }); + break; + } + + // --- / *** at function body top level ends the function (no return). if is_frame(trimmed) { self.bump(); - continue; + break; } if is_heading(trimmed) { @@ -191,10 +206,14 @@ impl<'a> Cursor<'a> { bail!("{span}: unexpected frame line as statement"); } - // Bold return **…** + // Bold return **…** (empty inner → None) if trimmed.starts_with("**") && trimmed.ends_with("**") && trimmed.len() >= 4 { let inner = &trimmed[2..trimmed.len() - 2]; - let value = parse_expr_str(inner)?; + let value = if inner.trim().is_empty() { + Expr::Literal(Literal::None) + } else { + parse_expr_str(inner)? + }; return Ok(Stmt::Return { value, span }); } @@ -481,9 +500,21 @@ fn is_frame(trimmed: &str) -> bool { if trimmed.len() < 3 { return false; } + // Empty bold return `****` is handled separately; frames are --- or *** (etc.). + if is_empty_bold_return(trimmed) { + return false; + } trimmed.chars().all(|c| c == '-') || trimmed.chars().all(|c| c == '*') } +/// `****` or `**` + whitespace only + `**`. +fn is_empty_bold_return(trimmed: &str) -> bool { + if !(trimmed.starts_with("**") && trimmed.ends_with("**") && trimmed.len() >= 4) { + return false; + } + trimmed[2..trimmed.len() - 2].trim().is_empty() +} + fn is_ordered_branch(trimmed: &str) -> bool { strip_ordered(trimmed).is_some() } diff --git a/src/view/html.rs b/src/view/html.rs index e7dddc8..c4f54ff 100644 --- a/src/view/html.rs +++ b/src/view/html.rs @@ -78,6 +78,21 @@ a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; } z-index: 20; } .topbar .brand { margin: 0; font-size: 1.05rem; font-weight: 600; letter-spacing: -0.022em; } +.brand-row { + display: flex; + align-items: center; + gap: 0.55rem; +} +.brand-row .brand { margin: 0; } +.logo { + width: 1.75rem; + height: 1.75rem; + object-fit: contain; + flex-shrink: 0; + border-radius: 6px; +} +.topbar .logo { width: 1.45rem; height: 1.45rem; } +.nav-brand .logo { width: 2rem; height: 2rem; } .nav-btn { appearance: none; border: 1px solid var(--line); @@ -112,7 +127,8 @@ a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; } align-self: start; height: 100vh; } -.nav-brand { display: block; padding: 0 0.35rem; } +.nav-brand { display: block; padding: 0 0.35rem; margin-bottom: 1.15rem; } +.nav-brand .tagline { margin: 0.1rem 0 0; } .brand { font-size: 1.35rem; font-weight: 700; @@ -122,9 +138,10 @@ a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; } .tagline { color: var(--muted); font-size: 0.78rem; - margin: 0 0 1.5rem; + margin: 0; font-weight: 500; } +.nav > h2:first-of-type { margin-top: 0.35rem; } .nav h2 { font-size: 0.68rem; text-transform: uppercase; @@ -286,7 +303,15 @@ section.block > h2 { color: var(--ink); font-weight: 500; } -.comment-text { color: var(--muted); font-size: 0.92rem; } +.comment-text { + color: var(--muted); + font-size: 0.92rem; + display: block; + margin-top: 0.35rem; + white-space: pre-line; + line-height: 1.55; + max-width: 42em; +} code.expr { font-family: var(--mono); font-size: 0.84rem; @@ -352,6 +377,9 @@ pub fn layout(title: &str, nav: &str, main: &str) -> String { {title} · marqdo + + + @@ -359,13 +387,21 @@ pub fn layout(title: &str, nav: &str, main: &str) -> String {
-

marqdo

+
+ +

marqdo

+
diff --git a/src/view/render.rs b/src/view/render.rs index ab97936..5cad9e0 100644 --- a/src/view/render.rs +++ b/src/view/render.rs @@ -77,6 +77,20 @@ fn skip_frontmatter_end(lines: &[ClassifiedLine]) -> Option { fn emit_comments(lines: &[ClassifiedLine], from_line: u32, before_line: u32) -> String { let mut s = String::new(); + let mut paragraph: Vec = Vec::new(); + + let flush = |paragraph: &mut Vec, s: &mut String| { + if paragraph.is_empty() { + return; + } + let text = paragraph.join("\n"); + paragraph.clear(); + s.push_str(&format!( + "
comment{}
", + escape(&text) + )); + }; + for l in lines { if l.line_no < from_line { continue; @@ -84,17 +98,18 @@ fn emit_comments(lines: &[ClassifiedLine], from_line: u32, before_line: u32) -> if l.line_no >= before_line { break; } - if l.kind == LineKind::Comment { - let text = l.text.trim(); - if text.is_empty() { - continue; + match l.kind { + LineKind::Comment => { + let text = l.text.trim(); + if !text.is_empty() { + paragraph.push(text.to_string()); + } } - s.push_str(&format!( - "
comment{}
", - escape(text) - )); + LineKind::Blank => flush(&mut paragraph, &mut s), + LineKind::Code => flush(&mut paragraph, &mut s), } } + flush(&mut paragraph, &mut s); s } @@ -421,4 +436,15 @@ mod tests { assert!(!html.contains("Binary {")); assert!(!html.contains("Literal(Int")); } + + #[test] + fn comments_render_as_paragraphs() { + let src = "段首说明\n续行仍属同段\n\n下一段\n\n# main\n\n> print text=x\n"; + let module = crate::parse::parse_source(src).unwrap(); + let html = render_module_structure(&module, src); + let cards = html.matches("comment-card").count(); + assert_eq!(cards, 2, "blank line should split comment paragraphs: {html}"); + assert!(html.contains("段首说明\n续行仍属同段")); + assert!(html.contains("下一段")); + } } diff --git a/tests/gold.rs b/tests/gold.rs index 5d1f990..4677702 100644 --- a/tests/gold.rs +++ b/tests/gold.rs @@ -77,6 +77,22 @@ fn structure_import() { ); } + +#[test] +fn structure_fn_end_hr() { + assert_out("tests/structure/fn-end-hr.mq.md", "Hello World!"); +} + +#[test] +fn structure_fn_end_empty_return() { + assert_out("tests/structure/fn-end-empty-return.mq.md", "Hi Marqdo!"); +} + +#[test] +fn structure_paragraph_comment() { + assert_out("tests/structure/paragraph-comment.mq.md", "ok"); +} + #[test] fn keywords_print() { assert_out( @@ -219,6 +235,34 @@ fn bytecode_import() { ); } + +#[test] +fn bytecode_fn_end_hr() { + assert_out_backend( + "tests/structure/fn-end-hr.mq.md", + "bytecode", + "Hello World!", + ); +} + +#[test] +fn bytecode_fn_end_empty_return() { + assert_out_backend( + "tests/structure/fn-end-empty-return.mq.md", + "bytecode", + "Hi Marqdo!", + ); +} + +#[test] +fn bytecode_paragraph_comment() { + assert_out_backend( + "tests/structure/paragraph-comment.mq.md", + "bytecode", + "ok", + ); +} + #[test] fn catalog_writes_yaml() { let dir = tempfile_dir("mq-cat"); diff --git a/tests/structure/fn-end-empty-return.mq.md b/tests/structure/fn-end-empty-return.mq.md new file mode 100644 index 0000000..eaa24a8 --- /dev/null +++ b/tests/structure/fn-end-empty-return.mq.md @@ -0,0 +1,15 @@ +--- +title: 函数结束 — 空返回 +description: **** 空返回并结束函数体 +--- + +# main + +> 问候 谁=Marqdo + +## 问候 + - 谁 + +> print text=Hi `谁`! + +**** diff --git a/tests/structure/fn-end-hr.mq.md b/tests/structure/fn-end-hr.mq.md new file mode 100644 index 0000000..c0df578 --- /dev/null +++ b/tests/structure/fn-end-hr.mq.md @@ -0,0 +1,15 @@ +--- +title: 函数结束 — 分割线 +description: --- 结束嵌套函数体,后续调用属于外层 +--- + +# main + +> 问候 谁=World + +## 问候 + - 谁 + +> print text=Hello `谁`! + +--- diff --git a/tests/structure/paragraph-comment.mq.md b/tests/structure/paragraph-comment.mq.md new file mode 100644 index 0000000..8e70b8f --- /dev/null +++ b/tests/structure/paragraph-comment.mq.md @@ -0,0 +1,11 @@ +--- +title: 成段注释 +description: 空行分段;段内以 ` 开头的续行仍是注释 +--- + +# main + +说明采用了 +`.mq.md`双层后缀,段内不算代码。 + +> print text=ok