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

段落ブロックの末尾空行を取ってから段落生成 #883

Merged
merged 4 commits into from
Dec 12, 2017
Merged
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
11 changes: 10 additions & 1 deletion lib/review/textutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ def detab(str, ts = 8)
def split_paragraph(lines)
pre = pre_paragraph
post = post_paragraph
trimmed_lines = trim_lines(lines)

blocked_lines = [[]]
lines.each do |element|
trimmed_lines.each do |element|
if element.empty?
blocked_lines << [] if blocked_lines.last != []
else
Expand All @@ -28,5 +29,13 @@ def split_paragraph(lines)
blocked_lines.map! { |i| [pre] + i + [post] } if pre && post
blocked_lines.map(&:join)
end

private

def trim_lines(lines)
new_lines = lines.dup
new_lines.pop while new_lines[-1] && new_lines[-1].strip.empty?
new_lines
end
end
end
2 changes: 2 additions & 0 deletions test/test_textutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def test_split_paragraph_p
assert_equal ['<p>abc</p>', '<p>def</p>'], ret
ret = @tu_p.split_paragraph(['abc', '', '', 'def', 'ghi'])
assert_equal ['<p>abc</p>', '<p>defghi</p>'], ret
ret = @tu_p.split_paragraph(['abc', '', '', 'def', 'ghi', '', ''])
assert_equal ['<p>abc</p>', '<p>defghi</p>'], ret
end

def test_split_paragraph_nil
Expand Down
2 changes: 1 addition & 1 deletion test/test_topbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_inline_in_table

def test_dlist_beforeulol
actual = compile_block(" : foo\n foo.\n\npara\n\n : foo\n foo.\n\n 1. bar\n\n : foo\n foo.\n\n * bar\n")
assert_equal %Q(★foo☆\n\tfoo.\n\t\n\npara\n\n★foo☆\n\tfoo.\n\t\n\n1\tbar\n\n★foo☆\n\tfoo.\n\t\n\n●\tbar\n\n), actual
assert_equal %Q(★foo☆\n\tfoo.\n\npara\n\n★foo☆\n\tfoo.\n\n1\tbar\n\n★foo☆\n\tfoo.\n\n●\tbar\n\n), actual
end

def test_paragraph
Expand Down