feat(markdown,value): record code span delimiters, inert-executable code and profile refinements
- md code nodes now carry `ticks` (delimiter length) so executable payload offsets inside code spans map back to exact source bytes instead of pointing at backticks; this keeps diagnostics precise for mixed text/code payloads. - value: add the markdown.inert_executable warning code and a small clippy fix, without changing the wire format. - spec: document the code-span tick metadata, declare strikethrough lazy, and make the inert-execution warning explicit for nodes outside any function. - workspace dependencies: add unicode-ident (grammar) and glob (capability path patterns) for the frontend/host layers. Tests: 15 markdown + 10 value + 2 span tests pass; fmt/clippy clean.
This commit is contained in:
1 parent
4db6e6afd6
commit
62a9af05fd
9 files changed
+34
-15
No files matched your search
Generated
-3
@@ -372,7 +372,6 @@ dependencies = [
|
|||||||
"marqdo-markdown",
|
"marqdo-markdown",
|
||||||
"marqdo-span",
|
"marqdo-span",
|
||||||
"marqdo-value",
|
"marqdo-value",
|
||||||
"serde",
|
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sha2",
|
"sha2",
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
@@ -421,13 +420,11 @@ dependencies = [
|
|||||||
name = "marqdo-math"
|
name = "marqdo-math"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"marqdo-span",
|
|
||||||
"marqdo-value",
|
"marqdo-value",
|
||||||
"num-bigint 0.5.1",
|
"num-bigint 0.5.1",
|
||||||
"num-rational",
|
"num-rational",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"serde",
|
"serde",
|
||||||
"thiserror",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -55,4 +55,6 @@ tempfile = "3"
|
|||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
clap = { version = "4", features = ["derive"] }
|
clap = { version = "4", features = ["derive"] }
|
||||||
walkdir = "2"
|
walkdir = "2"
|
||||||
|
glob = "0.3"
|
||||||
unicode-normalization = "0.1"
|
unicode-normalization = "0.1"
|
||||||
|
unicode-ident = "1"
|
||||||
@@ -74,8 +74,12 @@ pub enum MdKind {
|
|||||||
Emph,
|
Emph,
|
||||||
/// GFM strikethrough.
|
/// GFM strikethrough.
|
||||||
Strikethrough,
|
Strikethrough,
|
||||||
/// Inline code span.
|
/// Inline code span. `ticks` records the delimiter length so the literal
|
||||||
Code,
|
/// payload can be mapped back to exact source offsets.
|
||||||
|
Code {
|
||||||
|
/// Number of backtick delimiters.
|
||||||
|
ticks: usize,
|
||||||
|
},
|
||||||
/// Fenced or indented code block.
|
/// Fenced or indented code block.
|
||||||
CodeBlock {
|
CodeBlock {
|
||||||
/// Whether the block was fenced.
|
/// Whether the block was fenced.
|
||||||
@@ -176,7 +180,7 @@ impl MdNode {
|
|||||||
| MdKind::Strong
|
| MdKind::Strong
|
||||||
| MdKind::Emph
|
| MdKind::Emph
|
||||||
| MdKind::Strikethrough
|
| MdKind::Strikethrough
|
||||||
| MdKind::Code
|
| MdKind::Code { .. }
|
||||||
| MdKind::Math { .. }
|
| MdKind::Math { .. }
|
||||||
| MdKind::Link { .. }
|
| MdKind::Link { .. }
|
||||||
| MdKind::Image { .. }
|
| MdKind::Image { .. }
|
||||||
@@ -208,7 +212,7 @@ impl MdKind {
|
|||||||
MdKind::Strong => "strong",
|
MdKind::Strong => "strong",
|
||||||
MdKind::Emph => "emph",
|
MdKind::Emph => "emph",
|
||||||
MdKind::Strikethrough => "strikethrough",
|
MdKind::Strikethrough => "strikethrough",
|
||||||
MdKind::Code => "code",
|
MdKind::Code { .. } => "code",
|
||||||
MdKind::CodeBlock { .. } => "code_block",
|
MdKind::CodeBlock { .. } => "code_block",
|
||||||
MdKind::Math { .. } => "math",
|
MdKind::Math { .. } => "math",
|
||||||
MdKind::MathBlock => "math_block",
|
MdKind::MathBlock => "math_block",
|
||||||
|
|||||||
@@ -169,7 +169,12 @@ fn map_value(value: &NodeValue) -> (MdKind, Option<String>) {
|
|||||||
NodeValue::Strong(_) => (MdKind::Strong, None),
|
NodeValue::Strong(_) => (MdKind::Strong, None),
|
||||||
NodeValue::Emph(_) => (MdKind::Emph, None),
|
NodeValue::Emph(_) => (MdKind::Emph, None),
|
||||||
NodeValue::Strikethrough(_) => (MdKind::Strikethrough, None),
|
NodeValue::Strikethrough(_) => (MdKind::Strikethrough, None),
|
||||||
NodeValue::Code(code) => (MdKind::Code, Some(code.literal.clone())),
|
NodeValue::Code(code) => (
|
||||||
|
MdKind::Code {
|
||||||
|
ticks: code.num_backticks,
|
||||||
|
},
|
||||||
|
Some(code.literal.clone()),
|
||||||
|
),
|
||||||
NodeValue::CodeBlock(block) => (
|
NodeValue::CodeBlock(block) => (
|
||||||
MdKind::CodeBlock {
|
MdKind::CodeBlock {
|
||||||
fenced: block.fenced,
|
fenced: block.fenced,
|
||||||
@@ -209,7 +214,6 @@ fn map_value(value: &NodeValue) -> (MdKind, Option<String>) {
|
|||||||
TableAlignment::Center => "center",
|
TableAlignment::Center => "center",
|
||||||
TableAlignment::Right => "right",
|
TableAlignment::Right => "right",
|
||||||
TableAlignment::None => "none",
|
TableAlignment::None => "none",
|
||||||
_ => "none",
|
|
||||||
}
|
}
|
||||||
.to_string()
|
.to_string()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ pub fn executable_payload(node: &MdNode) -> Result<String, PayloadError> {
|
|||||||
for child in &node.children {
|
for child in &node.children {
|
||||||
match &child.kind {
|
match &child.kind {
|
||||||
MdKind::Text => payload.push_str(child.literal.as_deref().unwrap_or_default()),
|
MdKind::Text => payload.push_str(child.literal.as_deref().unwrap_or_default()),
|
||||||
MdKind::Code => payload.push_str(child.literal.as_deref().unwrap_or_default()),
|
MdKind::Code { .. } => payload.push_str(child.literal.as_deref().unwrap_or_default()),
|
||||||
other => {
|
other => {
|
||||||
return Err(PayloadError::new(
|
return Err(PayloadError::new(
|
||||||
child.span,
|
child.span,
|
||||||
@@ -72,7 +72,7 @@ pub fn plain_text(node: &MdNode) -> String {
|
|||||||
|
|
||||||
fn collect_plain_text(node: &MdNode, out: &mut String) {
|
fn collect_plain_text(node: &MdNode, out: &mut String) {
|
||||||
match &node.kind {
|
match &node.kind {
|
||||||
MdKind::Text | MdKind::Code | MdKind::Math { .. } | MdKind::MathBlock => {
|
MdKind::Text | MdKind::Code { .. } | MdKind::Math { .. } | MdKind::MathBlock => {
|
||||||
out.push_str(node.literal.as_deref().unwrap_or_default());
|
out.push_str(node.literal.as_deref().unwrap_or_default());
|
||||||
}
|
}
|
||||||
MdKind::SoftBreak | MdKind::LineBreak => out.push(' '),
|
MdKind::SoftBreak | MdKind::LineBreak => out.push(' '),
|
||||||
@@ -131,7 +131,7 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
vec![
|
vec![
|
||||||
node(MdKind::Text, Some("面积 = "), vec![]),
|
node(MdKind::Text, Some("面积 = "), vec![]),
|
||||||
node(MdKind::Code, Some("计算(r=1)"), vec![]),
|
node(MdKind::Code { ticks: 1 }, Some("计算(r=1)"), vec![]),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
assert_eq!(executable_payload(&strong).unwrap(), "面积 = 计算(r=1)");
|
assert_eq!(executable_payload(&strong).unwrap(), "面积 = 计算(r=1)");
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ use serde::{Deserialize, Serialize};
|
|||||||
pub mod codes {
|
pub mod codes {
|
||||||
/// A Markdown AST node occupies an executable position but has an invalid shape.
|
/// A Markdown AST node occupies an executable position but has an invalid shape.
|
||||||
pub const MARKDOWN_INVALID_CONSTRUCT: &str = "markdown.invalid_construct";
|
pub const MARKDOWN_INVALID_CONSTRUCT: &str = "markdown.invalid_construct";
|
||||||
|
/// A node that would be executable appears outside any function body and is
|
||||||
|
/// therefore inert document content.
|
||||||
|
pub const MARKDOWN_INERT_EXECUTABLE: &str = "markdown.inert_executable";
|
||||||
/// Front matter is malformed or appears somewhere other than the document start.
|
/// Front matter is malformed or appears somewhere other than the document start.
|
||||||
pub const FRONTMATTER_INVALID: &str = "frontmatter.invalid";
|
pub const FRONTMATTER_INVALID: &str = "frontmatter.invalid";
|
||||||
/// An executable payload failed to parse as an expression or statement.
|
/// An executable payload failed to parse as an expression or statement.
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ fn decode(json: &Json, depth: usize, limits: &WireLimits) -> Result<Value, WireE
|
|||||||
let type_tag = obj
|
let type_tag = obj
|
||||||
.get("type")
|
.get("type")
|
||||||
.and_then(Json::as_str)
|
.and_then(Json::as_str)
|
||||||
.ok_or_else(|| WireError::MissingField("type"))?;
|
.ok_or(WireError::MissingField("type"))?;
|
||||||
let require = |field: &'static str| obj.get(field).ok_or(WireError::MissingField(field));
|
let require = |field: &'static str| obj.get(field).ok_or(WireError::MissingField(field));
|
||||||
match type_tag {
|
match type_tag {
|
||||||
"unit" => Ok(Value::Unit),
|
"unit" => Ok(Value::Unit),
|
||||||
|
|||||||
+8
-1
@@ -50,6 +50,8 @@ content is never executed:
|
|||||||
* heading text (headings scope, they do not run)
|
* heading text (headings scope, they do not run)
|
||||||
* `link` labels and `image` alt text
|
* `link` labels and `image` alt text
|
||||||
* `table` cells (tables are document values)
|
* `table` cells (tables are document values)
|
||||||
|
* `strikethrough` wrappers: their content is inert prose and is not traversed
|
||||||
|
for execution; do not rely on formatting to hide executable nodes
|
||||||
* `code_block` and inline `code` outside designated payload positions
|
* `code_block` and inline `code` outside designated payload positions
|
||||||
* `math` / `math_block`
|
* `math` / `math_block`
|
||||||
* `html_block` / `html_inline`
|
* `html_block` / `html_inline`
|
||||||
@@ -78,7 +80,12 @@ including inside branch and loop bodies:
|
|||||||
Outside functions (module top-level prose) the same executable nodes are inert
|
Outside functions (module top-level prose) the same executable nodes are inert
|
||||||
document content (S-03 in the blueprint: executable lists/strong/emph only run
|
document content (S-03 in the blueprint: executable lists/strong/emph only run
|
||||||
inside a function body). The single exception is `main` itself, which is a
|
inside a function body). The single exception is `main` itself, which is a
|
||||||
function.
|
function. To make this explicit rather than silent, the frontend emits a
|
||||||
|
`markdown.inert_executable` **warning** for every would-be execution node found
|
||||||
|
outside a function body; the document still compiles and the node does nothing.
|
||||||
|
|
||||||
|
Headings inside container blocks (block quotes, list items) or fenced code never
|
||||||
|
create functions and never execute inline markup.
|
||||||
|
|
||||||
### 4.1 Strict payload extraction
|
### 4.1 Strict payload extraction
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,9 @@ Rules:
|
|||||||
`raw` payload of unmodelled nodes.
|
`raw` payload of unmodelled nodes.
|
||||||
* `link`/`image` embed `url` and `title`; `heading` embeds `level` and
|
* `link`/`image` embed `url` and `title`; `heading` embeds `level` and
|
||||||
`setext`; `list` embeds `ordered`, optional `start` and `tight`; `table`
|
`setext`; `list` embeds `ordered`, optional `start` and `tight`; `table`
|
||||||
embeds column `alignments`; `table_row` embeds `header`.
|
embeds column `alignments`; `table_row` embeds `header`; inline `code`
|
||||||
|
embeds `ticks` (delimiter length) so payload offsets can be mapped back to
|
||||||
|
exact source bytes (a code span's source span includes its backticks).
|
||||||
* Unmodelled parser nodes are preserved as `{"kind":"other","tag":"..."}`
|
* Unmodelled parser nodes are preserved as `{"kind":"other","tag":"..."}`
|
||||||
with their children and raw literal. They are inert for the language.
|
with their children and raw literal. They are inert for the language.
|
||||||
* Attribute order in JSON is fixed by the serializer and goldens are
|
* Attribute order in JSON is fixed by the serializer and goldens are
|
||||||
|
|||||||
Reference in new issue
Block a user