summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/asciidoctor/document.rb2
-rw-r--r--lib/asciidoctor/render_templates.rb12
-rw-r--r--test/text_test.rb4
3 files changed, 16 insertions, 2 deletions
diff --git a/lib/asciidoctor/document.rb b/lib/asciidoctor/document.rb
index eabfd55a..50cf4730 100644
--- a/lib/asciidoctor/document.rb
+++ b/lib/asciidoctor/document.rb
@@ -192,7 +192,7 @@ class Asciidoctor::Document
# using the appropriate built-in template.
def render(options = {})
r = renderer(options)
- @options.merge(options)[:header_footer] ? r.render('document', self) : content
+ @options.merge(options)[:header_footer] ? r.render('document', self) : r.render('embedded', self)
end
def content
diff --git a/lib/asciidoctor/render_templates.rb b/lib/asciidoctor/render_templates.rb
index 229a2417..42e86df7 100644
--- a/lib/asciidoctor/render_templates.rb
+++ b/lib/asciidoctor/render_templates.rb
@@ -14,7 +14,7 @@ class BaseTemplate
# We're ignoring locals for now. Shut up.
def render(obj = Object.new, locals = {})
output = template.result(obj.instance_eval {binding})
- self.is_a?(DocumentTemplate) ? output.gsub(/^\s*\n/, '') : output
+ (self.is_a?(DocumentTemplate) || self.is_a?(EmbeddedTemplate)) ? output.gsub(/^\s*\n/, '') : output
end
def template
@@ -92,6 +92,15 @@ class DocumentTemplate < BaseTemplate
end
end
+class EmbeddedTemplate < BaseTemplate
+ def template
+ @template ||= ::ERB.new <<-EOF
+<%#encoding:UTF-8%>
+<%= content %>
+ EOF
+ end
+end
+
class BlockPreambleTemplate < BaseTemplate
def template
@template ||= ::ERB.new <<-EOF
@@ -213,6 +222,7 @@ end
class BlockParagraphTemplate < BaseTemplate
def template
@template ||= ERB.new <<-EOF
+<%#encoding:UTF-8%>
<div#{id} class='paragraph#{role}'>
<% unless title.nil? %>
<div class='title'><%= title %></div>
diff --git a/test/text_test.rb b/test/text_test.rb
index bb7b4c69..721f10c5 100644
--- a/test/text_test.rb
+++ b/test/text_test.rb
@@ -5,6 +5,10 @@ context "Text" do
assert_xpath "//p", example_document(:encoding).render, 1
end
+ test "proper encoding to handle utf8 characters in embedded document" do
+ assert_xpath "//p", example_document(:encoding).render(:header_footer => false), 1
+ end
+
test 'escaped text markup' do
pending "Not done yet"
end