Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#38 list continuations #126

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/coradoc/element/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ module Block
require_relative "block/core"
require_relative "block/example"
require_relative "block/literal"
require_relative "block/quote"
require_relative "block/listing"
require_relative "block/open"
require_relative "block/pass"
require_relative "block/quote"
require_relative "block/side"
require_relative "block/sourcecode"
require_relative "block/reviewer_comment"
7 changes: 4 additions & 3 deletions lib/coradoc/element/block/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ def type_from_delimiter

def type_hash
@type_hash ||= {
"____" => :quote,
"****" => :side,
"----" => :source,
"====" => :example,
"...." => :literal,
"--" => :open,
"++++" => :pass,
"____" => :quote,
"****" => :side,
"----" => :source,
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/coradoc/element/block/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(title, options = {})
end

def to_adoc
"\n\n#{gen_anchor}#{gen_title}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
"\n\n#{gen_anchor}#{gen_title}#{gen_attributes}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions lib/coradoc/element/block/listing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Coradoc
module Element
module Block
class Listing < Core
def initialize(_title, options = {})
@id = options.fetch(:id, nil)
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
@lang = options.fetch(:lang, "")
@attributes = options.fetch(:attributes, AttributeList.new)
@lines = options.fetch(:lines, [])
@delimiter_char = "-"
@delimiter_len = options.fetch(:delimiter_len, 4)
end

def to_adoc
"\n\n#{gen_anchor}#{gen_attributes}\n#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
end
end
end
end
end
6 changes: 4 additions & 2 deletions lib/coradoc/element/block/literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ module Coradoc
module Element
module Block
class Literal < Core
def initialize(_title, options = {})
def initialize(title, options = {})
@title = title
@id = options.fetch(:id, nil)
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
@attributes = options.fetch(:attributes, AttributeList.new)
@lines = options.fetch(:lines, [])
@delimiter_char = "."
@delimiter_len = options.fetch(:delimiter_len, 4)
end

def to_adoc
"\n\n#{gen_anchor}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
"\n\n#{gen_anchor}#{gen_title}#{gen_attributes}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
end
end
end
Expand Down
22 changes: 22 additions & 0 deletions lib/coradoc/element/block/open.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Coradoc
module Element
module Block
class Open < Core
def initialize(title, options = {})
@title = title
@id = options.fetch(:id, nil)
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
@lang = options.fetch(:lang, "")
@attributes = options.fetch(:attributes, AttributeList.new)
@lines = options.fetch(:lines, [])
@delimiter_char = "-"
@delimiter_len = options.fetch(:delimiter_len, 2)
end

def to_adoc
"\n\n#{gen_anchor}#{gen_attributes}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/coradoc/element/list/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def initialize(items, options = {})
m = @items.select do |i|
i.is_a?(Coradoc::Element::ListItem) &&
!i.marker.nil?
end.first&.marker
@ol_count = m.size if m.is_a?(String)
end.first&.marker.to_s
@ol_count = m.size
end
@ol_count = 1 if @ol_count.nil?
@attrs = options.fetch(:attrs, AttributeList.new)
Expand Down
1 change: 1 addition & 0 deletions lib/coradoc/element/list/ordered.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def initialize(items, options = {})
end

def prefix
return @marker if @marker
"." * [@ol_count, 1].max
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/coradoc/element/list/unordered.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def initialize(items, options = {})
end

def prefix
return @marker if @marker
"*" * [@ol_count, 1].max
end
end
Expand Down
18 changes: 13 additions & 5 deletions lib/coradoc/element/list_item.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Coradoc
module Element
class ListItem < Base
attr_accessor :marker, :id, :anchor, :content, :line_break
attr_accessor :marker, :id, :anchor, :content, :subitem, :line_break

declare_children :content, :id, :anchor

Expand All @@ -10,11 +10,14 @@ def initialize(content, options = {})
@id = options.fetch(:id, nil)
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
@content = content
@attached = options.fetch(:attached, [])
@nested = options.fetch(:nested, nil)
@line_break = options.fetch(:line_break, "\n")
end

def to_adoc
anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
anchor = @anchor.nil? ? "" : " #{@anchor.to_adoc.to_s} "
# text = Coradoc::Generator.gen_adoc(@content)
content = Array(@content).map do |subitem|
next if subitem.is_a? Inline::HardLineBreak

Expand All @@ -24,10 +27,15 @@ def to_adoc
if Coradoc.a_single?(subitem, Coradoc::Element::TextElement)
subcontent = Coradoc.strip_unicode(subcontent)
end
subcontent.chomp
subcontent
end.compact.join("\n+\n")

" #{anchor}#{content.chomp}#{@line_break}"
# attach = Coradoc::Generator.gen_adoc(@attached)
attach = @attached.map do |elem|
"+\n" + Coradoc::Generator.gen_adoc(elem)
end.join
nest = Coradoc::Generator.gen_adoc(@nested)
out = " #{anchor}#{content}#{@line_break}"
out + attach + nest
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/coradoc/element/text_element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def inspect
str += "(#{@id})" if @id
str += ": "
str += @content.inspect
str += " + #{@line_break.inspect}" unless line_break.empty?
str += " + #{@line_break.inspect}" unless line_break.to_s.empty?
str
end

Expand Down
8 changes: 7 additions & 1 deletion lib/coradoc/parser/asciidoc/attribute_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ def named_attribute_value
match('[^\],]').repeat(1)
end

def named_key
(str('reviewer') |
match('[a-zA-Z0-9_-]').repeat(1)).as(:named_key)
end

def named_attribute
(match('[a-zA-Z0-9_-]').repeat(1).as(:named_key) >>
( named_key >>
str(' ').maybe >> str("=") >> str(' ').maybe >>
match['a-zA-Z0-9_\- \"'].repeat(1).as(:named_value) >>
str(' ').maybe
Expand Down Expand Up @@ -51,6 +56,7 @@ def positional_zero_or_one
end

def attribute_list(name = :attribute_list)
str('[').present? >>
str('[') >> str("[").absent? >>
( named_many |
positional_one_named_many |
Expand Down
Loading
Loading