Skip to content

Commit

Permalink
Fix disambiguations not shown (#160)
Browse files Browse the repository at this point in the history
Changes made:
* fix: fix disambiguations not shown
  • Loading branch information
Builditluc authored Feb 17, 2023
2 parents 16028a7 + e379b1b commit 56acbae
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/wiki/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use super::article::{Element, ElementType};

const SHOW_UNSUPPORTED: bool = false;
const LIST_MARKER: char = '-';
const DISAMBIGUATION_MARKER: char = '|';

pub struct Parser {
elements: Vec<Element>,
Expand Down Expand Up @@ -55,7 +56,22 @@ impl Parser {
"b" => self.parse_effect(node, Effect::Bold),
"i" => self.parse_effect(node, Effect::Italic),
"ul" => self.parse_list(node),
"div" if node.attr("class") == Some("redirectMsg") => self.parse_redirect_msg(node),
"div"
if node
.attr("class")
.map(|x| x.contains("hatnote"))
.unwrap_or(false) =>
{
self.parse_disambiguation(node)
}
"div"
if node
.attr("class")
.map(|x| x.contains("redirectMsg"))
.unwrap_or(false) =>
{
self.parse_redirect_msg(node)
}
"" => (),
_ if SHOW_UNSUPPORTED => {
self.elements.push(Element::new(
Expand Down Expand Up @@ -203,4 +219,17 @@ impl Parser {
self.parse_node(child)
}
}

fn parse_disambiguation(&mut self, node: Node) {
self.elements.push(Element::new(
self.next_id(),
ElementType::Text,
DISAMBIGUATION_MARKER.to_string(),
self.combine_effects(Style::from(config::CONFIG.theme.text)),
HashMap::new(),
));
self.parse_effect(node, Effect::Italic);
self.push_newline();
self.push_newline();
}
}

0 comments on commit 56acbae

Please sign in to comment.