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 disambiguations not shown #160

Merged
merged 1 commit into from
Feb 17, 2023
Merged
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
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();
}
}