summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-07-31 11:14:16 +0300
committerLars Wirzenius <liw@liw.fi>2022-07-31 11:22:37 +0300
commit79e4b9f695d1a25c960eb2f6a86aabe169f78a8e (patch)
tree842ce47c7e3ca66a027c81f1b49477969b074b35
parentb51e5bf01794732b61b9402eceabce457f2120c9 (diff)
downloadriki-79e4b9f695d1a25c960eb2f6a86aabe169f78a8e.tar.gz
feat: check for definition lists, and fail if found
Sponsored-by: author
-rw-r--r--riki.md46
-rw-r--r--src/error.rs3
-rw-r--r--src/html.rs15
3 files changed, 61 insertions, 3 deletions
diff --git a/riki.md b/riki.md
index 6fc0d53..e208baa 100644
--- a/riki.md
+++ b/riki.md
@@ -334,6 +334,52 @@ then AST of site/page.mdwn matches that of output/page.html
* [x] done
~~~
+## Definition list
+
+_Requirement: Markup indicating use of a definition list should be
+flagged as an error._
+
+Justification: Neither the CommonMark specification, nor GitHub
+Flavored Markdown, supports definition lists, even though some
+Markdown variants do. The Markdown parser Riki uses doesn't support
+it.
+
+~~~scenario
+given an installed riki
+
+given file site/page.mdwn from dl-1
+when I try to run riki build --plain-body site output
+then command fails
+then stderr contains "definition list"
+
+given file site/page.mdwn from dl-2
+when I try to run riki build --plain-body site output
+then command fails
+then stderr contains "definition list"
+
+given file site/page.mdwn from dl-3
+when I run riki build --plain-body site output
+then file output/page.html contains ": bar"
+~~~
+
+~~~{#dl-1 .file}
+foo
+: bar
+~~~
+
+~~~{#dl-2 .file}
+foo
+
+: bar
+~~~
+
+~~~{#dl-3 .file}
+foo
+
+<!-- no colon at beginning of line here -->: bar
+~~~
+
+
## Input files other than Markdown
_Requirement: Input files that aren't Markdown files must be copied
diff --git a/src/error.rs b/src/error.rs
index a5e65e1..756d7f0 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -49,4 +49,7 @@ pub enum SiteError {
#[error("link to missing page {1} on {0}")]
PageMissing(PathBuf, PathBuf),
+
+ #[error("attempt to use definition lists in Markdown: {0:?}")]
+ DefinitionList(String),
}
diff --git a/src/html.rs b/src/html.rs
index 90bf9d5..9d048a5 100644
--- a/src/html.rs
+++ b/src/html.rs
@@ -134,8 +134,17 @@ pub fn parse(markdown: &str) -> Result<Element, SiteError> {
}
},
Event::End(tag) => match &tag {
- Tag::Paragraph
- | Tag::Heading(_, _, _)
+ Tag::Paragraph => {
+ trace!("at end of paragraph, looking for definition list use");
+ let e = stack.pop();
+ let s = as_plain_text(e.children());
+ trace!("paragraph text: {:?}", s);
+ if s.starts_with(": ") || s.contains("\n: ") {
+ return Err(SiteError::DefinitionList(s));
+ }
+ stack.append_child(Content::Elt(e));
+ }
+ Tag::Heading(_, _, _)
| Tag::List(_)
| Tag::Item
| Tag::Link(_, _, _)
@@ -162,7 +171,7 @@ pub fn parse(markdown: &str) -> Result<Element, SiteError> {
}
Event::Html(s) => stack.append_child(Content::Html(s.to_string())),
Event::FootnoteReference(s) => trace!("footnote ref {:?}", s),
- Event::SoftBreak => stack.append_str(" "),
+ Event::SoftBreak => stack.append_str("\n"),
Event::HardBreak => stack.append_element(Element::new(ElementTag::Br)),
Event::Rule => stack.append_element(Element::new(ElementTag::Hr)),
Event::TaskListMarker(done) => {