Skip to content

Commit 1f568e0

Browse files
committed
Place a space between certain character class letters only
1 parent ab4084b commit 1f568e0

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

lib/rdoc/markup/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def build_paragraph margin
218218

219219
break if peek_token.first == :BREAK
220220

221-
data << ' ' if skip :NEWLINE
221+
data << ' ' if skip :NEWLINE and /#{SPACE_SEPARATED_LETTER_CLASS}\z/o.match?(data)
222222
else
223223
unget
224224
break

lib/rdoc/markup/to_html.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ def accept_block_quote block_quote
202202
def accept_paragraph paragraph
203203
@res << "\n<p>"
204204
text = paragraph.text @hard_break
205-
text = text.gsub(/\r?\n/, ' ')
205+
text = text.gsub(/(#{SPACE_SEPARATED_LETTER_CLASS})?\K\r?\n(?=(?(1)(#{SPACE_SEPARATED_LETTER_CLASS})?))/o) {
206+
defined?($2) && ' '
207+
}
206208
@res << to_html(text)
207209
@res << "</p>\n"
208210
end

lib/rdoc/text.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,10 @@ def wrap(txt, line_len = 76)
309309
res.join.strip
310310
end
311311

312+
##
313+
# Character class to be separated by a space when concatenating
314+
# lines.
315+
316+
SPACE_SEPARATED_LETTER_CLASS = /[\p{Nd}\p{Lc}\p{Pc}]/
317+
312318
end

test/rdoc/test_rdoc_markup_to_html.rb

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def accept_paragraph_br
257257
end
258258

259259
def accept_paragraph_break
260-
assert_equal "\n<p>hello<br> world</p>\n", @to.res.join
260+
assert_equal "\n<p>hello<br>world</p>\n", @to.res.join
261261
end
262262

263263
def accept_paragraph_i
@@ -391,11 +391,31 @@ def test_accept_heading_pipe
391391
end
392392

393393
def test_accept_paragraph_newline
394-
@to.start_accepting
394+
hellos = ["hello", "\u{393 3b5 3b9 3ac} \u{3c3 3bf 3c5}"]
395+
worlds = ["world", "\u{3ba 3cc 3c3 3bc 3bf 3c2}"]
396+
ohayo, sekai = %W"\u{304a 306f 3088 3046} \u{4e16 754c}"
397+
398+
hellos.product(worlds) do |hello, world|
399+
@to.start_accepting
400+
@to.accept_paragraph para("#{hello}\n", "#{world}\n")
401+
assert_equal "\n<p>#{hello} #{world}</p>\n", @to.res.join
402+
end
403+
404+
hellos.each do |hello|
405+
@to.start_accepting
406+
@to.accept_paragraph para("#{hello}\n", "#{sekai}\n")
407+
assert_equal "\n<p>#{hello}#{sekai}</p>\n", @to.res.join
408+
end
395409

396-
@to.accept_paragraph para("hello\n", "world\n")
410+
worlds.each do |world|
411+
@to.start_accepting
412+
@to.accept_paragraph para("#{ohayo}\n", "#{world}\n")
413+
assert_equal "\n<p>#{ohayo}#{world}</p>\n", @to.res.join
414+
end
397415

398-
assert_equal "\n<p>hello world </p>\n", @to.res.join
416+
@to.start_accepting
417+
@to.accept_paragraph para("#{ohayo}\n", "#{sekai}\n")
418+
assert_equal "\n<p>#{ohayo}#{sekai}</p>\n", @to.res.join
399419
end
400420

401421
def test_accept_heading_output_decoration

0 commit comments

Comments
 (0)