Skip to content

Commit

Permalink
Merge pull request #877 from kmuto/escape_in_fence
Browse files Browse the repository at this point in the history
フェンス記法内で@をエスケープ
  • Loading branch information
kmuto authored Nov 16, 2017
2 parents 2b757c0 + 7c73677 commit 64e2a27
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/review/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def compile_single(syntax, args)
def replace_fence(str)
str.gsub(/@<(\w+)>([$|])(.+?)(\2)/) do
op = $1
arg = $3.gsub('\\}') { '\\\\}' }.gsub('}') { '\}' }.sub(/(?:\\)+$/) { |m| '\\\\' * m.size }
arg = $3.gsub('@', "\x01").gsub('\\}') { '\\\\}' }.gsub('}') { '\}' }.sub(/(?:\\)+$/) { |m| '\\\\' * m.size }
"@<#{op}>{#{arg}}"
end
end
Expand All @@ -522,7 +522,7 @@ def text(str)
result << compile_inline(words.shift.gsub(/\\\}/, '}').gsub(/\\\\/, '\\'))
result << @strategy.nofunc_text(words.shift)
end
result
result.gsub("\x01", '@')
rescue => err
error err.message
end
Expand Down
5 changes: 5 additions & 0 deletions test/test_htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1681,4 +1681,9 @@ def test_inline_comment_for_draft
actual = compile_inline('test @<comment>{コメント} test2')
assert_equal %Q(test <span class="draft-comment">コメント</span> test2), actual
end

def test_inline_fence
actual = compile_inline('test @<code>|@<code>{$サンプル$}|')
assert_equal 'test <code class="inline-code tt">@&lt;code&gt;{$サンプル$}</code>', actual
end
end
5 changes: 5 additions & 0 deletions test/test_latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,11 @@ def test_inline_comment_for_draft
assert_equal 'test \\pdfcomment{コメント} test2', actual
end

def test_inline_fence
actual = compile_inline('test @<code>|@<code>{$サンプル$}|')
assert_equal 'test \\texttt{@\\textless{}code\\textgreater{}\\{\\textdollar{}サンプル\\textdollar{}\\}}', actual
end

def test_appendix_list
@chapter.instance_eval do
def on_appendix?
Expand Down

0 comments on commit 64e2a27

Please sign in to comment.