Skip to content

Commit

Permalink
#32
Browse files Browse the repository at this point in the history
  • Loading branch information
xyz65535 committed Aug 30, 2024
1 parent deeaca9 commit 4a517b5
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/coradoc/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 19 additions & 0 deletions lib/coradoc/element/tag.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions lib/coradoc/element/text_element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lib/coradoc/parser/asciidoc/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/coradoc/parser/asciidoc/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def contents
term | term2 |
bib_entry |
block_image |
tag |
comment_block |
comment_line |
include_directive |
Expand All @@ -19,7 +20,7 @@ def contents
glossaries.as(:glossaries) |
paragraph |
list |
empty_line
empty_line.as(:line_break)
).repeat(1)
end

Expand Down
1 change: 1 addition & 0 deletions lib/coradoc/parser/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Base < Parslet::Parser
block_image |
term | term2 |
citation |
tag |
comment_block |
comment_line |
block.as(:block) |
Expand Down
5 changes: 4 additions & 1 deletion lib/coradoc/transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion spec/coradoc/parser/asciidoc/content_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion spec/coradoc/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 4a517b5

Please sign in to comment.