| @@ -83,12 +83,6 @@ const KNOWN_KEYWORDS: &[&str] = &[ |
| 83 | // Leaving them out reported the corpus's most-used keyword as unrecognized. |
83 | // Leaving them out reported the corpus's most-used keyword as unrecognized. |
| 84 | "SLUG", "DRAFT", "TEMPLATE", |
84 | "SLUG", "DRAFT", "TEMPLATE", |
| 85 | ]; |
85 | ]; |
| 86 | /// Blocks with dedicated handling. Any *other* name renders as a special block — a div |
| |
| 87 | /// with that name holding parsed org — so an unlisted block is a note about what a corpus |
| |
| 88 | /// contains rather than a construct that will be lost. |
| |
| 89 | const KNOWN_BLOCKS: &[&str] = &[ |
| |
| 90 | "SRC", "QUOTE", "EXAMPLE", "CENTER", "EXPORT", "VERSE", "COMMENT", |
| |
| 91 | ]; |
| |
| 92 | const KNOWN_DRAWERS: &[&str] = &["PROPERTIES", "LOGBOOK", "END"]; |
86 | const KNOWN_DRAWERS: &[&str] = &["PROPERTIES", "LOGBOOK", "END"]; |
| 93 | /// Keyword names conventional enough to be worth flagging when they lead a heading. |
87 | /// Keyword names conventional enough to be worth flagging when they lead a heading. |
| 94 | /// A custom sequence is only *real* if some `#+TODO:` declares it, which the census |
88 | /// A custom sequence is only *real* if some `#+TODO:` declares it, which the census |
| @@ -107,7 +101,11 @@ impl Audit { |
| 107 | pub fn is_known(kind: Census, name: &str) -> bool { |
101 | pub fn is_known(kind: Census, name: &str) -> bool { |
| 108 | let known = match kind { |
102 | let known = match kind { |
| 109 | Census::Keyword => KNOWN_KEYWORDS, |
103 | Census::Keyword => KNOWN_KEYWORDS, |
| 110 | Census::Block => KNOWN_BLOCKS, |
104 | // Every block name renders, and renders as org renders it: the names in |
| |
105 | // `block_construct` through dedicated handling, every other name as a special |
| |
106 | // block — a div carrying the name, holding parsed org, which is exactly what |
| |
107 | // org's exporter emits. No block name is a blind spot. |
| |
108 | Census::Block => return true, |
| 111 | Census::Drawer => KNOWN_DRAWERS, |
109 | Census::Drawer => KNOWN_DRAWERS, |
| 112 | Census::Scheme => KNOWN_SCHEMES, |
110 | Census::Scheme => KNOWN_SCHEMES, |
| 113 | }; |
111 | }; |
| @@ -198,7 +196,7 @@ impl Audit { |
| 198 | if let Some(rest) = trimmed.to_ascii_uppercase().strip_prefix("#+BEGIN_") { |
196 | if let Some(rest) = trimmed.to_ascii_uppercase().strip_prefix("#+BEGIN_") { |
| 199 | let kind = rest.split_whitespace().next().unwrap_or("").to_string(); |
197 | let kind = rest.split_whitespace().next().unwrap_or("").to_string(); |
| 200 | self.count_census(Census::Block, &kind, &at); |
198 | self.count_census(Census::Block, &kind, &at); |
| 201 | self.count(scope_of_block(&kind), block_construct(&kind), &at); |
199 | self.count(Scope::In, block_construct(&kind), &at); |
| 202 | if trimmed.to_ascii_uppercase().contains(":RESULTS") { |
200 | if trimmed.to_ascii_uppercase().contains(":RESULTS") { |
| 203 | self.count(Scope::Out, "babel header args (:results)", &at); |
201 | self.count(Scope::Out, "babel header args (:results)", &at); |
| 204 | } |
202 | } |
| @@ -440,14 +438,6 @@ fn is_drawer(trimmed: &str) -> bool { |
| 440 | && t.len() > 2 |
438 | && t.len() > 2 |
| 441 | } |
439 | } |
| 442 | |
440 | |
| 443 | fn scope_of_block(kind: &str) -> Scope { |
| |
| 444 | if KNOWN_BLOCKS.iter().any(|k| k.eq_ignore_ascii_case(kind)) { |
| |
| 445 | Scope::In |
| |
| 446 | } else { |
| |
| 447 | Scope::Out |
| |
| 448 | } |
| |
| 449 | } |
| |
| 450 | |
| |
| 451 | fn block_construct(kind: &str) -> &'static str { |
441 | fn block_construct(kind: &str) -> &'static str { |
| 452 | match kind.to_ascii_uppercase().as_str() { |
442 | match kind.to_ascii_uppercase().as_str() { |
| 453 | "SRC" => "source block", |
443 | "SRC" => "source block", |
| @@ -455,7 +445,9 @@ fn block_construct(kind: &str) -> &'static str { |
| 455 | "EXAMPLE" => "example block", |
445 | "EXAMPLE" => "example block", |
| 456 | "CENTER" => "center block", |
446 | "CENTER" => "center block", |
| 457 | "EXPORT" => "export block", |
447 | "EXPORT" => "export block", |
| 458 | _ => "unmodelled block type", |
448 | "VERSE" => "verse block", |
| |
449 | "COMMENT" => "comment block", |
| |
450 | _ => "special block", |
| 459 | } |
451 | } |
| 460 | } |
452 | } |
| 461 | |
453 | |