Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

gemspec

gem 'pry'
44 changes: 44 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
PATH
remote: .
specs:
html2confluence (1.3.21)
nokogiri

GEM
remote: https://rubygems.org/
specs:
coderay (1.1.1)
diff-lcs (1.3)
method_source (0.8.2)
mini_portile2 (2.1.0)
nokogiri (1.7.2)
mini_portile2 (~> 2.1.0)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
slop (3.6.0)

PLATFORMS
ruby

DEPENDENCIES
html2confluence!
pry
rspec

BUNDLED WITH
1.13.7
3 changes: 2 additions & 1 deletion html2confluence.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Gem::Specification.new do |s|

s.require_path = 'lib'
s.files = Dir.glob("{lib,spec}/**/*") + %w(example.rb README.mdown)

s.add_dependency "nokogiri"
s.add_development_dependency "rspec"
end
20 changes: 13 additions & 7 deletions lib/html2confluence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def make_quicktag_start_pair(tag, wrapchar, attributes)

def make_quicktag_end_pair(wrapchar)
content = stop_capture

# Don't make quicktags with empty content.
if content.join("").strip.empty?
write(content)
Expand All @@ -87,7 +86,7 @@ def make_quicktag_end_pair(wrapchar)
end
write(["#{wrapchar}"])
end
write(content.collect(&:strip))
write(content)
write([wrapchar]) unless @skip_quicktag
unless in_nested_quicktag?
#write([" "])
Expand Down Expand Up @@ -443,16 +442,15 @@ def preprocess(data)

# Return the textile after processing
def to_wiki_markup
fix_textile_whitespace!(result.join).gsub(/\n(\*|#)+\s*\n(\*|#)+/) do |match|
"\n#{match.split("\n").last.squeeze(' ')}"
end
fix_textile_whitespace!(result.join)
end

def fix_textile_whitespace!(output)
# fixes multiple blank lines, blockquote indicator followed by blank lines, and trailing whitespace after quicktags
# modifies input string and also returns it
# fixes multiple blank lines
output.gsub!(/(\n\s*){2,}/,"\n\n")
# fixes blockquote indicator followed by blank lines
output.gsub!(/bq. \n+(\w)/,'bq. \1')
# fixes trailing whitespace after quicktags
QUICKTAGS.values.uniq.each do |t|
output.gsub!(/ #{Regexp.escape(t)}[ \t]+#{Regexp.escape(t)} /,' ') # removes empty quicktags
#output.gsub!(/(\[?#{Regexp.escape(t)})(\w+)([^#{Regexp.escape(t)}]+)(\s+)(#{Regexp.escape(t)}\]?)/,'\1\2\3\5\4') # fixes trailing whitespace before closing quicktags
Expand All @@ -461,6 +459,14 @@ def fix_textile_whitespace!(output)
#output.gsub!(/^[ \t]/,'') # leading whitespace
#output.gsub!(/[ \t]$/,'') # trailing whitespace
output.strip!
# fixes extra bullets generated when nesting list items
output.gsub!(/\n([\*|#]+)\s*\n([\*|#]+)/) do |match|
if $1 == $2
match
else
"\n#{match.split("\n").last}"
end.squeeze(' ')
end
return output
end

Expand Down
Loading