summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/asciidoctor.rb2
-rw-r--r--lib/asciidoctor/abstract_node.rb13
-rw-r--r--lib/asciidoctor/backends/html5.rb18
-rw-r--r--lib/asciidoctor/lexer.rb13
-rw-r--r--lib/asciidoctor/substituters.rb34
-rw-r--r--lib/asciidoctor/table.rb4
6 files changed, 63 insertions, 21 deletions
diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb
index c2b85537..63169603 100755
--- a/lib/asciidoctor.rb
+++ b/lib/asciidoctor.rb
@@ -443,7 +443,7 @@ module Asciidoctor
# inline literal passthrough macro
# `text`
- :pass_lit => /(^|[^`\w])(\\?`([^`\s]|[^`\s].*?\S)`)(?![`\w])/m,
+ :pass_lit => /(^|[^`\w])(?:\[([^\]]+?)\])?(\\?`([^`\s]|[^`\s].*?\S)`)(?![`\w])/m,
# placeholder for extracted passthrough text
:pass_placeholder => /\e(\d+)\e/,
diff --git a/lib/asciidoctor/abstract_node.rb b/lib/asciidoctor/abstract_node.rb
index ca66e971..7e5ed72e 100644
--- a/lib/asciidoctor/abstract_node.rb
+++ b/lib/asciidoctor/abstract_node.rb
@@ -121,6 +121,19 @@ class AbstractNode
end
end
+ # Public: A convenience method to check if the specified option attribute is
+ # enabled on the current node.
+ #
+ # Check if the option is enabled. This method simply checks to see if the
+ # {name}-option attribute is defined on the current node.
+ #
+ # name - the String or Symbol name of the option
+ #
+ # return a Boolean indicating whether the option has been specified
+ def option?(name)
+ @attributes.has_key? "#{name}-option"
+ end
+
# Public: Get the execution context of this object (via Kernel#binding).
#
# This method is used to set the 'self' reference as well as local variables
diff --git a/lib/asciidoctor/backends/html5.rb b/lib/asciidoctor/backends/html5.rb
index c8f36f4c..c6bca207 100644
--- a/lib/asciidoctor/backends/html5.rb
+++ b/lib/asciidoctor/backends/html5.rb
@@ -358,7 +358,7 @@ end %><%
last = (index == last_index)
unless continuing %>
<tr>
-<td class="hdlist1<%= (attr? 'strong-option') ? 'strong' : nil %>"><%
+<td class="hdlist1<%= (option? 'strong') ? 'strong' : nil %>"><%
end %>
<%= dt.text %>
<br><%
@@ -698,14 +698,14 @@ class BlockTableTemplate < 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="<%
-if !(attr? 'autowidth-option') %>width:<%= attr :tablepcwidth %>%; <% end %><%
+if !(option? 'autowidth') %>width:<%= attr :tablepcwidth %>%; <% end %><%
if attr? :float %>float: <%= attr :float %>; <% end %>"><%
if title? %>
<caption class="title"><% unless @caption.nil? %><%= @caption %><% end %><%= title %></caption><%
end
if (attr :rowcount) >= 0 %>
<colgroup><%
- if attr? 'autowidth-option'
+ if option? 'autowidth'
@columns.each do %>
<col><%
end
@@ -781,9 +781,9 @@ class BlockAudioTemplate < BaseTemplate
#{title_div :caption => true}
<div class="content">
<audio src="<%= media_uri(attr :target) %>"<%
-if attr? 'autoplay-option' %> autoplay<% end %><%
-unless attr? 'nocontrols-option' %> controls<% end %><%
-if attr? 'loop-option' %> loop<% end %>>
+if option? 'autoplay' %> autoplay<% end %><%
+unless option? 'nocontrols' %> controls<% end %><%
+if option? 'loop' %> loop<% end %>>
Your browser does not support the audio tag.
</audio>
</div>
@@ -800,9 +800,9 @@ class BlockVideoTemplate < BaseTemplate
<div class="content">
<video src="<%= media_uri(attr :target) %>"#{attribute('width', :width)}#{attribute('height', :height)}<%
if attr? 'poster' %> poster="<%= media_uri(attr :poster) %>"<% end %><%
-if attr? 'autoplay-option' %> autoplay<% end %><%
-unless attr? 'nocontrols-option' %> controls<% end %><%
-if attr? 'loop-option' %> loop<% end %>>
+if option? 'autoplay' %> autoplay<% end %><%
+unless option? 'nocontrols' %> controls<% end %><%
+if option? 'loop' %> loop<% end %>>
Your browser does not support the video tag.
</video>
</div>
diff --git a/lib/asciidoctor/lexer.rb b/lib/asciidoctor/lexer.rb
index 126eaf74..d31aa831 100644
--- a/lib/asciidoctor/lexer.rb
+++ b/lib/asciidoctor/lexer.rb
@@ -1893,12 +1893,21 @@ class Lexer
explicit_col_specs = false
end
- table_reader.skip_blank_lines
+ skipped = table_reader.skip_blank_lines
parser_ctx = Table::ParserContext.new(table, attributes)
+ loop_idx = -1
while table_reader.has_more_lines?
+ loop_idx += 1
line = table_reader.get_line
+ if skipped == 0 && loop_idx.zero? && !attributes.has_key?('options') &&
+ !(next_line = table_reader.peek_line(false)).nil? && next_line.chomp.empty?
+ table.has_header_option = true
+ attributes['options'] = "header"
+ attributes['header-option'] = ''
+ end
+
if parser_ctx.format == 'psv'
if parser_ctx.starts_with_delimiter? line
line = line[1..-1]
@@ -1959,7 +1968,7 @@ class Lexer
end
end
- table_reader.skip_blank_lines unless parser_ctx.cell_open?
+ skipped = table_reader.skip_blank_lines unless parser_ctx.cell_open?
if !table_reader.has_more_lines?
parser_ctx.close_cell true
diff --git a/lib/asciidoctor/substituters.rb b/lib/asciidoctor/substituters.rb
index a4db6768..fb00dc3f 100644
--- a/lib/asciidoctor/substituters.rb
+++ b/lib/asciidoctor/substituters.rb
@@ -174,11 +174,20 @@ module Substituters
m = $~
# honor the escape
- if m[2].start_with? '\\'
- next "#{m[1]}#{m[2][1..-1]}"
+ if m[3].start_with? '\\'
+ if m[2].nil?
+ next "#{m[1]}#{m[3][1..-1]}"
+ else
+ next "#{m[1]}[#{m[2]}]#{m[3][1..-1]}"
+ end
+ end
+
+ attributes = {}
+ unless m[2].nil?
+ attributes = parse_attributes(m[2])
end
- @passthroughs << {:text => m[3], :subs => [:specialcharacters], :literal => true}
+ @passthroughs << {:text => m[4], :subs => [:specialcharacters], :attributes => attributes, :literal => true}
index = @passthroughs.size - 1
"#{m[1]}\e#{index}\e"
} unless !result.include?('`')
@@ -197,7 +206,7 @@ module Substituters
text.gsub(REGEXP[:pass_placeholder]) {
pass = @passthroughs[$1.to_i];
text = apply_subs(pass[:text], pass.fetch(:subs, []))
- pass[:literal] ? Inline.new(self, :quoted, text, :type => :monospaced).render : text
+ pass[:literal] ? Inline.new(self, :quoted, text, :type => :monospaced, :attributes => pass.fetch(:attributes, {})).render : text
}
end
@@ -738,10 +747,21 @@ module Substituters
#
# returns The rendered text for the quoted text region
def transform_quoted_text(match, type, scope)
+ unescaped_attrs = nil
if match[0].start_with? '\\'
- match[0][1..-1]
- elsif scope == :constrained
- "#{match[1]}#{Inline.new(self, :quoted, match[3], :type => type, :attributes => parse_attributes(match[2])).render}"
+ if scope == :constrained && !match[2].nil?
+ unescaped_attrs = "[#{match[2]}]"
+ else
+ return match[0][1..-1]
+ end
+ end
+
+ if scope == :constrained
+ if unescaped_attrs.nil?
+ "#{match[1]}#{Inline.new(self, :quoted, match[3], :type => type, :attributes => parse_attributes(match[2])).render}"
+ else
+ "#{unescaped_attrs}#{Inline.new(self, :quoted, match[3], :type => type, :attributes => {}).render}"
+ end
else
Inline.new(self, :quoted, match[2], :type => type, :attributes => parse_attributes(match[1])).render
end
diff --git a/lib/asciidoctor/table.rb b/lib/asciidoctor/table.rb
index b2a59277..64e50b0e 100644
--- a/lib/asciidoctor/table.rb
+++ b/lib/asciidoctor/table.rb
@@ -52,7 +52,7 @@ class Table < AbstractBlock
attr_accessor :rows
# Public: Boolean specifies whether this table has a header row
- attr_reader :header_option
+ attr_accessor :has_header_option
def initialize(parent, attributes)
super(parent, :table)
@@ -110,7 +110,7 @@ class Table < AbstractBlock
# set rowcount before splitting up body rows
@attributes['rowcount'] = @rows.body.size
- if !rows.body.empty? && attributes.has_key?('header-option')
+ if !rows.body.empty? && @has_header_option
head = rows.body.shift
# styles aren't applied to header row
head.each {|c| c.attributes.delete('style') }