feat: add narrative metrics and documentation rules

This commit is contained in:
cflmy committed 2026-11-23 17:22:14 +08:00
1 parent 0717216c9d
commit f26f6099f2
7 files changed
+615 -1

No files matched your search

+20
View File
@@ -334,6 +334,7 @@ impl MarkdownTree {
&& self.mode_of(node) == HeadingMode::Exec
&& !self.has_carrier_ancestor(node)
&& !self.has_inert_ancestor(node)
&& !self.has_heading_ancestor(node)
{
if let Some(text) = self.nodes[node].literal.clone() {
fragments.push(ProseFragment {
@@ -363,6 +364,12 @@ impl MarkdownTree {
)
})
}
fn has_heading_ancestor(&self, node: NodeId) -> bool {
self.ancestors(node)
.into_iter()
.any(|ancestor| self.nodes[ancestor].kind == "heading")
}
}
fn flatten(raw: RawNode, parent: Option<NodeId>, nodes: &mut Vec<MarkdownNode>) -> NodeId {
@@ -453,4 +460,17 @@ mod tests {
assert!(tree.carriers.is_empty());
assert!(tree.prose_fragments(0).is_empty());
}
#[test]
fn exec_emphasis_is_a_carrier_not_prose_and_headings_are_excluded() {
let tree = tree("## @exec 标题不计量\n\n普通说明 **重要** 继续说明。\n\n### 小节也不计量\n\n*return 0*\n");
let function = tree.headings[0].node;
let prose: Vec<_> = tree
.prose_fragments(function)
.into_iter()
.map(|fragment| fragment.text)
.collect();
assert_eq!(prose, vec!["普通说明 ", " 继续说明。"]);
assert!(tree.carriers.iter().any(|carrier| carrier.payload == "重要"));
}
}
+4 -1
View File
@@ -4,6 +4,9 @@ mod source;
mod span;
pub use analysis::{semantic_nodes, AnalysisFunction, AnalysisModule, CoreDiagnostic, ExecutionProjection};
pub use markdown::{Carrier, CarrierKind, HeadingMode, HeadingSegment, MarkdownNode, MarkdownTree, NodeId};
pub use markdown::{
Carrier, CarrierKind, HeadingMode, HeadingSegment, MarkdownNode, MarkdownTree, NodeId,
ProseFragment,
};
pub use source::SourceSnapshot;
pub use span::{LineColumn, Span};