Commit 95fade3e authored by NuriYuri's avatar NuriYuri
Browse files

Fix json renderer so invalid HTML cannot be produced

parent 0a2c9152
......@@ -62,6 +62,24 @@ module JsonElementDef
def paragraph(text)
children = children_from(text)
return children[0].to_json << ',' if children.size == 1 && NO_PARAGRAPH_TYPES.include?(children[0]['type'])
if children.any? { |child| NO_PARAGRAPH_TYPES.include?(child['type']) }
accu = []
result = ''
children.each do |child|
if NO_PARAGRAPH_TYPES.include?(child['type'])
if accu.any?
result << { type: :p, children: accu }.to_json << ','
accu.clear
end
result << child.to_json << ','
else
accu << child
end
end
result << { type: :p, children: accu }.to_json << ',' if accu.any?
return result
end
{ type: :p, children: children }.to_json << ','
end
......@@ -157,6 +175,7 @@ module JsonElementDef
type: :figure,
src: link,
alt: alt_text,
align: align,
children: [{ text: title }],
}.to_json << ','
elsif link.include?('https://www.youtube.com/watch?v=')
......@@ -189,6 +208,10 @@ class JsonRenderer < Redcarpet::Render::HTML
class SubRenderer < Redcarpet::Render::HTML
include JsonElementDef
def paragraph(text)
children = children_from(text)
{ type: :subP, children: children }.to_json << ','
end
end
# Constant containing the Summary title in various langs
SUMMARY_TITLES = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment