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:
cflmy committed 2026-11-20 10:36:07 +08:00
1 parent 4db6e6afd6
commit 62a9af05fd
9 files changed
+34 -15

No files matched your search

+8 -4
View File
@@ -74,8 +74,12 @@ pub enum MdKind {
Emph,
/// GFM strikethrough.
Strikethrough,
/// Inline code span.
Code,
/// Inline code span. `ticks` records the delimiter length so the literal
/// payload can be mapped back to exact source offsets.
Code {
/// Number of backtick delimiters.
ticks: usize,
},
/// Fenced or indented code block.
CodeBlock {
/// Whether the block was fenced.
@@ -176,7 +180,7 @@ impl MdNode {
| MdKind::Strong
| MdKind::Emph
| MdKind::Strikethrough
| MdKind::Code
| MdKind::Code { .. }
| MdKind::Math { .. }
| MdKind::Link { .. }
| MdKind::Image { .. }
@@ -208,7 +212,7 @@ impl MdKind {
MdKind::Strong => "strong",
MdKind::Emph => "emph",
MdKind::Strikethrough => "strikethrough",
MdKind::Code => "code",
MdKind::Code { .. } => "code",
MdKind::CodeBlock { .. } => "code_block",
MdKind::Math { .. } => "math",
MdKind::MathBlock => "math_block",
+6 -2
View File
@@ -169,7 +169,12 @@ fn map_value(value: &NodeValue) -> (MdKind, Option<String>) {
NodeValue::Strong(_) => (MdKind::Strong, None),
NodeValue::Emph(_) => (MdKind::Emph, 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) => (
MdKind::CodeBlock {
fenced: block.fenced,
@@ -209,7 +214,6 @@ fn map_value(value: &NodeValue) -> (MdKind, Option<String>) {
TableAlignment::Center => "center",
TableAlignment::Right => "right",
TableAlignment::None => "none",
_ => "none",
}
.to_string()
})
+3 -3
View File
@@ -44,7 +44,7 @@ pub fn executable_payload(node: &MdNode) -> Result<String, PayloadError> {
for child in &node.children {
match &child.kind {
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 => {
return Err(PayloadError::new(
child.span,
@@ -72,7 +72,7 @@ pub fn plain_text(node: &MdNode) -> String {
fn collect_plain_text(node: &MdNode, out: &mut String) {
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());
}
MdKind::SoftBreak | MdKind::LineBreak => out.push(' '),
@@ -131,7 +131,7 @@ mod tests {
None,
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)");