summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2013-01-30 12:11:13 -0700
committerDan Allen <dan.j.allen@gmail.com>2013-01-30 12:11:13 -0700
commita355a08ca9c3ac1e25e2262287b2de3c3b1f953b (patch)
tree467a646090b0fd065172160b75417695cb121f7a
parentb82ed8ea14a8e4b1b2e5a507dfe754c9dc422363 (diff)
resolves issue #144 - encoding issue w/ utf-8
- needed to add magic encoding line to all erb templates - add example from issue to encodings test case
-rw-r--r--lib/asciidoctor/backends/docbook45.rb81
-rw-r--r--lib/asciidoctor/backends/html5.rb86
-rw-r--r--test/fixtures/encoding.asciidoc4
-rw-r--r--test/test_helper.rb5
-rw-r--r--test/text_test.rb24
5 files changed, 90 insertions, 110 deletions
diff --git a/lib/asciidoctor/backends/docbook45.rb b/lib/asciidoctor/backends/docbook45.rb
index 55bce12f..4efef2e1 100644
--- a/lib/asciidoctor/backends/docbook45.rb
+++ b/lib/asciidoctor/backends/docbook45.rb
@@ -60,8 +60,7 @@ class DocumentTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<?xml version="1.0" encoding="UTF-8"?>
+<%#encoding:UTF-8%><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE <%= doctype %> PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<% if attr? :toc %><?asciidoc-toc?><% end %>
<% if attr? :numbered %><?asciidoc-numbered?><% end %>
@@ -87,8 +86,7 @@ end
class EmbeddedTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<%= content %>
+<%#encoding:UTF-8%><%= content %>
EOS
end
end
@@ -96,8 +94,7 @@ end
class BlockPreambleTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<% if document.doctype == 'book' %>
+<%#encoding:UTF-8%><% if document.doctype == 'book' %>
<preface#{id}#{role}#{xreflabel}>
<title><%= title %></title>
<%= content %>
@@ -112,8 +109,7 @@ end
class SectionTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<<%= @special ? @sectname : (document.doctype == 'book' && @level <= 1 ? 'chapter' : 'section') %>#{id}#{role}#{xreflabel}>
+<%#encoding:UTF-8%><<%= @special ? @sectname : (document.doctype == 'book' && @level <= 1 ? 'chapter' : 'section') %>#{id}#{role}#{xreflabel}>
#{title}
<%= content %>
</<%= @special ? @sectname : (document.doctype == 'book' && @level <= 1 ? 'chapter' : 'section') %>>
@@ -124,7 +120,7 @@ end
class BlockFloatingTitleTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<bridgehead#{id}#{role}#{xreflabel} renderas="sect<%= @level %>"><%= title %></bridgehead>
+<%#encoding:UTF-8%><bridgehead#{id}#{role}#{xreflabel} renderas="sect<%= @level %>"><%= title %></bridgehead>
EOS
end
end
@@ -133,8 +129,7 @@ end
class BlockParagraphTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<% if !title? %>
+<%#encoding:UTF-8%><% if !title? %>
<simpara#{id}#{role}#{xreflabel}><%= content %></simpara>
<% else %>
<formalpara#{id}#{role}#{xreflabel}>
@@ -149,8 +144,7 @@ end
class BlockAdmonitionTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<<%= attr :name %>#{id}#{role}#{xreflabel}>
+<%#encoding:UTF-8%><<%= attr :name %>#{id}#{role}#{xreflabel}>
#{title}
<% if blocks? %>
<%= content %>
@@ -165,8 +159,7 @@ end
class BlockUlistTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<% if (attr :style) == 'bibliography' %>
+<%#encoding:UTF-8%><% if (attr :style) == 'bibliography' %>
<bibliodiv#{id}#{role}#{xreflabel}>
#{title}
<% content.each do |li| %>
@@ -198,8 +191,7 @@ end
class BlockOlistTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<orderedlist#{id}#{role}#{xreflabel}#{attribute('numeration', :style)}>
+<%#encoding:UTF-8%><orderedlist#{id}#{role}#{xreflabel}#{attribute('numeration', :style)}>
#{title}
<% content.each do |li| %>
<listitem>
@@ -217,8 +209,7 @@ end
class BlockColistTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<calloutlist#{id}#{role}#{xreflabel}>
+<%#encoding:UTF-8%><calloutlist#{id}#{role}#{xreflabel}>
#{title}
<% content.each do |li| %>
<callout arearefs="<%= li.attr :coids %>">
@@ -257,8 +248,7 @@ class BlockDlistTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<% tags = (template.class::LIST_TAGS[attr :style] || template.class::LIST_TAGS['labeled']) %>
+<%#encoding:UTF-8%><% tags = (template.class::LIST_TAGS[attr :style] || template.class::LIST_TAGS['labeled']) %>
<% if tags[:list] %><<%= tags[:list] %>#{id}#{role}#{xreflabel}><% end %>
#{title}
<% content.each do |dt, dd| %>
@@ -286,8 +276,7 @@ end
class BlockOpenTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<%= content %>
+<%#encoding:UTF-8%><%= content %>
EOS
end
end
@@ -295,8 +284,7 @@ end
class BlockListingTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<% if !title? %>
+<%#encoding:UTF-8%><% if !title? %>
<% if (attr :style) == 'source' %>
<programlisting#{id}#{role}#{xreflabel}#{attribute('language', :language)} linenumbering="<%= (attr? :linenums) ? 'numbered' : 'unnumbered' %>"><%= template.preserve_endlines(content, self) %></programlisting>
<% else %>
@@ -321,8 +309,7 @@ end
class BlockLiteralTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<% if !title? %>
+<%#encoding:UTF-8%><% if !title? %>
<literallayout#{id}#{role}#{xreflabel} class="monospaced"><%= template.preserve_endlines(content, self) %></literallayout>
<% else %>
<formalpara#{id}#{role}#{xreflabel}>
@@ -339,8 +326,7 @@ end
class BlockExampleTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<example#{id}#{role}#{xreflabel}>
+<%#encoding:UTF-8%><example#{id}#{role}#{xreflabel}>
#{title}
<%= content %>
</example>
@@ -351,8 +337,7 @@ end
class BlockSidebarTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<sidebar#{id}#{role}#{xreflabel}>
+<%#encoding:UTF-8%><sidebar#{id}#{role}#{xreflabel}>
#{title}
<%= content %>
</sidebar>
@@ -363,8 +348,7 @@ end
class BlockQuoteTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<blockquote#{id}#{role}#{xreflabel}>
+<%#encoding:UTF-8%><blockquote#{id}#{role}#{xreflabel}>
#{title}
<% if (attr? :attribution) || (attr? :citetitle) %>
<attribution>
@@ -387,8 +371,7 @@ end
class BlockVerseTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<blockquote#{id}#{role}#{xreflabel}>
+<%#encoding:UTF-8%><blockquote#{id}#{role}#{xreflabel}>
#{title}
<% if (attr? :attribution) || (attr? :citetitle) %>
<attribution>
@@ -407,8 +390,7 @@ end
class BlockPassTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<%= content %>
+<%#encoding:UTF-8%><%= content %>
EOS
end
end
@@ -416,8 +398,7 @@ end
class BlockTableTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<<%= title? ? 'table' : 'informaltable'%>#{id}#{role}#{xreflabel} frame="<%= attr :frame, 'all'%>"
+<%#encoding:UTF-8%><<%= title? ? 'table' : 'informaltable'%>#{id}#{role}#{xreflabel} frame="<%= attr :frame, 'all'%>"
rowsep="<%= ['none', 'cols'].include?(attr :grid) ? 0 : 1 %>" colsep="<%= ['none', 'rows'].include?(attr :grid) ? 0 : 1 %>">
#{title}
<% if attr? :width %>
@@ -460,8 +441,7 @@ end
class BlockImageTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%#encoding:UTF-8%>
-<figure#{id}#{role}#{xreflabel}>
+<%#encoding:UTF-8%><%#encoding:UTF-8%><figure#{id}#{role}#{xreflabel}>
#{title}
<mediaobject>
<imageobject>
@@ -477,7 +457,7 @@ end
class BlockRulerTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<simpara><?asciidoc-hr?></simpara>
+<%#encoding:UTF-8%><simpara><?asciidoc-hr?></simpara>
EOF
end
end
@@ -485,7 +465,7 @@ end
class InlineBreakTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<%= text %><?asciidoc-br?>
+<%#encoding:UTF-8%><%= text %><?asciidoc-br?>
EOF
end
end
@@ -504,7 +484,7 @@ class InlineQuotedTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<% tags = template.class::QUOTED_TAGS[@type] %><%= tags.first %><%
+<%#encoding:UTF-8%><% tags = template.class::QUOTED_TAGS[@type] %><%= tags.first %><%
if attr? :role %><phrase#{role}><%
end %><%= @text %><%
if attr? :role %></phrase><%
@@ -516,7 +496,7 @@ end
class InlineAnchorTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<% if @type == :xref
+<%#encoding:UTF-8%><% if @type == :xref
%><%
if @text.nil?
%><xref linkend="<%= @target %>"/><%
@@ -537,7 +517,7 @@ end
class InlineImageTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<inlinemediaobject>
+<%#encoding:UTF-8%><inlinemediaobject>
<imageobject>
<imagedata fileref="<%= image_uri(@target) %>"#{attribute('width', :width)}#{attribute('depth', :height)}/>
</imageobject>
@@ -550,13 +530,12 @@ end
class InlineFootnoteTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%
+<%#encoding:UTF-8%><%
if type == :xref
%><footnoteref linkend="<%= @target %>"/><%
else
%><footnote#{id}><simpara><%= @text %></simpara></footnote><%
-end
-%>
+end %>
EOS
end
end
@@ -564,7 +543,7 @@ end
class InlineCalloutTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOF
-<co#{id}/>
+<%#encoding:UTF-8%><co#{id}/>
EOF
end
end
@@ -572,7 +551,7 @@ end
class InlineIndextermTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<% if type == :visible %><indexterm><primary><%= @text %></primary></indexterm><%= @text %><%
+<%#encoding:UTF-8%><% if type == :visible %><indexterm><primary><%= @text %></primary></indexterm><%= @text %><%
else %><% terms = (attr :terms); numterms = terms.size %><%
if numterms > 2 %><indexterm>
<primary><%= terms[0] %></primary><secondary><%= terms[1] %></secondary><tertiary><%= terms[2] %></tertiary>
diff --git a/lib/asciidoctor/backends/html5.rb b/lib/asciidoctor/backends/html5.rb
index 57274483..aab4614f 100644
--- a/lib/asciidoctor/backends/html5.rb
+++ b/lib/asciidoctor/backends/html5.rb
@@ -57,8 +57,7 @@ class DocumentTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<!DOCTYPE html>
+<%#encoding:UTF-8%><!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<%= attr :encoding %>">
@@ -144,8 +143,7 @@ end
class EmbeddedTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<%= content %>
+<%#encoding:UTF-8%><%= content %>
EOS
end
end
@@ -153,8 +151,7 @@ end
class BlockPreambleTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div id="preamble">
+<%#encoding:UTF-8%><div id="preamble">
<div class="sectionbody">
<%= content %>
</div>
@@ -166,8 +163,8 @@ end
class SectionTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<% if @level == 0 %>
+<%#encoding:UTF-8%><%
+if @level == 0 %>
<h1#{id}><%= title %></h1>
<%= content %>
<% else %>
@@ -189,7 +186,7 @@ end
class BlockFloatingTitleTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<h<%= @level + 1 %>#{id} class="#{style_class false}#{role_class}"><%= title %></h<%= @level + 1 %>>
+<%#encoding:UTF-8%><h<%= @level + 1 %>#{id} class="#{style_class false}#{role_class}"><%= title %></h<%= @level + 1 %>>
EOS
end
end
@@ -197,8 +194,8 @@ end
class BlockDlistTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<% if (attr :style) == 'qanda' %>
+<%#encoding:UTF-8%><%
+if (attr :style) == 'qanda' %>
<div#{id} class="qlist#{style_class}#{role_class}">
#{title_div}
<ol>
@@ -268,8 +265,7 @@ end
class BlockListingTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div#{id} class="listingblock#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="listingblock#{role_class}">
#{title_div}
<div class="content monospaced">
<% if (attr :style) == 'source' %>
@@ -286,8 +282,7 @@ end
class BlockLiteralTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div#{id} class="literalblock#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="literalblock#{role_class}">
#{title_div}
<div class="content monospaced">
<pre><%= template.preserve_endlines(content, self) %></pre>
@@ -300,8 +295,7 @@ end
class BlockAdmonitionTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div#{id} class="admonitionblock#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="admonitionblock#{role_class}">
<table>
<tr>
<td class="icon">
@@ -325,8 +319,7 @@ end
class BlockParagraphTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div#{id} class="paragraph#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="paragraph#{role_class}">
#{title_div}
<p><%= content %></p>
</div>
@@ -337,8 +330,7 @@ end
class BlockSidebarTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div#{id} class="sidebarblock#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="sidebarblock#{role_class}">
<div class="content">
#{title_div}
<%= content %>
@@ -351,8 +343,7 @@ end
class BlockExampleTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div#{id} class="exampleblock#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="exampleblock#{role_class}">
#{title_div :caption => true}
<div class="content">
<%= content %>
@@ -365,8 +356,7 @@ end
class BlockOpenTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div#{id} class="openblock#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="openblock#{role_class}">
#{title_div}
<div class="content">
<%= content %>
@@ -379,8 +369,7 @@ end
class BlockPassTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<%= content %>
+<%#encoding:UTF-8%><%= content %>
EOS
end
end
@@ -388,8 +377,7 @@ end
class BlockQuoteTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div#{id} class="quoteblock#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="quoteblock#{role_class}">
#{title_div}
<blockquote>
<%= content %>
@@ -413,8 +401,7 @@ end
class BlockVerseTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div#{id} class="verseblock#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="verseblock#{role_class}">
#{title_div}
<pre class="content"><%= template.preserve_endlines(content, self) %></pre>
<div class="attribution">
@@ -436,8 +423,7 @@ end
class BlockUlistTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div#{id} class="ulist#{style_class}#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="ulist#{style_class}#{role_class}">
#{title_div}
<ul>
<% content.each do |li| %>
@@ -457,8 +443,7 @@ end
class BlockOlistTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div#{id} class="olist#{style_class}#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="olist#{style_class}#{role_class}">
#{title_div}
<ol class="<%= attr :style %>"#{attribute('start', :start)}>
<% content.each do |li| %>
@@ -478,8 +463,7 @@ end
class BlockColistTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div#{id} class="colist#{style_class}#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="colist#{style_class}#{role_class}">
#{title_div}
<% if attr? :icons %>
<table>
@@ -507,8 +491,7 @@ end
class BlockTableTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<table#{id} class="tableblock frame-<%= attr :frame, 'all' %> grid-<%= attr :grid, 'all'%>#{role_class}" style="<%
+<%#encoding:UTF-8%><table#{id} class="tableblock frame-<%= attr :frame, 'all' %> grid-<%= attr :grid, 'all'%>#{role_class}" style="<%
if !(attr? 'autowidth-option') %>width: <%= attr :tablepcwidth %>%; <% end %><%
if attr? :float %>float: <%= attr :float %>; <% end %>">
<% if title? %>
@@ -554,8 +537,7 @@ end
class BlockImageTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%#encoding:UTF-8%>
-<div#{id} class="imageblock#{role_class}">
+<%#encoding:UTF-8%><div#{id} class="imageblock#{role_class}">
<div class="content">
<% if attr :link %>
<a class="image" href="<%= attr :link %>"><img src="<%= image_uri(attr :target) %>" alt="<%= attr :alt %>"#{attribute('width', :width)}#{attribute('height', :height)}></a>
@@ -572,7 +554,7 @@ end
class BlockRulerTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<hr>
+<%#encoding:UTF-8%><hr>
EOS
end
end
@@ -580,7 +562,7 @@ end
class InlineBreakTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%= text %><br>
+<%#encoding:UTF-8%><%= text %><br>
EOS
end
end
@@ -588,7 +570,7 @@ end
class InlineCalloutTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<% if attr? :icons %><img src="<%= icon_uri("callouts/\#@text") %>" alt="<%= @text %>"><% else %><b>&lt;<%= @text %>&gt;</b><% end %>
+<%#encoding:UTF-8%><% if attr? :icons %><img src="<%= icon_uri("callouts/\#@text") %>" alt="<%= @text %>"><% else %><b>&lt;<%= @text %>&gt;</b><% end %>
EOS
end
end
@@ -607,7 +589,7 @@ class InlineQuotedTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<% tags = template.class::QUOTED_TAGS[@type] %><%= tags.first %><%
+<%#encoding:UTF-8%><% tags = template.class::QUOTED_TAGS[@type] %><%= tags.first %><%
if attr? :role %><span#{attribute('class', :role)}><%
end %><%= @text %><%
if attr? :role %></span><%
@@ -619,7 +601,7 @@ end
class InlineAnchorTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%
+<%#encoding:UTF-8%><%
if type == :xref
%><a href="#<%= @target %>"><%= @text || @document.references[:ids].fetch(@target, '[' + @target + ']') %></a><%
elsif @type == :ref
@@ -628,8 +610,7 @@ elsif @type == :bibref
%><a id="<%= @target %>"></a>[<%= @target %>]<%
else
%><a href="<%= @target %>"><%= @text %></a><%
-end
-%>
+end %>
EOS
end
end
@@ -638,7 +619,7 @@ class InlineImageTemplate < ::Asciidoctor::BaseTemplate
def template
# care is taken here to avoid a space inside the optional <a> tag
@template ||= @eruby.new <<-EOS
-<span class="image#{role_class}">
+<%#encoding:UTF-8%><span class="image#{role_class}">
<%
if attr :link %><a class="image" href="<%= attr :link %>"><%
end %><img src="<%= image_uri(target) %>" alt="<%= attr :alt %>"#{attribute('width', :width)}#{attribute('height', :height)}#{attribute('title', :title)}><%
@@ -652,13 +633,12 @@ end
class InlineFootnoteTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<%
+<%#encoding:UTF-8%><%
if type == :xref
%><span class="footnoteref">[<a href="#_footnote_<%= attr :index %>" title="View footnote." class="footnote"><%= attr :index %></a>]</span><%
else
%><span class="footnote"<% if @id %> id="_footnote_<%= @id %>"<% end %>>[<a id="_footnoteref_<%= attr :index %>" href="#_footnote_<%= attr :index %>" title="View footnote." class="footnote"><%= attr :index %></a>]</span><%
-end
-%>
+end %>
EOS
end
end
@@ -666,7 +646,7 @@ end
class InlineIndextermTemplate < ::Asciidoctor::BaseTemplate
def template
@template ||= @eruby.new <<-EOS
-<% if type == :visible %><%= @text %><% end %>
+<%#encoding:UTF-8%><% if type == :visible %><%= @text %><% end %>
EOS
end
end
diff --git a/test/fixtures/encoding.asciidoc b/test/fixtures/encoding.asciidoc
index 3b260ab9..cbc10057 100644
--- a/test/fixtures/encoding.asciidoc
+++ b/test/fixtures/encoding.asciidoc
@@ -1 +1,5 @@
Gregory Romé has written an AsciiDoc plugin for the Redmine project management application.
+
+https://github.com/foo-users/foo
+へと `vicmd` キーマップを足してみている試み、
+アニメーションgifです。
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 6b7c2333..9e5f63bb 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -41,8 +41,9 @@ class Test::Unit::TestCase
File.join(File.expand_path(File.dirname(__FILE__)), 'fixtures', name)
end
- def example_document(name)
- Asciidoctor::Document.new(File.readlines(sample_doc_path(name)), :header_footer => true)
+ def example_document(name, opts = {})
+ opts[:header_footer] = true unless opts.has_key?(:header_footer)
+ Asciidoctor::Document.new(File.readlines(sample_doc_path(name)), opts)
end
def assert_difference(expression, difference = 1, message = nil, &block)
diff --git a/test/text_test.rb b/test/text_test.rb
index de8695b6..daa87ea9 100644
--- a/test/text_test.rb
+++ b/test/text_test.rb
@@ -1,12 +1,28 @@
require 'test_helper'
context "Text" do
- test "proper encoding to handle utf8 characters in document" do
- assert_xpath "//p", example_document(:encoding).render, 1
+ test "proper encoding to handle utf8 characters in document using html backend" do
+ output = example_document(:encoding).render
+ assert_xpath '//p', output, 2
+ assert_xpath '//a', output, 1
end
- test "proper encoding to handle utf8 characters in embedded document" do
- assert_xpath "//p", example_document(:encoding).render(:header_footer => false), 1
+ test "proper encoding to handle utf8 characters in embedded document using html backend" do
+ output = example_document(:encoding, :header_footer => false).render
+ assert_xpath '//p', output, 2
+ assert_xpath '//a', output, 1
+ end
+
+ test "proper encoding to handle utf8 characters in document using docbook backend" do
+ output = example_document(:encoding, :attributes => {'backend' => 'docbook'}).render
+ assert_xpath '//simpara', output, 2
+ assert_xpath '//ulink', output, 1
+ end
+
+ test "proper encoding to handle utf8 characters in embedded document using docbook backend" do
+ output = example_document(:encoding, :header_footer => false, :attributes => {'backend' => 'docbook'}).render
+ assert_xpath '//simpara', output, 2
+ assert_xpath '//ulink', output, 1
end
# NOTE this test ensures we have the encoding line on block templates too