Skip to content

Commit

Permalink
textmaker: write a line between th/td by default. introduced textmake…
Browse files Browse the repository at this point in the history
…r/th_bold flag for backward compatibility. Closes: #1789
  • Loading branch information
kmuto committed Feb 5, 2022
1 parent 6aeaba0 commit 1c2c38b
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 11 deletions.
6 changes: 6 additions & 0 deletions doc/config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,9 @@ pdfmaker:
# options_with_caption: "colbacktitle=black!25!white"
#
# pdfmaker:階層を使うものはここまで
# textmaker:
# 表見出しの表現の設定
# nullの場合は区切り線(------------)で見出し行と通常の行を分ける。
# trueの場合は見出しを★〜☆で囲み(太字と同様)、区切り線を入れない。
# th_bold: null
# textmaker:階層を使うものはここまで
5 changes: 4 additions & 1 deletion lib/review/configure.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2012-2021 Masanori Kado, Masayoshi Takahashi, Kenshi Muto
# Copyright (c) 2012-2022 Masanori Kado, Masayoshi Takahashi, Kenshi Muto
#
# This program is free software.
# You can distribute or modify this program under the terms of
Expand Down Expand Up @@ -141,6 +141,9 @@ def self.values # rubocop:disable Metrics/MethodLength
'force_include_images' => [],
'cover_linear' => nil,
'back_footnote' => nil
},
'textmaker' => {
'th_bold' => nil
}
]
conf.maker = nil
Expand Down
27 changes: 25 additions & 2 deletions lib/review/topbuilder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2008-2021 Minero Aoki, Kenshi Muto
# Copyright (c) 2008-2022 Minero Aoki, Kenshi Muto
# 2002-2006 Minero Aoki
#
# This program is free software.
Expand Down Expand Up @@ -262,8 +262,31 @@ def table(lines, id = nil, caption = nil)
blank
end

def table_rows(sepidx, rows)
if sepidx
sepidx.times do
tr(rows.shift.map { |s| th(s) })
end
if !@book.config['textmaker'] || !@book.config['textmaker']['th_bold']
puts '-' * 12
end
rows.each do |cols|
tr(cols.map { |s| td(s) })
end
else
rows.each do |cols|
h, *cs = *cols
tr([th(h)] + cs.map { |s| td(s) })
end
end
end

def th(str)
"★#{str}☆"
if @book.config['textmaker'] && @book.config['textmaker']['th_bold']
"★#{str}☆"
else
str
end
end

def table_end
Expand Down
69 changes: 61 additions & 8 deletions test/test_topbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def test_inline_in_table
actual = compile_block("//table{\n★1☆\t▲2☆\n------------\n★3☆\t▲4☆<>&\n//}\n")
expected = <<-EOS
◆→開始:表←◆
★★1☆☆\t★▲2☆☆
★1☆\t▲2☆
------------
★3☆\t▲4☆<>&
◆→終了:表←◆
Expand Down Expand Up @@ -506,7 +507,8 @@ def test_table
actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
expected = <<-EOS
◆→開始:表←◆
★aaa☆\t★bbb☆
aaa\tbbb
------------
ccc\tddd<>&
◆→終了:表←◆
Expand All @@ -518,7 +520,8 @@ def test_table
◆→開始:表←◆
表1.1 FOO
★aaa☆\t★bbb☆
aaa\tbbb
------------
ccc\tddd<>&
◆→終了:表←◆
Expand All @@ -529,12 +532,36 @@ def test_table
actual = compile_block("//table[foo][FOO]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
expected = <<-EOS
◆→開始:表←◆
★aaa☆\t★bbb☆
aaa\tbbb
------------
ccc\tddd<>&
表1.1 FOO
◆→終了:表←◆
EOS
assert_equal expected, actual
end

def test_table_th_bold
@config['textmaker']['th_bold'] = true
actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
expected = <<-EOS
◆→開始:表←◆
★aaa☆\t★bbb☆
ccc\tddd<>&
◆→終了:表←◆
EOS
assert_equal expected, actual

actual = compile_block("//table{\naaa\tbbb\nccc\tddd<>&\n//}\n")
expected = <<-EOS
◆→開始:表←◆
★aaa☆\tbbb
★ccc☆\tddd<>&
◆→終了:表←◆
EOS
assert_equal expected, actual
end
Expand All @@ -561,6 +588,28 @@ def test_emtable
◆→開始:表←◆
foo
aaa\tbbb
------------
ccc\tddd<>&
◆→終了:表←◆
◆→開始:表←◆
aaa\tbbb
------------
ccc\tddd<>&
◆→終了:表←◆
EOS
assert_equal expected, actual
end

def test_emtable_thbold
@config['textmaker']['th_bold'] = true
actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
expected = <<-EOS
◆→開始:表←◆
foo
★aaa☆\t★bbb☆
ccc\tddd<>&
◆→終了:表←◆
Expand All @@ -578,7 +627,8 @@ def test_table_row_separator
src = "//table{\n1\t2\t\t3 4| 5\n------------\na b\tc d |e\n//}\n"
expected = <<-EOS
◆→開始:表←◆
★1☆ ★2☆ ★3 4| 5☆
1 2 3 4| 5
------------
a b c d |e
◆→終了:表←◆
Expand All @@ -590,7 +640,8 @@ def test_table_row_separator
actual = compile_block(src)
expected = <<-EOS
◆→開始:表←◆
★1☆ ★2☆ ★☆ ★3 4| 5☆
1 2 3 4| 5
------------
a b c d |e
◆→終了:表←◆
Expand All @@ -601,7 +652,8 @@ def test_table_row_separator
actual = compile_block(src)
expected = <<-EOS
◆→開始:表←◆
★1☆ ★2☆ ★3☆ ★4|☆ ★5☆
1 2 3 4| 5
------------
a b c d |e
◆→終了:表←◆
Expand All @@ -612,7 +664,8 @@ def test_table_row_separator
actual = compile_block(src)
expected = <<-EOS
◆→開始:表←◆
★1 2 3 4☆ ★5☆
1 2 3 4 5
------------
a b c d e
◆→終了:表←◆
Expand Down

0 comments on commit 1c2c38b

Please sign in to comment.