mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 03:23:05 +00:00
Merge pull request #807 from vashirov/i806
Handle multiline snippets better
This commit is contained in:
commit
ecaeacf1d8
2 changed files with 10 additions and 2 deletions
|
@ -18,7 +18,7 @@ pub fn all_cheat_files(path: &Path) -> Vec<String> {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|e| e.ok())
|
.filter_map(|e| e.ok())
|
||||||
.map(|e| e.path().to_str().unwrap_or("").to_string())
|
.map(|e| e.path().to_str().unwrap_or("").to_string())
|
||||||
.filter(|e| e.ends_with(".cheat"))
|
.filter(|e| e.ends_with(".cheat") || e.ends_with(".cheat.md"))
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -243,6 +243,8 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
let mut variable_cmd = String::from("");
|
let mut variable_cmd = String::from("");
|
||||||
|
|
||||||
|
let mut inside_snippet: bool = false;
|
||||||
|
|
||||||
for (line_nr, line_result) in lines.enumerate() {
|
for (line_nr, line_result) in lines.enumerate() {
|
||||||
let line = line_result
|
let line = line_result
|
||||||
.with_context(|| format!("Failed to read line number {} in cheatsheet `{}`", line_nr, id))?;
|
.with_context(|| format!("Failed to read line number {} in cheatsheet `{}`", line_nr, id))?;
|
||||||
|
@ -284,7 +286,9 @@ impl<'a> Parser<'a> {
|
||||||
item.comment = without_prefix(&line);
|
item.comment = without_prefix(&line);
|
||||||
}
|
}
|
||||||
// variable
|
// variable
|
||||||
else if !variable_cmd.is_empty() || (line.starts_with('$') && line.contains(':')) {
|
else if !variable_cmd.is_empty()
|
||||||
|
|| (line.starts_with('$') && line.contains(':')) && !inside_snippet
|
||||||
|
{
|
||||||
should_break = self.write_cmd(&item).is_err();
|
should_break = self.write_cmd(&item).is_err();
|
||||||
|
|
||||||
item.snippet = String::from("");
|
item.snippet = String::from("");
|
||||||
|
@ -306,6 +310,10 @@ impl<'a> Parser<'a> {
|
||||||
.insert_suggestion(&item.tags, variable, (String::from(command), opts));
|
.insert_suggestion(&item.tags, variable, (String::from(command), opts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// markdown snippet
|
||||||
|
else if line.starts_with("```") {
|
||||||
|
inside_snippet = !inside_snippet;
|
||||||
|
}
|
||||||
// snippet
|
// snippet
|
||||||
else {
|
else {
|
||||||
if !(&item.snippet).is_empty() {
|
if !(&item.snippet).is_empty() {
|
||||||
|
|
Loading…
Reference in a new issue