Skip to content

Commit

Permalink
trim pre/post spaces in ruby. Cloess: #1837
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuto committed Jul 25, 2022
1 parent ec6df4f commit 0c1cc13
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion doc/format.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ UL1-OL1-PARAGRAPH
* `@<column>{ラベルまたは見出し}` : コラムを参照します。

### その他
* `@<ruby>{親文字, ルビ}` : ルビを振ります。たとえば `@<ruby>{愕然, がくぜん}` のように表記します。
* `@<ruby>{親文字,ルビ}` : ルビを振ります。たとえば `@<ruby>{愕然,がくぜん}` のように表記します。
* `@<br>{}` : 段落途中で改行します。濫用は避けたいところですが、表のセル内や箇条書き内などで必要になることもあります。
* `@<uchar>{番号}` : Unicode文字を出力します。引数は16進数で指定します。
* `@<href>{URL}`, `@<href>{URL, 文字表現}` : ハイパーリンクを作成します(後述)。
Expand Down
2 changes: 1 addition & 1 deletion doc/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ Output:
### Other inline commands

```
@<ruby>{Matsumoto, Matz}:: ruby markups
@<ruby>{Matsumoto,Matz}:: ruby markups
@<br>{}:: linebreak in paragraph
@<uchar>{2460}:: Unicode code point
@<href>{http://www.google.com/, google}:: hyper link(URL)
Expand Down
4 changes: 2 additions & 2 deletions lib/review/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,10 @@ def inline_bou(str)
def inline_ruby(arg)
base, *ruby = *arg.scan(/(?:(?:(?:\\\\)*\\,)|[^,\\]+)+/)
if base
base = base.gsub(/\\,/, ',')
base = base.gsub(/\\,/, ',').strip
end
if ruby
ruby = ruby.join(',').gsub(/\\,/, ',')
ruby = ruby.join(',').gsub(/\\,/, ',').strip
end
compile_ruby(base, ruby)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/review/idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def endnote_item(id)
end

def compile_ruby(base, ruby)
%Q(<GroupRuby><aid:ruby xmlns:aid="http://ns.adobe.com/AdobeInDesign/3.0/"><aid:rb>#{escape(base.strip)}</aid:rb><aid:rt>#{escape(ruby.strip)}</aid:rt></aid:ruby></GroupRuby>)
%Q(<GroupRuby><aid:ruby xmlns:aid="http://ns.adobe.com/AdobeInDesign/3.0/"><aid:rb>#{escape(base)}</aid:rb><aid:rt>#{escape(ruby)}</aid:rt></aid:ruby></GroupRuby>)
end

def compile_kw(word, alt)
Expand Down
2 changes: 2 additions & 0 deletions test/test_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def @b.compile_ruby(base, ruby)
end
str = @b.inline_ruby('foo,bar')
assert_equal str, ['foo', 'bar']
str = @b.inline_ruby(' foo , bar ')
assert_equal str, ['foo', 'bar']
str = @b.inline_ruby('foo\\,\\,,\\,bar,buz')
assert_equal str, ['foo,,', ',bar,buz']
end
Expand Down
3 changes: 3 additions & 0 deletions test/test_htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ def test_inline_balloon
def test_inline_ruby
actual = compile_inline('@<ruby>{粗雑,クルード}と思われているなら@<ruby>{繊細,テクニカル}にやり、繊細と思われているなら粗雑にやる。')
assert_equal '<ruby>粗雑<rp>(</rp><rt>クルード</rt><rp>)</rp></ruby>と思われているなら<ruby>繊細<rp>(</rp><rt>テクニカル</rt><rp>)</rp></ruby>にやり、繊細と思われているなら粗雑にやる。', actual

actual = compile_inline('@<ruby>{ 粗雑 , クルード }と思われているなら@<ruby>{ 繊細 ,テクニカル }にやり、繊細と思われているなら粗雑にやる。')
assert_equal '<ruby>粗雑<rp>(</rp><rt>クルード</rt><rp>)</rp></ruby>と思われているなら<ruby>繊細<rp>(</rp><rt>テクニカル</rt><rp>)</rp></ruby>にやり、繊細と思われているなら粗雑にやる。', actual
end

def test_inline_ruby_comma
Expand Down
5 changes: 4 additions & 1 deletion test/test_idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ def test_inline_uchar
end

def test_inline_ruby
actual = compile_inline('@<ruby>{coffin, bed}')
actual = compile_inline('@<ruby>{coffin,bed}')
assert_equal %Q(<GroupRuby><aid:ruby xmlns:aid="http://ns.adobe.com/AdobeInDesign/3.0/"><aid:rb>coffin</aid:rb><aid:rt>bed</aid:rt></aid:ruby></GroupRuby>), actual

actual = compile_inline('@<ruby>{ coffin , bed }')
assert_equal %Q(<GroupRuby><aid:ruby xmlns:aid="http://ns.adobe.com/AdobeInDesign/3.0/"><aid:rb>coffin</aid:rb><aid:rt>bed</aid:rt></aid:ruby></GroupRuby>), actual
end

Expand Down
8 changes: 8 additions & 0 deletions test/test_latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,17 @@ def test_inline_pageref
assert_equal 'test p.\pageref{p1}', actual
end

def test_inline_ruby
actual = compile_inline('@<ruby>{ foo , bar }')
assert_equal '\\ruby{foo}{bar}', actual
end

def test_inline_ruby_comma
actual = compile_inline('@<ruby>{foo\\, bar\\, buz,フー・バー・バズ}')
assert_equal '\\ruby{foo, bar, buz}{フー・バー・バズ}', actual

actual = compile_inline('@<ruby>{foo\\, bar\\, buz , フー・バー・バズ }')
assert_equal '\\ruby{foo, bar, buz}{フー・バー・バズ}', actual
end

def test_inline_uchar
Expand Down
3 changes: 3 additions & 0 deletions test/test_plaintextbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def test_inline_raw
def test_inline_ruby
actual = compile_inline('@<ruby>{coffin,bed}')
assert_equal 'coffin', actual

actual = compile_inline('@<ruby>{ coffin , bed }')
assert_equal 'coffin', actual
end

def test_inline_kw
Expand Down
3 changes: 3 additions & 0 deletions test/test_rstbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def test_inline_raw
def test_inline_ruby
actual = compile_inline('@<ruby>{coffin,bed}')
assert_equal ' :ruby:`coffin`<bed>`_ ', actual

actual = compile_inline('@<ruby>{ coffin , bed }')
assert_equal ' :ruby:`coffin`<bed>`_ ', actual
end

def test_inline_kw
Expand Down
3 changes: 3 additions & 0 deletions test/test_topbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def test_inline_raw
def test_inline_ruby
actual = compile_inline('@<ruby>{coffin,bed}')
assert_equal 'coffin◆→DTP連絡:「coffin」に「bed」とルビ←◆', actual

actual = compile_inline('@<ruby>{ coffin , bed }')
assert_equal 'coffin◆→DTP連絡:「coffin」に「bed」とルビ←◆', actual
end

def test_inline_kw
Expand Down

0 comments on commit 0c1cc13

Please sign in to comment.