Sha256: 05ba7e4a6c4d31c165bc8d908685046697cb740a2a9cfb60387edc297c2e5752

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

module Coradoc
  module Parser
    module Asciidoc
      module Section

        def contents
          (
            citation |
            term | term2 |
            bib_entry |
            block_image |
            tag |
            comment_block |
            comment_line |
            include_directive |
            admonition_line |
            block.as(:block) |
            table.as(:table) |
            highlight.as(:highlight) |
            glossaries.as(:glossaries) |
            paragraph |
            list |
            empty_line.as(:line_break)
          ).repeat(1)
        end

        def section_block(level = 2)
          return nil if level > 8
          (attribute_list >> newline).maybe >>
          section_id.maybe >>
          (attribute_list >> newline).maybe >>
            section_title(level).as(:title) >>
            contents.as(:contents).maybe
        end

        # Section id
        def section_id
          (str("[[") >> keyword.as(:id) >> str("]]") |
            str("[#") >> keyword.as(:id) >> str("]")) >> newline
        end

        # Heading
        def section_title(level = 2, max_level = 8)
          match("=").repeat(level, max_level).as(:level) >>
            str('=').absent? >>
            space? >> text.as(:text) >> endline.as(:line_break)
        end

        # section
        def section(level = 2)
          r = section_block(level) 
          if level < 8
            r = r >> section(level + 1).as(:section).repeat(0).as(:sections)
          end
          if level == 2
            (r).as(:section)
          else
            r
          end
        end

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coradoc-1.1.3 lib/coradoc/parser/asciidoc/section.rb
coradoc-1.1.2 lib/coradoc/parser/asciidoc/section.rb
coradoc-1.1.1 lib/coradoc/parser/asciidoc/section.rb