Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/temple/html/pretty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class Pretty < Fast
header hgroup hr html li link meta nav ol option p
rp rt ruby section script style table tbody td tfoot
th thead tr ul video doctype).freeze,
pre_tags: %w(code pre textarea).freeze
pre_tags: %w(code pre textarea).freeze,
compact: false

def initialize(opts = {})
super
Expand Down Expand Up @@ -62,6 +63,18 @@ def on_html_tag(name, attrs, content = nil)
result = [:multi, [:static, "#{tag_indent(name)}<#{name}"], compile(attrs)]
result << [:static, (closed && @format != :html ? ' /' : '') + '>']

# strip newlines around terminal nodes
@pretty = true
case content
in [:multi, [:newline]]
return (result << [:static, "</#{name}>"])
in [:multi, [:multi, [:static, str]]]
return (result << [:static, "#{str}</#{name}>"])
in [:multi, [:escape, true, [:dynamic, code]], [:multi, [:newline]]]
return (result << [:multi, [:escape, true, [:dynamic, code]], [:static, "</#{name}>"]])
else nil
end if options[:compact]

@pretty = !@pre_tags || !options[:pre_tags].include?(name)
if content
@indent += 1
Expand Down