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

MARKDOWNBuilder: support some commands #881

Merged
merged 5 commits into from
Jun 21, 2018
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
64 changes: 62 additions & 2 deletions lib/review/markdownbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def extname
end

def builder_init_file
@noindent = nil
@blank_seen = nil
@ul_indent = 0
@chapter.book.image_types = %w[.png .jpg .jpeg .gif .svg]
Expand Down Expand Up @@ -48,8 +49,18 @@ def quote(lines)
end

def paragraph(lines)
puts lines.join
puts "\n"
if @noindent
puts %Q(<p class="noindent">#{lines.join}</p>)
puts "\n"
@noindent = nil
else
puts lines.join
puts "\n"
end
end

def noindent
@noindent = true
end

def list_header(id, caption, lang)
Expand Down Expand Up @@ -129,6 +140,14 @@ def emlist(lines, caption = nil, lang = nil)
blank
end

def captionblock(type, lines, caption, _specialstyle = nil)
puts %Q(<div class="#{type}">)
puts %Q(<p class="caption">#{compile_inline(caption)}</p>) if caption.present?
blocked_lines = split_paragraph(lines)
puts blocked_lines.join("\n")
puts '</div>'
end

def hr
puts '----'
end
Expand Down Expand Up @@ -160,10 +179,22 @@ def inline_code(str)
"`#{str}`"
end

def inline_sub(str)
"<sub>#{str}</sub>"
end

def inline_sup(str)
"<sup>#{str}</sup>"
end

def inline_tt(str)
"`#{str}`"
end

def inline_u(str)
"<u>#{str}</u>"
end

def image_image(id, caption, _metric)
blank
puts "![#{compile_inline(caption)}](#{@chapter.image(id).path.sub(%r{\A\./}, '')})"
Expand All @@ -180,6 +211,10 @@ def inline_img(id)
error "unknown image: #{id}"
end

def inline_dtp(str)
"<!-- DTP:#{str} -->"
end

def indepimage(_lines, id, caption = '', _metric = nil)
blank
puts "![#{compile_inline(caption)}](#{@chapter.image(id).path.sub(%r{\A\./}, '')})"
Expand Down Expand Up @@ -299,6 +334,16 @@ def compile_ruby(base, ruby)
end
end

def compile_kw(word, alt)
%Q(<b class="kw">) +
if alt
escape_html(word + " (#{alt.strip})")
else
escape_html(word)
end +
"</b><!-- IDX:#{escape_comment(escape_html(word))} -->"
end

def comment(lines, comment = nil)
return unless @book.config['draft']
lines ||= []
Expand All @@ -309,12 +354,27 @@ def comment(lines, comment = nil)
puts %Q(<div class="red">#{escape(str)}</div>)
end

def inline_icon(id)
begin
"![](#{@chapter.image(id).path.sub(%r{\A\./}, '')})"
rescue
warn "image not bound: #{id}"
%Q(<pre>missing image: #{id}</pre>)
end
end

def inline_comment(str)
if @book.config['draft']
%Q(<span class="red">#{escape(str)}</span>)
else
''
end
end

def flushright(lines)
puts %Q(<div class="flushright">)
puts lines.join
puts %Q(</div>)
end
end
end # module ReVIEW
10 changes: 10 additions & 0 deletions test/test_markdownbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ def test_quote
assert_equal %Q(\n> foobar\n> \n> buz\n\n), actual
end

def test_memo
actual = compile_block("//memo[this is @<b>{test}<&>_]{\ntest1\n\ntest@<i>{2}\n//}\n")
assert_equal %Q(<div class="memo">\n<p class="caption">this is **test**<&>_</p>\ntest1\ntest*2*\n</div>\n), actual
end

def test_noindent
actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
assert_equal %Q(<p class="noindent">foobar</p>\n\nfoo2bar2\n\n), actual
end

def test_inline_em
assert_equal 'test*foo*abc', compile_inline('test@<em>{foo}abc')
end
Expand Down