summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--riki.md19
-rw-r--r--src/html.rs23
-rw-r--r--src/parse.rs14
-rw-r--r--subplot/riki.rs2
4 files changed, 48 insertions, 10 deletions
diff --git a/riki.md b/riki.md
index ed5c2c2..baee12d 100644
--- a/riki.md
+++ b/riki.md
@@ -173,21 +173,28 @@ then AST of site/page.mdwn matches that of output/page.html
There is ~~struck through~~.
~~~
-### Top level heading
+### Headings
-_Requirement: Given a Markdown file with top level heading, the output must
-be an HTML file with one h1 element, without extra elements._
+_Requirement: Given a Markdown file with headings of various levels,
+the output must be an HTML file with corresponding `h1`, `h2`, etc,
+elements, without extra elements. Up to six levels of headings must be
+supported._
~~~scenario
given an installed riki
-given file site/page.mdwn from h1
+given file site/page.mdwn from headings
when I run riki site output
then AST of site/page.mdwn matches that of output/page.html
~~~
-~~~{#h1 .file}
-# Heading
+~~~{#headings .file}
+# Heading one
+## Heading two
+### Heading three
+#### Heading four
+##### Heading five
+###### Heading six
~~~
### Inline code
diff --git a/src/html.rs b/src/html.rs
index 8bb7d58..faadce7 100644
--- a/src/html.rs
+++ b/src/html.rs
@@ -61,8 +61,17 @@ impl From<Block> for Content {
fn from(block: Block) -> Self {
trace!("Content from Block: {:?}", block);
let e = match block {
- Block::Header(1, _, inlines) => {
- let mut e = Element::new(Tag::H1);
+ Block::Header(level, _, inlines) => {
+ let tag = match level {
+ 1 => Tag::H1,
+ 2 => Tag::H2,
+ 3 => Tag::H3,
+ 4 => Tag::H4,
+ 5 => Tag::H5,
+ 6 => Tag::H6,
+ _ => panic!("heading level {} is not allowed", level),
+ };
+ let mut e = Element::new(tag);
for inline in inlines {
e.push(Content::from(inline));
}
@@ -251,6 +260,11 @@ pub enum Tag {
Body,
Title,
H1,
+ H2,
+ H3,
+ H4,
+ H5,
+ H6,
P,
Code,
Em,
@@ -269,6 +283,11 @@ impl Tag {
Self::Title => "title",
Self::P => "p",
Self::H1 => "h1",
+ Self::H2 => "h2",
+ Self::H3 => "h3",
+ Self::H4 => "h4",
+ Self::H5 => "h5",
+ Self::H6 => "h6",
Self::Code => "code",
Self::Em => "em",
Self::Strong => "strong",
diff --git a/src/parse.rs b/src/parse.rs
index 50db281..16fd890 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -1,7 +1,7 @@
use super::error::SiteError;
use log::trace;
use pandoc_ast::{Attr, Block, Inline};
-use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag};
+use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag, HeadingLevel};
pub fn parse(markdown: &str) -> Result<Vec<Block>, SiteError> {
// Define the Markdown parser.
@@ -45,7 +45,17 @@ pub fn parse(markdown: &str) -> Result<Vec<Block>, SiteError> {
// End of a block or inline.
Event::End(tag) => match &tag {
Tag::Paragraph => blocks.push(paragraph(stack.pop())),
- Tag::Heading(level, _, _) => blocks.push(heading(*level as i64, stack.pop())),
+ Tag::Heading(level, _, _) => {
+ let level = match level {
+ HeadingLevel::H1 => 1,
+ HeadingLevel::H2 => 2,
+ HeadingLevel::H3 => 3,
+ HeadingLevel::H4 => 4,
+ HeadingLevel::H5 => 5,
+ HeadingLevel::H6 => 6,
+ };
+ blocks.push(heading(level, stack.pop()));
+ },
Tag::BlockQuote => (),
Tag::CodeBlock(kind) => blocks.push(code_block(kind, stack.pop())),
Tag::List(_no) => (),
diff --git a/subplot/riki.rs b/subplot/riki.rs
index 2b9cb7e..f00c0ac 100644
--- a/subplot/riki.rs
+++ b/subplot/riki.rs
@@ -42,6 +42,8 @@ fn asts_match(context: &Datadir, first: &str, second: &str) {
println!();
println!("first: {:#?}", first);
println!("second: {:#?}", second);
+ println!("first: {:?}", first);
+ println!("second: {:?}", second);
assert!(first == second);
}