Remove broken footnote links from grammar summary
Our grammar syntax supports linking to footnotes which we render in
the Markdown version. This works when the rendering is done on the
same page that the footnote appears.
On the grammar summary page, however, where we also render the
grammar, these footnotes are not present, and so the links were all
broken.
Let's fix this for now by not rendering these footnote links on the
grammar summary page.
diff --git a/mdbook-spec/src/grammar/render_markdown.rs b/mdbook-spec/src/grammar/render_markdown.rs
index 36de0ce..1cf0cde 100644
--- a/mdbook-spec/src/grammar/render_markdown.rs
+++ b/mdbook-spec/src/grammar/render_markdown.rs
@@ -64,7 +64,8 @@
name = self.name,
)
.unwrap();
- self.expression.render_markdown(link_map, output);
+ self.expression
+ .render_markdown(link_map, output, for_summary);
output.push('\n');
}
}
@@ -91,11 +92,16 @@
}
}
- fn render_markdown(&self, link_map: &HashMap<String, String>, output: &mut String) {
+ fn render_markdown(
+ &self,
+ link_map: &HashMap<String, String>,
+ output: &mut String,
+ for_summary: bool,
+ ) {
match &self.kind {
ExpressionKind::Grouped(e) => {
output.push_str("( ");
- e.render_markdown(link_map, output);
+ e.render_markdown(link_map, output, for_summary);
if !matches!(e.last(), ExpressionKind::Break(_)) {
output.push(' ');
}
@@ -104,7 +110,7 @@
ExpressionKind::Alt(es) => {
let mut iter = es.iter().peekable();
while let Some(e) = iter.next() {
- e.render_markdown(link_map, output);
+ e.render_markdown(link_map, output, for_summary);
if iter.peek().is_some() {
if !matches!(e.last(), ExpressionKind::Break(_)) {
output.push(' ');
@@ -116,34 +122,34 @@
ExpressionKind::Sequence(es) => {
let mut iter = es.iter().peekable();
while let Some(e) = iter.next() {
- e.render_markdown(link_map, output);
+ e.render_markdown(link_map, output, for_summary);
if iter.peek().is_some() && !matches!(e.last(), ExpressionKind::Break(_)) {
output.push(' ');
}
}
}
ExpressionKind::Optional(e) => {
- e.render_markdown(link_map, output);
+ e.render_markdown(link_map, output, for_summary);
output.push_str("<sup>?</sup>");
}
ExpressionKind::Repeat(e) => {
- e.render_markdown(link_map, output);
+ e.render_markdown(link_map, output, for_summary);
output.push_str("<sup>\\*</sup>");
}
ExpressionKind::RepeatNonGreedy(e) => {
- e.render_markdown(link_map, output);
+ e.render_markdown(link_map, output, for_summary);
output.push_str("<sup>\\* (non-greedy)</sup>");
}
ExpressionKind::RepeatPlus(e) => {
- e.render_markdown(link_map, output);
+ e.render_markdown(link_map, output, for_summary);
output.push_str("<sup>+</sup>");
}
ExpressionKind::RepeatPlusNonGreedy(e) => {
- e.render_markdown(link_map, output);
+ e.render_markdown(link_map, output, for_summary);
output.push_str("<sup>+ (non-greedy)</sup>");
}
ExpressionKind::RepeatRange(e, a, b) => {
- e.render_markdown(link_map, output);
+ e.render_markdown(link_map, output, for_summary);
write!(
output,
"<sup>{}..{}</sup>",
@@ -174,7 +180,7 @@
ExpressionKind::Charset(set) => charset_render_markdown(set, link_map, output),
ExpressionKind::NegExpression(e) => {
output.push('~');
- e.render_markdown(link_map, output);
+ e.render_markdown(link_map, output, for_summary);
}
ExpressionKind::Unicode(s) => {
output.push_str("U+");
@@ -184,9 +190,12 @@
if let Some(suffix) = &self.suffix {
write!(output, "<sub class=\"grammar-text\">{suffix}</sub>").unwrap();
}
- if let Some(footnote) = &self.footnote {
- // The ZeroWidthSpace is to avoid conflicts with markdown link references.
- write!(output, "​[^{footnote}]").unwrap();
+ if !for_summary {
+ if let Some(footnote) = &self.footnote {
+ // The `ZeroWidthSpace` is to avoid conflicts with markdown link
+ // references.
+ write!(output, "​[^{footnote}]").unwrap();
+ }
}
}
}