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

Place a space between certain character class letters only #1057

Merged
merged 1 commit into from
Nov 27, 2023
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
2 changes: 1 addition & 1 deletion lib/rdoc/markup/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def build_paragraph margin

break if peek_token.first == :BREAK

data << ' ' if skip :NEWLINE
data << ' ' if skip :NEWLINE and /#{SPACE_SEPARATED_LETTER_CLASS}\z/o.match?(data)
else
unget
break
Expand Down
4 changes: 3 additions & 1 deletion lib/rdoc/markup/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ def accept_block_quote block_quote
def accept_paragraph paragraph
@res << "\n<p>"
text = paragraph.text @hard_break
text = text.gsub(/\r?\n/, ' ')
text = text.gsub(/(#{SPACE_SEPARATED_LETTER_CLASS})?\K\r?\n(?=(?(1)(#{SPACE_SEPARATED_LETTER_CLASS})?))/o) {
defined?($2) && ' '
}
@res << to_html(text)
@res << "</p>\n"
end
Expand Down
6 changes: 6 additions & 0 deletions lib/rdoc/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,10 @@ def wrap(txt, line_len = 76)
res.join.strip
end

##
# Character class to be separated by a space when concatenating
# lines.

SPACE_SEPARATED_LETTER_CLASS = /[\p{Nd}\p{Lc}\p{Pc}]/

end
28 changes: 24 additions & 4 deletions test/rdoc/test_rdoc_markup_to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def accept_paragraph_br
end

def accept_paragraph_break
assert_equal "\n<p>hello<br> world</p>\n", @to.res.join
assert_equal "\n<p>hello<br>world</p>\n", @to.res.join
end

def accept_paragraph_i
Expand Down Expand Up @@ -391,11 +391,31 @@ def test_accept_heading_pipe
end

def test_accept_paragraph_newline
@to.start_accepting
hellos = ["hello", "\u{393 3b5 3b9 3ac} \u{3c3 3bf 3c5}"]
worlds = ["world", "\u{3ba 3cc 3c3 3bc 3bf 3c2}"]
ohayo, sekai = %W"\u{304a 306f 3088 3046} \u{4e16 754c}"

hellos.product(worlds) do |hello, world|
@to.start_accepting
@to.accept_paragraph para("#{hello}\n", "#{world}\n")
assert_equal "\n<p>#{hello} #{world}</p>\n", @to.res.join
end

hellos.each do |hello|
@to.start_accepting
@to.accept_paragraph para("#{hello}\n", "#{sekai}\n")
assert_equal "\n<p>#{hello}#{sekai}</p>\n", @to.res.join
end

@to.accept_paragraph para("hello\n", "world\n")
worlds.each do |world|
@to.start_accepting
@to.accept_paragraph para("#{ohayo}\n", "#{world}\n")
assert_equal "\n<p>#{ohayo}#{world}</p>\n", @to.res.join
end

assert_equal "\n<p>hello world </p>\n", @to.res.join
@to.start_accepting
@to.accept_paragraph para("#{ohayo}\n", "#{sekai}\n")
assert_equal "\n<p>#{ohayo}#{sekai}</p>\n", @to.res.join
end

def test_accept_heading_output_decoration
Expand Down