diff --git a/spec/classes/paragraph_converter_spec.cr b/spec/classes/paragraph_converter_spec.cr
index bac37f5..c3e30cb 100644
--- a/spec/classes/paragraph_converter_spec.cr
+++ b/spec/classes/paragraph_converter_spec.cr
@@ -190,6 +190,14 @@ describe ParagraphConverter do
it "converts all the tags" do
paragraphs = Array(PostResponse::Paragraph).from_json <<-JSON
[
+ {
+ "text": "text",
+ "type": "H2",
+ "markups": [],
+ "iframe": null,
+ "layout": null,
+ "metadata": null
+ },
{
"text": "text",
"type": "H3",
@@ -303,6 +311,7 @@ describe ParagraphConverter do
]
JSON
expected = [
+ Heading1.new([Text.new("text")] of Child),
Heading2.new([Text.new("text")] of Child),
Heading3.new([Text.new("text")] of Child),
Paragraph.new([Text.new("text")] of Child),
diff --git a/spec/components/page_content_spec.cr b/spec/components/page_content_spec.cr
index 50520a6..7b40351 100644
--- a/spec/components/page_content_spec.cr
+++ b/spec/components/page_content_spec.cr
@@ -162,6 +162,23 @@ describe PageContent do
HTML
end
+ it "renders an H2" do
+ page = Page.new(
+ title: "Title",
+ author: user_anchor_factory,
+ created_at: Time.local,
+ nodes: [
+ Heading1.new(children: [
+ Text.new(content: "Title!"),
+ ] of Child),
+ ] of Child
+ )
+
+ html = PageContent.new(page: page).render_to_string
+
+ html.should eq %(
Title!
)
+ end
+
it "renders an H3" do
page = Page.new(
title: "Title",
diff --git a/src/classes/paragraph_converter.cr b/src/classes/paragraph_converter.cr
index 6070cf6..77ab31c 100644
--- a/src/classes/paragraph_converter.cr
+++ b/src/classes/paragraph_converter.cr
@@ -10,6 +10,10 @@ class ParagraphConverter
paragraph = paragraphs.shift
children = MarkupConverter.convert(paragraph.text, paragraph.markups)
node = BlockQuote.new(children: children)
+ when PostResponse::ParagraphType::H2
+ paragraph = paragraphs.shift
+ children = MarkupConverter.convert(paragraph.text, paragraph.markups)
+ node = Heading1.new(children: children)
when PostResponse::ParagraphType::H3
paragraph = paragraphs.shift
children = MarkupConverter.convert(paragraph.text, paragraph.markups)
diff --git a/src/components/page_content.cr b/src/components/page_content.cr
index 90a5be8..7ffb41f 100644
--- a/src/components/page_content.cr
+++ b/src/components/page_content.cr
@@ -81,6 +81,10 @@ class PageContent < BaseComponent
script src: child.src
end
+ def render_child(node : Heading1)
+ h1 { render_children(node.children) }
+ end
+
def render_child(node : Heading2)
h2 { render_children(node.children) }
end
diff --git a/src/models/nodes.cr b/src/models/nodes.cr
index 9518225..fec0a30 100644
--- a/src/models/nodes.cr
+++ b/src/models/nodes.cr
@@ -40,6 +40,9 @@ module Nodes
class FigureCaption < Container
end
+ class Heading1 < Container
+ end
+
class Heading2 < Container
end
diff --git a/src/models/post_response.cr b/src/models/post_response.cr
index 28c6768..99a0931 100644
--- a/src/models/post_response.cr
+++ b/src/models/post_response.cr
@@ -42,6 +42,7 @@ class PostResponse
enum ParagraphType
BQ
+ H2
H3
H4
IFRAME