MCPcopy Create free account
hub / github.com/bevyengine/bevy-website / new

Method new

write-rustdoc-hide-lines/src/code_block_definition.rs:80–114  ·  view source on GitHub ↗
(line: &str)

Source from the content-addressed store, hash-verified

78
79impl CodeBlockDefinition {
80 pub fn new(line: &str) -> Option<CodeBlockDefinition> {
81 let lang_re = Regex::new(r"(\s*)```(.+)").ok()?;
82 let captures = lang_re.captures(line)?;
83
84 let whitespace = captures.get(1).map(|mat| mat.as_str())?;
85 let lang = captures.get(2).map(|mat| mat.as_str())?;
86
87 let mut hide_lines_idx = None;
88
89 let mut parts = lang.split(',');
90 let tag = parts.next()?;
91
92 if tag != "rs" && tag != "rust" {
93 return None;
94 }
95
96 let annotations = parts
97 .enumerate()
98 .map(|(idx, a)| {
99 let annotation = Annotation::from(a);
100
101 if let Annotation::HideLines(_) = annotation {
102 hide_lines_idx = Some(idx);
103 }
104
105 annotation
106 })
107 .collect();
108
109 Some(CodeBlockDefinition {
110 tag: format!("{whitespace}```{tag}"),
111 annotations,
112 hide_lines_idx,
113 })
114 }
115
116 pub fn get_hidden_ranges(&self) -> Option<&HiddenRanges> {
117 self.hide_lines_idx.map(|idx| match &self.annotations[idx] {

Callers

nothing calls this directly

Calls 3

getMethod · 0.80
as_strMethod · 0.80
nextMethod · 0.80

Tested by

no test coverage detected