Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing whitespace on list items starting with a special character #153

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/ui/article/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ impl LinesWrapper {
pub fn wrap_lines(mut self) -> Self {
debug!("wrapping the lines");

let mut last_type: ElementType = ElementType::Text;

// go through every element
for element in self.elements.clone().iter() {
// is this a link?
Expand All @@ -156,6 +158,8 @@ impl LinesWrapper {
// fill the current line and make the next one blank
self.fill_line();
self.newline();

last_type = element.kind();
continue;
}

Expand All @@ -176,7 +180,9 @@ impl LinesWrapper {

// if the element does not have a leading special character and we are not at the beginning
// of a line, add a leading whitespace
if !element.content().starts_with([',', '.', ';', ':']) && !self.current_line.is_empty()
if (!element.content().starts_with([',', '.', ';', ':'])
&& !self.current_line.is_empty())
|| last_type == ElementType::ListMarker
{
self.push_whitespace();
}
Expand All @@ -190,6 +196,7 @@ impl LinesWrapper {
}
// then add it to the merged element
merged_element.push_str(span);
last_type = element.kind();
continue;
}

Expand Down Expand Up @@ -228,6 +235,7 @@ impl LinesWrapper {
}
// then add it to the merged element
merged_element.push_str(span);
last_type = element.kind();
continue;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/wiki/article.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum ElementType {
Link,
Header,
Unsupported,
ListMarker,
}

#[derive(Debug, Clone)]
Expand Down
4 changes: 2 additions & 2 deletions src/wiki/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ impl Parser {

self.elements.push(Element::new(
self.next_id(),
ElementType::Text,
format!("\t{}", LIST_MARKER),
ElementType::ListMarker,
format!("\t{} ", LIST_MARKER),
self.combine_effects(Style::from(config::CONFIG.theme.text)),
HashMap::new(),
));
Expand Down