-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #671 from vvakame/feat-md2inaobuilder
md2inaobuilderの追加とrubyのサポート
- Loading branch information
Showing
4 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# -*- coding: utf-8 -*- | ||
# This program is free software. | ||
# You can distribute or modify this program under the terms of | ||
# the GNU LGPL, Lesser General Public License version 2.1. | ||
|
||
require 'review/markdownbuilder' | ||
|
||
module ReVIEW | ||
|
||
class MD2INAOBuilder < MARKDOWNBuilder | ||
def paragraph(lines) | ||
puts " " + lines.join | ||
puts "\n" | ||
end | ||
|
||
def list_header(id, caption, lang) | ||
lang ||= "" | ||
puts "```#{lang}" | ||
print %Q[●リスト#{@chapter.list(id).number}::#{compile_inline(caption)}\n\n] | ||
end | ||
|
||
def cmd(lines) | ||
# WEB+DB では使っていないらしいけど | ||
puts "!!! cmd" | ||
lines.each do |line| | ||
puts detab(line) | ||
end | ||
puts "" | ||
end | ||
|
||
def dl_begin | ||
puts '<dl>' | ||
end | ||
|
||
def dt(line) | ||
puts "<dt>#{line}</dt>" | ||
end | ||
|
||
def dd(lines) | ||
puts "<dd>#{lines.join}</dd>" | ||
end | ||
|
||
def dl_end | ||
puts '</dl>' | ||
end | ||
|
||
def comment(lines, comment = nil) | ||
lines ||= [] | ||
lines.unshift comment unless comment.blank? | ||
str = lines.join("\n") | ||
puts '<span class="red">' | ||
puts str | ||
puts '</span>' | ||
end | ||
|
||
def compile_ruby(base, ruby) | ||
if base.length == 1 | ||
%Q[<span class='monoruby'>#{escape_html(base)}(#{escape_html(ruby)})</span>] | ||
else | ||
%Q[<span class='groupruby'>#{escape_html(base)}(#{escape_html(ruby)})</span>] | ||
end | ||
end | ||
|
||
end | ||
|
||
end # module ReVIEW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# encoding: utf-8 | ||
|
||
require 'test_helper' | ||
require 'review/compiler' | ||
require 'review/book' | ||
require 'review/md2inaobuilder' | ||
require 'review/i18n' | ||
|
||
class MD2INAOBuilderTest < Test::Unit::TestCase | ||
include ReVIEW | ||
|
||
def setup | ||
@builder = MD2INAOBuilder.new() | ||
@config = { | ||
"secnolevel" => 2, # for IDGXMLBuilder, HTMLBuilder | ||
"stylesheet" => nil, # for HTMLBuilder | ||
} | ||
@book = Book::Base.new(".") | ||
@book.config = @config | ||
@compiler = ReVIEW::Compiler.new(@builder) | ||
@chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new) | ||
location = Location.new(nil, nil) | ||
@builder.bind(@compiler, @chapter, location) | ||
I18n.setup("ja") | ||
end | ||
|
||
def test_paragraph | ||
actual = compile_block("Hello, world!") | ||
assert_equal " Hello, world!\n\n", actual | ||
end | ||
|
||
def test_cmd | ||
actual = compile_block("//cmd{\nlineA\nlineB\n//}\n") | ||
assert_equal "!!! cmd\nlineA\nlineB\n\n", actual | ||
end | ||
|
||
def test_dlist | ||
actual = compile_block(": foo\n foo.\n bar.\n") | ||
assert_equal "<dl>\n<dt>foo</dt>\n<dd>foo.bar.</dd>\n</dl>\n", actual | ||
end | ||
|
||
def test_list | ||
actual = compile_block(<<-EOS) | ||
//list[name][caption]{ | ||
AAA | ||
BBB | ||
//} | ||
EOS | ||
|
||
assert_equal <<-EOS, actual | ||
``` | ||
●リスト1::caption | ||
AAA | ||
BBB | ||
``` | ||
EOS | ||
end | ||
|
||
def test_comment | ||
actual = compile_block("//comment{\nHello, world!\n//}\n") | ||
assert_equal "<span class=\"red\">\nHello, world!\n</span>\n", actual | ||
end | ||
|
||
def test_ruby_mono | ||
actual = compile_block("@<ruby>{謳,うた}い文句") | ||
assert_equal " <span class='monoruby'>謳(うた)</span>い文句\n\n", actual | ||
end | ||
|
||
def test_ruby_group | ||
actual = compile_block("@<ruby>{欠伸,あくび}が出る") | ||
assert_equal " <span class='groupruby'>欠伸(あくび)</span>が出る\n\n", actual | ||
end | ||
|
||
end |