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

resolves #55 sort attribute entries in document header #63

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
encapsulate assignment of prologue and attributes on writer
  • Loading branch information
mojavelinux committed Aug 19, 2018
commit 06c1721b5261f38c44db3fb534f6b614f2d1d859
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