diff --git a/lib/coradoc/document.rb b/lib/coradoc/document.rb index 1238538..917f8df 100644 --- a/lib/coradoc/document.rb +++ b/lib/coradoc/document.rb @@ -17,6 +17,7 @@ require_relative "element/document_attributes" require_relative "element/paragraph" require_relative "element/table" +require_relative "element/tag" require_relative "element/list" require_relative "element/inline" require_relative "element/image" diff --git a/lib/coradoc/element/tag.rb b/lib/coradoc/element/tag.rb new file mode 100644 index 0000000..4a88100 --- /dev/null +++ b/lib/coradoc/element/tag.rb @@ -0,0 +1,19 @@ +module Coradoc + module Element + class Tag < Base + attr_accessor :name + + def initialize(tag_name, options = {}) + @tag_name = tag_name + @prefix = options.fetch(:prefix, "tag") + @attrs = options.fetch(:attribute_list, nil) + @line_break = options.fetch(:line_break, "\n") + end + + def to_adoc + attrs = @attrs.to_adoc + "// #{@prefix}::#{@tag_name}#{attrs}#{@line_break}" + end + end + end +end diff --git a/lib/coradoc/element/text_element.rb b/lib/coradoc/element/text_element.rb index 8b8490d..a27b361 100644 --- a/lib/coradoc/element/text_element.rb +++ b/lib/coradoc/element/text_element.rb @@ -68,6 +68,10 @@ class LineBreak < Base def initialize(line_break) @line_break = line_break end + + def to_adoc + @line_break + end end class Highlight < Element::TextElement diff --git a/lib/coradoc/parser/asciidoc/base.rb b/lib/coradoc/parser/asciidoc/base.rb index c88ff93..a75ca84 100644 --- a/lib/coradoc/parser/asciidoc/base.rb +++ b/lib/coradoc/parser/asciidoc/base.rb @@ -147,6 +147,16 @@ def comment_line ).as(:comment_line) end + def tag + (str('//') >> str("/").absent? >> + space? >> + (str('tag') | str('end')).as(:prefix) >> + str('::') >> + text.as(:text) >> + attribute_list + ).as(:tag) + end + def comment_block ( str('////') >> line_ending >> ((line_ending >> str('////')).absent? >> any diff --git a/lib/coradoc/parser/asciidoc/section.rb b/lib/coradoc/parser/asciidoc/section.rb index e5ece0d..8f3c5fb 100644 --- a/lib/coradoc/parser/asciidoc/section.rb +++ b/lib/coradoc/parser/asciidoc/section.rb @@ -9,6 +9,7 @@ def contents term | term2 | bib_entry | block_image | + tag | comment_block | comment_line | include_directive | @@ -19,7 +20,7 @@ def contents glossaries.as(:glossaries) | paragraph | list | - empty_line + empty_line.as(:line_break) ).repeat(1) end diff --git a/lib/coradoc/parser/base.rb b/lib/coradoc/parser/base.rb index 55709db..6bbe4a6 100644 --- a/lib/coradoc/parser/base.rb +++ b/lib/coradoc/parser/base.rb @@ -40,6 +40,7 @@ class Base < Parslet::Parser block_image | term | term2 | citation | + tag | comment_block | comment_line | block.as(:block) | diff --git a/lib/coradoc/transformer.rb b/lib/coradoc/transformer.rb index c7471ac..008dcb3 100644 --- a/lib/coradoc/transformer.rb +++ b/lib/coradoc/transformer.rb @@ -36,6 +36,10 @@ class Transformer < Parslet::Transform Element::Comment::Block.new(comment_text) } + rule(tag: subtree(:tag)) { + Element::Tag.new(tag[:name]) + } + # AttributeList class NamedAttribute < Struct.new(:key, :value); end @@ -248,7 +252,6 @@ class NamedAttribute < Struct.new(:key, :value); end } rule(citation: subtree(:citation)){ - puts citation.inspect xref = citation[:cross_reference] xref = Element::Inline::CrossReference.new(xref[0], xref[1..-1]) if xref comment = citation[:comment] diff --git a/spec/coradoc/parser/asciidoc/content_spec.rb b/spec/coradoc/parser/asciidoc/content_spec.rb index 218f9c6..017fc82 100644 --- a/spec/coradoc/parser/asciidoc/content_spec.rb +++ b/spec/coradoc/parser/asciidoc/content_spec.rb @@ -154,7 +154,7 @@ ast = Asciidoc::ContentTester.parse(content) glossaries = ast.first[:glossaries] - lines = ast[1][:paragraph][:lines] + lines = ast[2][:paragraph][:lines] expect(glossaries[0][:key]).to eq("Clause") expect(glossaries[0][:value]).to eq("5.1") diff --git a/spec/coradoc/parser_spec.rb b/spec/coradoc/parser_spec.rb index 3dae1f7..2a85af5 100644 --- a/spec/coradoc/parser_spec.rb +++ b/spec/coradoc/parser_spec.rb @@ -38,7 +38,7 @@ expect(purpose_section[:contents][0][:paragraph]).not_to be_nil guidance = clause_5_1[:sections][2][:section] - expect(guidance[:contents].count).to eq(16) + expect(guidance[:contents].count).to eq(17) expect(guidance[:contents][0][:paragraph][:lines][0][:id]).to eq("guidance_5.1_part_1") expect(guidance[:contents][1][:paragraph][:lines][0][:id]).to eq("guidance_5.1_part_2")