Skip to content

Commit

Permalink
encapsulate assignment of prologue and attributes on writer
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Aug 19, 2018
1 parent 699b980 commit 06c1721
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/kramdown-asciidoc/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def convert_root el, opts
if (fallback_doctitle = @attributes.delete 'title')
writer.doctitle ||= fallback_doctitle
end
writer.attributes.update @attributes unless @attributes.empty?
writer.add_attributes @attributes unless @attributes.empty?
result = writer.to_s.gsub TrailingSpaceRx, ''
# QUESTION should we add a preprocessor step to clean the source?
result = result.tr NBSP, ' ' if result.include? NBSP
Expand Down Expand Up @@ -191,7 +191,7 @@ def convert_heading el, opts
# NOTE kramdown has already removed newlines
title = compose_text el, strip: true
if level == 1 && writer.empty? && @current_heading_level != 1
writer.prologue << attrlist if attrlist
writer.add_prologue_line attrlist if attrlist
writer.doctitle = title
nil
else
Expand Down Expand Up @@ -653,7 +653,7 @@ def extract_prologue el, opts
(prologue_el = el.dup).children = children.take_while {|child| child.type == :xml_comment || child.type == :blank }
(el = el.dup).children = children.drop prologue_el.children.size
traverse prologue_el, (opts.merge writer: (prologue_writer = Writer.new))
opts[:writer].prologue.push(*prologue_writer.body)
opts[:writer].add_prologue_lines prologue_writer.body
end
el
end
Expand Down
14 changes: 12 additions & 2 deletions lib/kramdown-asciidoc/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ module Kramdown; module AsciiDoc
class Writer
LF = ?\n

attr_reader :prologue
attr_accessor :doctitle
attr_reader :attributes
attr_reader :body

def initialize
Expand All @@ -18,6 +16,18 @@ def initialize
@list_level = { list: 0, dlist: 0 }
end

def add_attributes new_attributes
@attributes.update new_attributes
end

def add_prologue_line line
@prologue << line
end

def add_prologue_lines lines
@prologue.push(*lines)
end

def start_block
@body << @block_separator[-1] unless empty?
nil
Expand Down

0 comments on commit 06c1721

Please sign in to comment.