Parsing Fix: Add H2 Paragraph type
The post id 34dead42a28 contained a new paragraph type: H2. Previously the only known header types were H3 and H4. In this case, the paragraph doesn't actually get rendered because it's the page title which is removed from the page nodes (see commits6baba803
and thenfba87c10
). However, it somehow an author is able to get an H2 paragraph into the page, it will display as an <h1> just as H3 displays as <h2> and H4 displays as <h3>.
This commit is contained in:
parent
eaf25ef23a
commit
f7ad92f4bf
6 changed files with 38 additions and 0 deletions
|
@ -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),
|
||||
|
|
|
@ -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 %(<h1>Title!</h1>)
|
||||
end
|
||||
|
||||
it "renders an H3" do
|
||||
page = Page.new(
|
||||
title: "Title",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -40,6 +40,9 @@ module Nodes
|
|||
class FigureCaption < Container
|
||||
end
|
||||
|
||||
class Heading1 < Container
|
||||
end
|
||||
|
||||
class Heading2 < Container
|
||||
end
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ class PostResponse
|
|||
|
||||
enum ParagraphType
|
||||
BQ
|
||||
H2
|
||||
H3
|
||||
H4
|
||||
IFRAME
|
||||
|
|
Loading…
Reference in a new issue