asciidoctor 1.5.6.2 → 1.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of asciidoctor might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +330 -143
- data/README-fr.adoc +441 -0
- data/README-jp.adoc +418 -0
- data/README-zh_CN.adoc +430 -0
- data/README.adoc +454 -0
- data/Rakefile +57 -0
- data/asciidoctor.gemspec +7 -1
- data/data/locale/attributes-ar.adoc +22 -0
- data/data/locale/attributes-bg.adoc +22 -0
- data/data/locale/attributes-ca.adoc +22 -0
- data/data/locale/attributes-cs.adoc +22 -0
- data/data/locale/attributes-da.adoc +22 -0
- data/data/locale/attributes-de.adoc +22 -0
- data/data/locale/attributes-en.adoc +23 -0
- data/data/locale/attributes-es.adoc +22 -0
- data/data/locale/attributes-fa.adoc +22 -0
- data/data/locale/attributes-fi.adoc +22 -0
- data/data/locale/attributes-fr.adoc +22 -0
- data/data/locale/attributes-hu.adoc +22 -0
- data/data/locale/attributes-id.adoc +22 -0
- data/data/locale/attributes-it.adoc +22 -0
- data/data/locale/attributes-ja.adoc +22 -0
- data/data/locale/attributes-kr.adoc +22 -0
- data/data/locale/attributes-nb.adoc +22 -0
- data/data/locale/attributes-nl.adoc +22 -0
- data/data/locale/attributes-nn.adoc +22 -0
- data/data/locale/attributes-pl.adoc +22 -0
- data/data/locale/attributes-pt.adoc +22 -0
- data/data/locale/attributes-pt_BR.adoc +22 -0
- data/data/locale/attributes-ro.adoc +22 -0
- data/data/locale/attributes-ru.adoc +22 -0
- data/data/locale/attributes-sr.adoc +22 -0
- data/data/locale/attributes-sr_Latn.adoc +22 -0
- data/data/locale/attributes-tr.adoc +22 -0
- data/data/locale/attributes-uk.adoc +22 -0
- data/data/locale/attributes-zh_CN.adoc +22 -0
- data/data/locale/attributes-zh_TW.adoc +22 -0
- data/data/locale/attributes.adoc +8 -649
- data/data/stylesheets/asciidoctor-default.css +77 -72
- data/features/xref.feature +366 -7
- data/lib/asciidoctor.rb +107 -93
- data/lib/asciidoctor/abstract_block.rb +247 -239
- data/lib/asciidoctor/abstract_node.rb +56 -58
- data/lib/asciidoctor/block.rb +3 -3
- data/lib/asciidoctor/callouts.rb +1 -1
- data/lib/asciidoctor/cli/invoker.rb +36 -9
- data/lib/asciidoctor/cli/options.rb +63 -25
- data/lib/asciidoctor/converter.rb +23 -13
- data/lib/asciidoctor/converter/base.rb +4 -0
- data/lib/asciidoctor/converter/docbook45.rb +16 -9
- data/lib/asciidoctor/converter/docbook5.rb +115 -97
- data/lib/asciidoctor/converter/factory.rb +29 -31
- data/lib/asciidoctor/converter/html5.rb +229 -192
- data/lib/asciidoctor/converter/manpage.rb +72 -50
- data/lib/asciidoctor/converter/template.rb +12 -12
- data/lib/asciidoctor/core_ext.rb +5 -1
- data/lib/asciidoctor/core_ext/1.8.7/base64/strict_encode64.rb +6 -0
- data/lib/asciidoctor/document.rb +168 -77
- data/lib/asciidoctor/extensions.rb +79 -47
- data/lib/asciidoctor/helpers.rb +33 -11
- data/lib/asciidoctor/inline.rb +3 -2
- data/lib/asciidoctor/list.rb +2 -1
- data/lib/asciidoctor/logging.rb +122 -0
- data/lib/asciidoctor/parser.rb +406 -382
- data/lib/asciidoctor/path_resolver.rb +169 -162
- data/lib/asciidoctor/reader.rb +166 -121
- data/lib/asciidoctor/section.rb +45 -28
- data/lib/asciidoctor/stylesheets.rb +13 -5
- data/lib/asciidoctor/substitutors.rb +328 -254
- data/lib/asciidoctor/table.rb +105 -48
- data/lib/asciidoctor/timings.rb +34 -6
- data/lib/asciidoctor/version.rb +1 -1
- data/man/asciidoctor.1 +41 -23
- data/man/asciidoctor.adoc +14 -8
- data/test/api_test.rb +1004 -0
- data/test/attributes_test.rb +241 -50
- data/test/blocks_test.rb +549 -124
- data/test/converter_test.rb +170 -78
- data/test/document_test.rb +208 -767
- data/test/extensions_test.rb +188 -53
- data/test/fixtures/custom-backends/slim/html5/block_paragraph.html.slim +1 -1
- data/test/fixtures/custom-backends/slim/html5/block_sidebar.html.slim +1 -1
- data/test/fixtures/file-with-missing-include.adoc +1 -0
- data/test/fixtures/include-file.jsx +8 -0
- data/test/fixtures/lists.adoc +96 -0
- data/test/fixtures/other-chapters.adoc +11 -0
- data/test/fixtures/outer-include.adoc +5 -0
- data/test/fixtures/sample.asciidoc +5 -1
- data/test/fixtures/subdir/index.adoc +3 -0
- data/test/fixtures/subdir/inner-include.adoc +3 -0
- data/test/fixtures/subdir/middle-include.adoc +5 -0
- data/test/fixtures/tagged-class-enclosed.rb +0 -1
- data/test/fixtures/unclosed-tag.adoc +3 -0
- data/test/fixtures/unexpected-end-tag.adoc +4 -0
- data/test/invoker_test.rb +101 -40
- data/test/links_test.rb +266 -72
- data/test/lists_test.rb +243 -45
- data/test/logger_test.rb +211 -0
- data/test/manpage_test.rb +124 -6
- data/test/options_test.rb +46 -1
- data/test/paragraphs_test.rb +23 -10
- data/test/parser_test.rb +30 -1
- data/test/paths_test.rb +115 -33
- data/test/preamble_test.rb +1 -1
- data/test/reader_test.rb +337 -81
- data/test/sections_test.rb +656 -72
- data/test/substitutions_test.rb +182 -57
- data/test/tables_test.rb +324 -57
- data/test/test_helper.rb +77 -32
- data/test/text_test.rb +7 -7
- metadata +67 -3
| @@ -1,24 +1,18 @@ | |
| 1 1 | 
             
            # encoding: UTF-8
         | 
| 2 2 | 
             
            module Asciidoctor
         | 
| 3 3 | 
             
            class AbstractBlock < AbstractNode
         | 
| 4 | 
            -
              # Public: The types of content that this block can accomodate
         | 
| 5 | 
            -
              attr_accessor :content_model
         | 
| 6 | 
            -
             | 
| 7 | 
            -
              # Public: Substitutions to be applied to content in this block
         | 
| 8 | 
            -
              attr_reader :subs
         | 
| 9 | 
            -
             | 
| 10 4 | 
             
              # Public: Get the Array of Asciidoctor::AbstractBlock sub-blocks for this block
         | 
| 11 5 | 
             
              attr_reader :blocks
         | 
| 12 6 |  | 
| 13 | 
            -
              # Public: Set the Integer level of this Section or the Section level in which this Block resides
         | 
| 14 | 
            -
              attr_accessor :level
         | 
| 15 | 
            -
             | 
| 16 | 
            -
              # Public: Get/Set the String style (block type qualifier) for this block.
         | 
| 17 | 
            -
              attr_accessor :style
         | 
| 18 | 
            -
             | 
| 19 7 | 
             
              # Public: Set the caption for this block
         | 
| 20 8 | 
             
              attr_writer :caption
         | 
| 21 9 |  | 
| 10 | 
            +
              # Public: The types of content that this block can accomodate
         | 
| 11 | 
            +
              attr_accessor :content_model
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              # Public: Set the Integer level of this Section or the Section level in which this Block resides
         | 
| 14 | 
            +
              attr_accessor :level
         | 
| 15 | 
            +
             | 
| 22 16 | 
             
              # Public: Get/Set the number of this block (if section, relative to parent, otherwise absolute)
         | 
| 23 17 | 
             
              # Only assigned to section if automatic section numbering is enabled
         | 
| 24 18 | 
             
              # Only assigned to formal block (block with title) if corresponding caption attribute is present
         | 
| @@ -27,6 +21,12 @@ class AbstractBlock < AbstractNode | |
| 27 21 | 
             
              # Public: Gets/Sets the location in the AsciiDoc source where this block begins
         | 
| 28 22 | 
             
              attr_accessor :source_location
         | 
| 29 23 |  | 
| 24 | 
            +
              # Public: Get/Set the String style (block type qualifier) for this block.
         | 
| 25 | 
            +
              attr_accessor :style
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              # Public: Substitutions to be applied to content in this block
         | 
| 28 | 
            +
              attr_reader :subs
         | 
| 29 | 
            +
             | 
| 30 30 | 
             
              def initialize parent, context, opts = {}
         | 
| 31 31 | 
             
                super
         | 
| 32 32 | 
             
                @content_model = :compound
         | 
| @@ -52,13 +52,14 @@ class AbstractBlock < AbstractNode | |
| 52 52 | 
             
                false
         | 
| 53 53 | 
             
              end
         | 
| 54 54 |  | 
| 55 | 
            -
              # Public:  | 
| 56 | 
            -
               | 
| 57 | 
            -
             | 
| 58 | 
            -
               | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 55 | 
            +
              # Public: Get the source file where this block started
         | 
| 56 | 
            +
              def file
         | 
| 57 | 
            +
                @source_location && @source_location.file
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
              # Public: Get the source line number where this block started
         | 
| 61 | 
            +
              def lineno
         | 
| 62 | 
            +
                @source_location && @source_location.lineno
         | 
| 62 63 | 
             
              end
         | 
| 63 64 |  | 
| 64 65 | 
             
              # Public: Get the converted String content for this Block.  If the block
         | 
| @@ -79,147 +80,15 @@ class AbstractBlock < AbstractNode | |
| 79 80 | 
             
                @blocks.map {|b| b.convert } * LF
         | 
| 80 81 | 
             
              end
         | 
| 81 82 |  | 
| 82 | 
            -
              # Public:  | 
| 83 | 
            -
              def file
         | 
| 84 | 
            -
                @source_location ? @source_location.file : nil
         | 
| 85 | 
            -
              end
         | 
| 86 | 
            -
             | 
| 87 | 
            -
              # Public: Get the source line number where this block started
         | 
| 88 | 
            -
              def lineno
         | 
| 89 | 
            -
                @source_location ? @source_location.lineno : nil
         | 
| 90 | 
            -
              end
         | 
| 91 | 
            -
             | 
| 92 | 
            -
              # Public: A convenience method that checks whether the specified
         | 
| 93 | 
            -
              # substitution is enabled for this block.
         | 
| 94 | 
            -
              #
         | 
| 95 | 
            -
              # name - The Symbol substitution name
         | 
| 96 | 
            -
              #
         | 
| 97 | 
            -
              # Returns A Boolean indicating whether the specified substitution is
         | 
| 98 | 
            -
              # enabled for this block
         | 
| 99 | 
            -
              def sub? name
         | 
| 100 | 
            -
                @subs.include? name
         | 
| 101 | 
            -
              end
         | 
| 102 | 
            -
             | 
| 103 | 
            -
              # Public: A convenience method that checks whether the title of this block is defined.
         | 
| 104 | 
            -
              #
         | 
| 105 | 
            -
              # Returns a [Boolean] indicating whether this block has a title.
         | 
| 106 | 
            -
              def title?
         | 
| 107 | 
            -
                @title ? true : false
         | 
| 108 | 
            -
              end
         | 
| 109 | 
            -
             | 
| 110 | 
            -
              # Public: Get the String title of this Block with title substitions applied
         | 
| 111 | 
            -
              #
         | 
| 112 | 
            -
              # The following substitutions are applied to block and section titles:
         | 
| 113 | 
            -
              #
         | 
| 114 | 
            -
              # :specialcharacters, :quotes, :replacements, :macros, :attributes and :post_replacements
         | 
| 115 | 
            -
              #
         | 
| 116 | 
            -
              # Examples
         | 
| 117 | 
            -
              #
         | 
| 118 | 
            -
              #   block.title = "Foo 3^ # {two-colons} Bar(1)"
         | 
| 119 | 
            -
              #   block.title
         | 
| 120 | 
            -
              #   => "Foo 3^ # :: Bar(1)"
         | 
| 121 | 
            -
              #
         | 
| 122 | 
            -
              # Returns the converted String title for this Block, or nil if the source title is falsy
         | 
| 123 | 
            -
              def title
         | 
| 124 | 
            -
                # prevent substitutions from being applied to title multiple times
         | 
| 125 | 
            -
                @title_converted ? @converted_title : (@converted_title = (@title_converted = true) && @title && (apply_title_subs @title))
         | 
| 126 | 
            -
              end
         | 
| 127 | 
            -
             | 
| 128 | 
            -
              # Public: Set the String block title.
         | 
| 129 | 
            -
              #
         | 
| 130 | 
            -
              # Returns the new String title assigned to this Block
         | 
| 131 | 
            -
              def title= val
         | 
| 132 | 
            -
                @title, @title_converted = val, nil
         | 
| 133 | 
            -
              end
         | 
| 134 | 
            -
             | 
| 135 | 
            -
              # Gets the caption for this block.
         | 
| 136 | 
            -
              #
         | 
| 137 | 
            -
              # This method routes the deprecated use of the caption method on an
         | 
| 138 | 
            -
              # admonition block to the textlabel attribute.
         | 
| 139 | 
            -
              #
         | 
| 140 | 
            -
              # Returns the [String] caption for this block (or the value of the textlabel
         | 
| 141 | 
            -
              # attribute if this is an admonition block).
         | 
| 142 | 
            -
              def caption
         | 
| 143 | 
            -
                @context == :admonition ? @attributes['textlabel'] : @caption
         | 
| 144 | 
            -
              end
         | 
| 145 | 
            -
             | 
| 146 | 
            -
              # Public: Convenience method that returns the interpreted title of the Block
         | 
| 147 | 
            -
              # with the caption prepended.
         | 
| 148 | 
            -
              #
         | 
| 149 | 
            -
              # Concatenates the value of this Block's caption instance variable and the
         | 
| 150 | 
            -
              # return value of this Block's title method. No space is added between the
         | 
| 151 | 
            -
              # two values. If the Block does not have a caption, the interpreted title is
         | 
| 152 | 
            -
              # returned.
         | 
| 153 | 
            -
              #
         | 
| 154 | 
            -
              # Returns the converted String title prefixed with the caption, or just the
         | 
| 155 | 
            -
              # converted String title if no caption is set
         | 
| 156 | 
            -
              def captioned_title
         | 
| 157 | 
            -
                %(#{@caption}#{title})
         | 
| 158 | 
            -
              end
         | 
| 159 | 
            -
             | 
| 160 | 
            -
              # Public: Returns the converted alt text for this block image.
         | 
| 161 | 
            -
              #
         | 
| 162 | 
            -
              # Returns the [String] value of the alt attribute with XML special character
         | 
| 163 | 
            -
              # and replacement substitutions applied.
         | 
| 164 | 
            -
              def alt
         | 
| 165 | 
            -
                if (text = @attributes['alt'])
         | 
| 166 | 
            -
                  if text == @attributes['default-alt']
         | 
| 167 | 
            -
                    sub_specialchars text
         | 
| 168 | 
            -
                  else
         | 
| 169 | 
            -
                    text = sub_specialchars text
         | 
| 170 | 
            -
                    (ReplaceableTextRx.match? text) ? (sub_replacements text) : text
         | 
| 171 | 
            -
                  end
         | 
| 172 | 
            -
                end
         | 
| 173 | 
            -
              end
         | 
| 174 | 
            -
             | 
| 175 | 
            -
              # Public: Generate cross reference text (xreftext) that can be used to refer
         | 
| 176 | 
            -
              # to this block.
         | 
| 177 | 
            -
              #
         | 
| 178 | 
            -
              # Use the explicit reftext for this block, if specified, retrieved from the
         | 
| 179 | 
            -
              # {#reftext} method. Otherwise, if this is a section or captioned block (a
         | 
| 180 | 
            -
              # block with both a title and caption), generate the xreftext according to
         | 
| 181 | 
            -
              # the value of the xrefstyle argument (e.g., full, short). This logic may
         | 
| 182 | 
            -
              # leverage the {Substitutors#sub_quotes} method to apply formatting to the
         | 
| 183 | 
            -
              # text. If this is not a captioned block, return the title, if present, or
         | 
| 184 | 
            -
              # nil otherwise.
         | 
| 83 | 
            +
              # Public: Update the context of this block.
         | 
| 185 84 | 
             
              #
         | 
| 186 | 
            -
              #  | 
| 187 | 
            -
              #             the xreftext ('full', 'short', or 'basic') (default: nil).
         | 
| 85 | 
            +
              # This method changes the context of this block. It also updates the node name accordingly.
         | 
| 188 86 | 
             
              #
         | 
| 189 | 
            -
              #  | 
| 190 | 
            -
              # nothing if there isn't sufficient information to generate one.
         | 
| 191 | 
            -
              def xreftext xrefstyle = nil
         | 
| 192 | 
            -
                if (val = reftext) && !val.empty?
         | 
| 193 | 
            -
                  val
         | 
| 194 | 
            -
                # NOTE xrefstyle only applies to blocks with a title and a caption or number
         | 
| 195 | 
            -
                elsif xrefstyle && @title && @caption
         | 
| 196 | 
            -
                  case xrefstyle
         | 
| 197 | 
            -
                  when 'full'
         | 
| 198 | 
            -
                    quoted_title = sprintf sub_quotes(@document.compat_mode ? %q(``%s'') : '"`%s`"'), title
         | 
| 199 | 
            -
                    if @number && (prefix = @document.attributes[@context == :image ? 'figure-caption' : %(#{@context}-caption)])
         | 
| 200 | 
            -
                      %(#{prefix} #{@number}, #{quoted_title})
         | 
| 201 | 
            -
                    else
         | 
| 202 | 
            -
                      %(#{@caption.chomp '. '}, #{quoted_title})
         | 
| 203 | 
            -
                    end
         | 
| 204 | 
            -
                  when 'short'
         | 
| 205 | 
            -
                    if @number && (prefix = @document.attributes[@context == :image ? 'figure-caption' : %(#{@context}-caption)])
         | 
| 206 | 
            -
                      %(#{prefix} #{@number})
         | 
| 207 | 
            -
                    else
         | 
| 208 | 
            -
                      @caption.chomp '. '
         | 
| 209 | 
            -
                    end
         | 
| 210 | 
            -
                  else # 'basic'
         | 
| 211 | 
            -
                    title
         | 
| 212 | 
            -
                  end
         | 
| 213 | 
            -
                else
         | 
| 214 | 
            -
                  title
         | 
| 215 | 
            -
                end
         | 
| 216 | 
            -
              end
         | 
| 217 | 
            -
             | 
| 218 | 
            -
              # Public: Determine whether this Block contains block content
         | 
| 87 | 
            +
              # context - the context Symbol context to assign to this block
         | 
| 219 88 | 
             
              #
         | 
| 220 | 
            -
              # Returns  | 
| 221 | 
            -
              def  | 
| 222 | 
            -
                 | 
| 89 | 
            +
              # Returns the new context Symbol assigned to this block
         | 
| 90 | 
            +
              def context= context
         | 
| 91 | 
            +
                @node_name = (@context = context).to_s
         | 
| 223 92 | 
             
              end
         | 
| 224 93 |  | 
| 225 94 | 
             
              # Public: Append a content block to this block's list of blocks.
         | 
| @@ -239,8 +108,7 @@ class AbstractBlock < AbstractNode | |
| 239 108 | 
             
              #
         | 
| 240 109 | 
             
              # Returns The parent Block
         | 
| 241 110 | 
             
              def << block
         | 
| 242 | 
            -
                 | 
| 243 | 
            -
                #block.parent = self
         | 
| 111 | 
            +
                block.parent = self unless block.parent == self
         | 
| 244 112 | 
             
                @blocks << block
         | 
| 245 113 | 
             
                self
         | 
| 246 114 | 
             
              end
         | 
| @@ -248,30 +116,11 @@ class AbstractBlock < AbstractNode | |
| 248 116 | 
             
              # NOTE append alias required for adapting to a Java API
         | 
| 249 117 | 
             
              alias append <<
         | 
| 250 118 |  | 
| 251 | 
            -
              # Public:  | 
| 252 | 
            -
              #
         | 
| 253 | 
            -
              # Only applies to Document and Section instances
         | 
| 254 | 
            -
              #
         | 
| 255 | 
            -
              # Examples
         | 
| 256 | 
            -
              #
         | 
| 257 | 
            -
              #   doc << (sect1 = Section.new doc, 1, false)
         | 
| 258 | 
            -
              #   sect1.title = 'Section 1'
         | 
| 259 | 
            -
              #   para1 = Block.new sect1, :paragraph, :source => 'Paragraph 1'
         | 
| 260 | 
            -
              #   para2 = Block.new sect1, :paragraph, :source => 'Paragraph 2'
         | 
| 261 | 
            -
              #   sect1 << para1 << para2
         | 
| 262 | 
            -
              #   sect1 << (sect1_1 = Section.new sect1, 2, false)
         | 
| 263 | 
            -
              #   sect1_1.title = 'Section 1.1'
         | 
| 264 | 
            -
              #   sect1_1 << (Block.new sect1_1, :paragraph, :source => 'Paragraph 3')
         | 
| 265 | 
            -
              #   sect1.blocks?
         | 
| 266 | 
            -
              #   # => true
         | 
| 267 | 
            -
              #   sect1.blocks.size
         | 
| 268 | 
            -
              #   # => 3
         | 
| 269 | 
            -
              #   sect1.sections.size
         | 
| 270 | 
            -
              #   # => 1
         | 
| 119 | 
            +
              # Public: Determine whether this Block contains block content
         | 
| 271 120 | 
             
              #
         | 
| 272 | 
            -
              # Returns  | 
| 273 | 
            -
              def  | 
| 274 | 
            -
                 | 
| 121 | 
            +
              # Returns A Boolean indicating whether this Block has block content
         | 
| 122 | 
            +
              def blocks?
         | 
| 123 | 
            +
                !@blocks.empty?
         | 
| 275 124 | 
             
              end
         | 
| 276 125 |  | 
| 277 126 | 
             
              # Public: Check whether this block has any child Section objects.
         | 
| @@ -283,37 +132,6 @@ class AbstractBlock < AbstractNode | |
| 283 132 | 
             
                @next_section_index > 0
         | 
| 284 133 | 
             
              end
         | 
| 285 134 |  | 
| 286 | 
            -
            # stage the Enumerable mixin until we're sure we've got it right
         | 
| 287 | 
            -
            =begin
         | 
| 288 | 
            -
              include ::Enumerable
         | 
| 289 | 
            -
             | 
| 290 | 
            -
              # Public: Yield the block on this block node and all its descendant
         | 
| 291 | 
            -
              # block node children to satisfy the Enumerable contract.
         | 
| 292 | 
            -
              #
         | 
| 293 | 
            -
              # Returns nothing
         | 
| 294 | 
            -
              def each &block
         | 
| 295 | 
            -
                # yucky, dlist is a special case
         | 
| 296 | 
            -
                if @context == :dlist
         | 
| 297 | 
            -
                  @blocks.flatten.each &block
         | 
| 298 | 
            -
                else
         | 
| 299 | 
            -
                  #yield self.header if @context == :document && header?
         | 
| 300 | 
            -
                  @blocks.each &block
         | 
| 301 | 
            -
                end
         | 
| 302 | 
            -
              end
         | 
| 303 | 
            -
             | 
| 304 | 
            -
              #--
         | 
| 305 | 
            -
              # TODO is there a way to make this lazy?
         | 
| 306 | 
            -
              def each_recursive &block
         | 
| 307 | 
            -
                block = lambda {|node| node } unless block_given?
         | 
| 308 | 
            -
                results = []
         | 
| 309 | 
            -
                self.each do |node|
         | 
| 310 | 
            -
                  results << block.call(node)
         | 
| 311 | 
            -
                  results.concat(node.each_recursive(&block)) if ::Enumerable === node
         | 
| 312 | 
            -
                end
         | 
| 313 | 
            -
                block_given? ? results : results.to_enum
         | 
| 314 | 
            -
              end
         | 
| 315 | 
            -
            =end
         | 
| 316 | 
            -
             | 
| 317 135 | 
             
              # Public: Query for all descendant block-level nodes in the document tree
         | 
| 318 136 | 
             
              # that match the specified selector (context, style, id, and/or role). If a
         | 
| 319 137 | 
             
              # Ruby block is given, it's used as an additional filter. If no selector or
         | 
| @@ -377,6 +195,7 @@ class AbstractBlock < AbstractNode | |
| 377 195 | 
             
                end
         | 
| 378 196 | 
             
                result
         | 
| 379 197 | 
             
              end
         | 
| 198 | 
            +
             | 
| 380 199 | 
             
              alias query find_by
         | 
| 381 200 |  | 
| 382 201 | 
             
              # Move to the next adjacent block in document order. If the current block is the last
         | 
| @@ -385,6 +204,126 @@ class AbstractBlock < AbstractNode | |
| 385 204 | 
             
                (sib = (p = parent).blocks[(p.blocks.find_index self) + 1]) ? sib : p.next_adjacent_block unless @context == :document
         | 
| 386 205 | 
             
              end
         | 
| 387 206 |  | 
| 207 | 
            +
              # Public: Get the Array of child Section objects
         | 
| 208 | 
            +
              #
         | 
| 209 | 
            +
              # Only applies to Document and Section instances
         | 
| 210 | 
            +
              #
         | 
| 211 | 
            +
              # Examples
         | 
| 212 | 
            +
              #
         | 
| 213 | 
            +
              #   doc << (sect1 = Section.new doc, 1)
         | 
| 214 | 
            +
              #   sect1.title = 'Section 1'
         | 
| 215 | 
            +
              #   para1 = Block.new sect1, :paragraph, :source => 'Paragraph 1'
         | 
| 216 | 
            +
              #   para2 = Block.new sect1, :paragraph, :source => 'Paragraph 2'
         | 
| 217 | 
            +
              #   sect1 << para1 << para2
         | 
| 218 | 
            +
              #   sect1 << (sect1_1 = Section.new sect1, 2)
         | 
| 219 | 
            +
              #   sect1_1.title = 'Section 1.1'
         | 
| 220 | 
            +
              #   sect1_1 << (Block.new sect1_1, :paragraph, :source => 'Paragraph 3')
         | 
| 221 | 
            +
              #   sect1.blocks?
         | 
| 222 | 
            +
              #   # => true
         | 
| 223 | 
            +
              #   sect1.blocks.size
         | 
| 224 | 
            +
              #   # => 3
         | 
| 225 | 
            +
              #   sect1.sections.size
         | 
| 226 | 
            +
              #   # => 1
         | 
| 227 | 
            +
              #
         | 
| 228 | 
            +
              # Returns an [Array] of Section objects
         | 
| 229 | 
            +
              def sections
         | 
| 230 | 
            +
                @blocks.select {|block| block.context == :section }
         | 
| 231 | 
            +
              end
         | 
| 232 | 
            +
             | 
| 233 | 
            +
              # Public: Returns the converted alt text for this block image.
         | 
| 234 | 
            +
              #
         | 
| 235 | 
            +
              # Returns the [String] value of the alt attribute with XML special character
         | 
| 236 | 
            +
              # and replacement substitutions applied.
         | 
| 237 | 
            +
              def alt
         | 
| 238 | 
            +
                if (text = @attributes['alt'])
         | 
| 239 | 
            +
                  if text == @attributes['default-alt']
         | 
| 240 | 
            +
                    sub_specialchars text
         | 
| 241 | 
            +
                  else
         | 
| 242 | 
            +
                    text = sub_specialchars text
         | 
| 243 | 
            +
                    (ReplaceableTextRx.match? text) ? (sub_replacements text) : text
         | 
| 244 | 
            +
                  end
         | 
| 245 | 
            +
                end
         | 
| 246 | 
            +
              end
         | 
| 247 | 
            +
             | 
| 248 | 
            +
              # Gets the caption for this block.
         | 
| 249 | 
            +
              #
         | 
| 250 | 
            +
              # This method routes the deprecated use of the caption method on an
         | 
| 251 | 
            +
              # admonition block to the textlabel attribute.
         | 
| 252 | 
            +
              #
         | 
| 253 | 
            +
              # Returns the [String] caption for this block (or the value of the textlabel
         | 
| 254 | 
            +
              # attribute if this is an admonition block).
         | 
| 255 | 
            +
              def caption
         | 
| 256 | 
            +
                @context == :admonition ? @attributes['textlabel'] : @caption
         | 
| 257 | 
            +
              end
         | 
| 258 | 
            +
             | 
| 259 | 
            +
              # Public: Convenience method that returns the interpreted title of the Block
         | 
| 260 | 
            +
              # with the caption prepended.
         | 
| 261 | 
            +
              #
         | 
| 262 | 
            +
              # Concatenates the value of this Block's caption instance variable and the
         | 
| 263 | 
            +
              # return value of this Block's title method. No space is added between the
         | 
| 264 | 
            +
              # two values. If the Block does not have a caption, the interpreted title is
         | 
| 265 | 
            +
              # returned.
         | 
| 266 | 
            +
              #
         | 
| 267 | 
            +
              # Returns the converted String title prefixed with the caption, or just the
         | 
| 268 | 
            +
              # converted String title if no caption is set
         | 
| 269 | 
            +
              def captioned_title
         | 
| 270 | 
            +
                %(#{@caption}#{title})
         | 
| 271 | 
            +
              end
         | 
| 272 | 
            +
             | 
| 273 | 
            +
              # Public: Retrieve the list marker keyword for the specified list type.
         | 
| 274 | 
            +
              #
         | 
| 275 | 
            +
              # For use in the HTML type attribute.
         | 
| 276 | 
            +
              #
         | 
| 277 | 
            +
              # list_type - the type of list; default to the @style if not specified
         | 
| 278 | 
            +
              #
         | 
| 279 | 
            +
              # Returns the single-character [String] keyword that represents the marker for the specified list type
         | 
| 280 | 
            +
              def list_marker_keyword list_type = nil
         | 
| 281 | 
            +
                ORDERED_LIST_KEYWORDS[list_type || @style]
         | 
| 282 | 
            +
              end
         | 
| 283 | 
            +
             | 
| 284 | 
            +
              # Public: Get the String title of this Block with title substitions applied
         | 
| 285 | 
            +
              #
         | 
| 286 | 
            +
              # The following substitutions are applied to block and section titles:
         | 
| 287 | 
            +
              #
         | 
| 288 | 
            +
              # :specialcharacters, :quotes, :replacements, :macros, :attributes and :post_replacements
         | 
| 289 | 
            +
              #
         | 
| 290 | 
            +
              # Examples
         | 
| 291 | 
            +
              #
         | 
| 292 | 
            +
              #   block.title = "Foo 3^ # {two-colons} Bar(1)"
         | 
| 293 | 
            +
              #   block.title
         | 
| 294 | 
            +
              #   => "Foo 3^ # :: Bar(1)"
         | 
| 295 | 
            +
              #
         | 
| 296 | 
            +
              # Returns the converted String title for this Block, or nil if the source title is falsy
         | 
| 297 | 
            +
              def title
         | 
| 298 | 
            +
                # prevent substitutions from being applied to title multiple times
         | 
| 299 | 
            +
                @title_converted ? @converted_title : (@converted_title = (@title_converted = true) && @title && (apply_title_subs @title))
         | 
| 300 | 
            +
              end
         | 
| 301 | 
            +
             | 
| 302 | 
            +
              # Public: A convenience method that checks whether the title of this block is defined.
         | 
| 303 | 
            +
              #
         | 
| 304 | 
            +
              # Returns a [Boolean] indicating whether this block has a title.
         | 
| 305 | 
            +
              def title?
         | 
| 306 | 
            +
                @title ? true : false
         | 
| 307 | 
            +
              end
         | 
| 308 | 
            +
             | 
| 309 | 
            +
              # Public: Set the String block title.
         | 
| 310 | 
            +
              #
         | 
| 311 | 
            +
              # Returns the new String title assigned to this Block
         | 
| 312 | 
            +
              def title= val
         | 
| 313 | 
            +
                @title, @title_converted = val, nil
         | 
| 314 | 
            +
              end
         | 
| 315 | 
            +
             | 
| 316 | 
            +
              # Public: A convenience method that checks whether the specified
         | 
| 317 | 
            +
              # substitution is enabled for this block.
         | 
| 318 | 
            +
              #
         | 
| 319 | 
            +
              # name - The Symbol substitution name
         | 
| 320 | 
            +
              #
         | 
| 321 | 
            +
              # Returns A Boolean indicating whether the specified substitution is
         | 
| 322 | 
            +
              # enabled for this block
         | 
| 323 | 
            +
              def sub? name
         | 
| 324 | 
            +
                @subs.include? name
         | 
| 325 | 
            +
              end
         | 
| 326 | 
            +
             | 
| 388 327 | 
             
              # Public: Remove a substitution from this block
         | 
| 389 328 | 
             
              #
         | 
| 390 329 | 
             
              # sub  - The Symbol substitution name
         | 
| @@ -395,6 +334,49 @@ class AbstractBlock < AbstractNode | |
| 395 334 | 
             
                nil
         | 
| 396 335 | 
             
              end
         | 
| 397 336 |  | 
| 337 | 
            +
              # Public: Generate cross reference text (xreftext) that can be used to refer
         | 
| 338 | 
            +
              # to this block.
         | 
| 339 | 
            +
              #
         | 
| 340 | 
            +
              # Use the explicit reftext for this block, if specified, retrieved from the
         | 
| 341 | 
            +
              # {#reftext} method. Otherwise, if this is a section or captioned block (a
         | 
| 342 | 
            +
              # block with both a title and caption), generate the xreftext according to
         | 
| 343 | 
            +
              # the value of the xrefstyle argument (e.g., full, short). This logic may
         | 
| 344 | 
            +
              # leverage the {Substitutors#sub_quotes} method to apply formatting to the
         | 
| 345 | 
            +
              # text. If this is not a captioned block, return the title, if present, or
         | 
| 346 | 
            +
              # nil otherwise.
         | 
| 347 | 
            +
              #
         | 
| 348 | 
            +
              # xrefstyle - An optional String that specifies the style to use to format
         | 
| 349 | 
            +
              #             the xreftext ('full', 'short', or 'basic') (default: nil).
         | 
| 350 | 
            +
              #
         | 
| 351 | 
            +
              # Returns the generated [String] xreftext used to refer to this block or
         | 
| 352 | 
            +
              # nothing if there isn't sufficient information to generate one.
         | 
| 353 | 
            +
              def xreftext xrefstyle = nil
         | 
| 354 | 
            +
                if (val = reftext) && !val.empty?
         | 
| 355 | 
            +
                  val
         | 
| 356 | 
            +
                # NOTE xrefstyle only applies to blocks with a title and a caption or number
         | 
| 357 | 
            +
                elsif xrefstyle && @title && @caption
         | 
| 358 | 
            +
                  case xrefstyle
         | 
| 359 | 
            +
                  when 'full'
         | 
| 360 | 
            +
                    quoted_title = sprintf sub_quotes(@document.compat_mode ? %q(``%s'') : '"`%s`"'), title
         | 
| 361 | 
            +
                    if @number && (prefix = @document.attributes[@context == :image ? 'figure-caption' : %(#{@context}-caption)])
         | 
| 362 | 
            +
                      %(#{prefix} #{@number}, #{quoted_title})
         | 
| 363 | 
            +
                    else
         | 
| 364 | 
            +
                      %(#{@caption.chomp '. '}, #{quoted_title})
         | 
| 365 | 
            +
                    end
         | 
| 366 | 
            +
                  when 'short'
         | 
| 367 | 
            +
                    if @number && (prefix = @document.attributes[@context == :image ? 'figure-caption' : %(#{@context}-caption)])
         | 
| 368 | 
            +
                      %(#{prefix} #{@number})
         | 
| 369 | 
            +
                    else
         | 
| 370 | 
            +
                      @caption.chomp '. '
         | 
| 371 | 
            +
                    end
         | 
| 372 | 
            +
                  else # 'basic'
         | 
| 373 | 
            +
                    title
         | 
| 374 | 
            +
                  end
         | 
| 375 | 
            +
                else
         | 
| 376 | 
            +
                  title
         | 
| 377 | 
            +
                end
         | 
| 378 | 
            +
              end
         | 
| 379 | 
            +
             | 
| 398 380 | 
             
              # Public: Generate and assign caption to block if not already assigned.
         | 
| 399 381 | 
             
              #
         | 
| 400 382 | 
             
              # If the block has a title and a caption prefix is available for this block,
         | 
| @@ -421,41 +403,36 @@ class AbstractBlock < AbstractNode | |
| 421 403 | 
             
                end
         | 
| 422 404 | 
             
              end
         | 
| 423 405 |  | 
| 424 | 
            -
              # Internal: Assign the next index (0-based) and  | 
| 406 | 
            +
              # Internal: Assign the next index (0-based) and numeral (1-based) to the section.
         | 
| 407 | 
            +
              # If the section is an appendix, the numeral is a letter (starting with A). This
         | 
| 408 | 
            +
              # method also assigns the appendix caption.
         | 
| 409 | 
            +
              #
         | 
| 410 | 
            +
              # section - The section to which to assign the next index and numeral.
         | 
| 425 411 | 
             
              #
         | 
| 426 412 | 
             
              # Assign to the specified section the next index and, if the section is
         | 
| 427 | 
            -
              # numbered,  | 
| 413 | 
            +
              # numbered, the numeral within this block (its parent).
         | 
| 428 414 | 
             
              #
         | 
| 429 415 | 
             
              # Returns nothing
         | 
| 430 | 
            -
              def  | 
| 416 | 
            +
              def assign_numeral section
         | 
| 431 417 | 
             
                @next_section_index = (section.index = @next_section_index) + 1
         | 
| 432 | 
            -
                if ( | 
| 433 | 
            -
                   | 
| 434 | 
            -
             | 
| 435 | 
            -
                     | 
| 418 | 
            +
                if (like = section.numbered)
         | 
| 419 | 
            +
                  if (sectname = section.sectname) == 'appendix'
         | 
| 420 | 
            +
                    section.number = @document.counter 'appendix-number', 'A'
         | 
| 421 | 
            +
                    if (caption = @document.attributes['appendix-caption'])
         | 
| 422 | 
            +
                      section.caption = %(#{caption} #{section.number}: )
         | 
| 423 | 
            +
                    else
         | 
| 424 | 
            +
                      section.caption = %(#{section.number}. )
         | 
| 425 | 
            +
                    end
         | 
| 426 | 
            +
                  # NOTE currently chapters in a book doctype are sequential even for multi-part books (see #979)
         | 
| 427 | 
            +
                  elsif sectname == 'chapter' || like == :chapter
         | 
| 428 | 
            +
                    section.number = @document.counter 'chapter-number', 1
         | 
| 436 429 | 
             
                  else
         | 
| 437 | 
            -
                     | 
| 430 | 
            +
                    @next_section_number = (section.number = @next_section_number) + 1
         | 
| 438 431 | 
             
                  end
         | 
| 439 | 
            -
                 | 
| 440 | 
            -
                elsif sectname == 'chapter'
         | 
| 441 | 
            -
                  section.number = @document.counter 'chapter-number', 1
         | 
| 442 | 
            -
                else
         | 
| 443 | 
            -
                  @next_section_number = (section.number = @next_section_number) + 1
         | 
| 444 | 
            -
                end if section.numbered
         | 
| 432 | 
            +
                end
         | 
| 445 433 | 
             
                nil
         | 
| 446 434 | 
             
              end
         | 
| 447 435 |  | 
| 448 | 
            -
              # Public: Retrieve the list marker keyword for the specified list type.
         | 
| 449 | 
            -
              #
         | 
| 450 | 
            -
              # For use in the HTML type attribute.
         | 
| 451 | 
            -
              #
         | 
| 452 | 
            -
              # list_type - the type of list; default to the @style if not specified
         | 
| 453 | 
            -
              #
         | 
| 454 | 
            -
              # Returns the single-character [String] keyword that represents the marker for the specified list type
         | 
| 455 | 
            -
              def list_marker_keyword list_type = nil
         | 
| 456 | 
            -
                ORDERED_LIST_KEYWORDS[list_type || @style]
         | 
| 457 | 
            -
              end
         | 
| 458 | 
            -
             | 
| 459 436 | 
             
              # Internal: Reassign the section indexes
         | 
| 460 437 | 
             
              #
         | 
| 461 438 | 
             
              # Walk the descendents of the current Document or Section
         | 
| @@ -471,10 +448,41 @@ class AbstractBlock < AbstractNode | |
| 471 448 | 
             
                @next_section_number = 1
         | 
| 472 449 | 
             
                @blocks.each do |block|
         | 
| 473 450 | 
             
                  if block.context == :section
         | 
| 474 | 
            -
                     | 
| 451 | 
            +
                    assign_numeral block
         | 
| 475 452 | 
             
                    block.reindex_sections
         | 
| 476 453 | 
             
                  end
         | 
| 477 454 | 
             
                end
         | 
| 478 455 | 
             
              end
         | 
| 456 | 
            +
             | 
| 457 | 
            +
            # stage the Enumerable mixin until we're sure we've got it right
         | 
| 458 | 
            +
            =begin
         | 
| 459 | 
            +
              include ::Enumerable
         | 
| 460 | 
            +
             | 
| 461 | 
            +
              # Public: Yield the block on this block node and all its descendant
         | 
| 462 | 
            +
              # block node children to satisfy the Enumerable contract.
         | 
| 463 | 
            +
              #
         | 
| 464 | 
            +
              # Returns nothing
         | 
| 465 | 
            +
              def each &block
         | 
| 466 | 
            +
                # yucky, dlist is a special case
         | 
| 467 | 
            +
                if @context == :dlist
         | 
| 468 | 
            +
                  @blocks.flatten.each &block
         | 
| 469 | 
            +
                else
         | 
| 470 | 
            +
                  #yield self.header if @context == :document && header?
         | 
| 471 | 
            +
                  @blocks.each &block
         | 
| 472 | 
            +
                end
         | 
| 473 | 
            +
              end
         | 
| 474 | 
            +
             | 
| 475 | 
            +
              #--
         | 
| 476 | 
            +
              # TODO is there a way to make this lazy?
         | 
| 477 | 
            +
              def each_recursive &block
         | 
| 478 | 
            +
                block = lambda {|node| node } unless block_given?
         | 
| 479 | 
            +
                results = []
         | 
| 480 | 
            +
                self.each do |node|
         | 
| 481 | 
            +
                  results << block.call(node)
         | 
| 482 | 
            +
                  results.concat(node.each_recursive(&block)) if ::Enumerable === node
         | 
| 483 | 
            +
                end
         | 
| 484 | 
            +
                block_given? ? results : results.to_enum
         | 
| 485 | 
            +
              end
         | 
| 486 | 
            +
            =end
         | 
| 479 487 | 
             
            end
         | 
| 480 488 | 
             
            end
         |