require 'test_helper' require 'md2man/html/engine' describe 'html engine' do before do @markdown = Md2Man::HTML::ENGINE end def heredoc document document.gsub(/^\s*\|/, '').chomp end it 'renders nothing as nothing' do @markdown.render('').must_be_empty end it 'renders paragraphs' do @markdown.render(heredoc(<<-INPUT)).must_equal(heredoc(<<-OUTPUT)) |just some paragraph |spanning |multiple |lines |but within 4-space indent INPUT |

just some paragraph |spanning |multiple |lines |but within 4-space indent

OUTPUT end it 'renders tagged paragraphs with uniformly two-space indented bodies' do @markdown.render(heredoc(<<-INPUT)).must_equal(heredoc(<<-OUTPUT)) |just some paragraph | spanning | multiple | lines | but within 4-space indent | | and a single line following | | and multiple | lines following INPUT |
just some paragraph
spanning |multiple |lines |but within 4-space indent
and a single line following
and multiple |lines following
OUTPUT end it 'does not break surrounding Markdown while processing references' do @markdown.render(heredoc(<<-INPUT)).must_equal(heredoc(<<-OUTPUT)) |For example, the `printf(3)` cross reference would be emitted as this HTML: | | printf(3) INPUT |

For example, the printf(3) cross reference would be emitted as this HTML:

|
<a class="md2man-reference" href="../man3/printf.3.html">printf(3)</a>
      |
| OUTPUT end it 'renders references to other man pages as hyperlinks in middle of line' do @markdown.render(heredoc(<<-INPUT)).must_equal(heredoc(<<-OUTPUT)) |convert them from markdown(7) into roff(7), using INPUT |

convert them from markdown(7) into roff(7), using

OUTPUT end it 'renders references to other man pages as hyperlinks at beginning of line' do @markdown.render(heredoc(<<-INPUT)).must_equal(heredoc(<<-OUTPUT)) |markdown(1) into roff(2) INPUT |

markdown(1) into roff(2)

OUTPUT end it 'renders references inside code blocks' do @markdown.render(heredoc(<<-INPUT)).must_equal(heredoc(<<-OUTPUT)) | this is a code block | containing markdown(7), | roff(7), and much more! INPUT |
this is a code block
      |containing markdown(7),
      |roff(7), and much more!
      |
| OUTPUT end it 'renders references inside code spans' do @markdown.render(heredoc(<<-INPUT)).must_equal(heredoc(<<-OUTPUT)) |this is a code span `containing markdown(7), roff(7), and` much more! INPUT |

this is a code span containing markdown(7), roff(7), and much more!

OUTPUT end it 'does not render references inside image descriptions' do @markdown.render(heredoc(<<-INPUT)).must_equal(heredoc(<<-OUTPUT)) |![Obligatory screenshot of md2man-roff(1) in action!]( |https://raw.github.com/sunaku/md2man/master/EXAMPLE.png) INPUT |

Obligatory screenshot of md2man-roff(1) in action!

OUTPUT end it 'escapes backslashes inside code blocks' do # NOTE: we have to escape backslashes in the INPUT to # prevent Ruby from interpreting them as escapes @markdown.render(heredoc(<<-INPUT)).must_equal(heredoc(<<-OUTPUT)) | _______ _______ | ___ /___________ /__ | _ __/ __ \\ __/ /_/ | / /_/ /_/ / / / ,\\ | \\__/\\____/_/ /_/|_\\ | >>>------> INPUT |
_______      _______
      | ___  /___________ /__
      |  _  __/ __ \\  __/ /_/
      |  / /_/ /_/ / / / ,\\
      |  \\__/\\____/_/ /_/|_\\
      |             >>>------>
      |
| OUTPUT end it 'adds permalinks to headings' do @markdown.render(heredoc(<<-INPUT)).must_equal(heredoc(<<-OUTPUT)) |# foo *BAR* |## bar BAZ |### --BAZ-QUX-- |#### qux (MOZ) |##### {m}oz END |# bar BAZ |## bar *BAZ* |### bar **BAZ** |#### -bar--BAZ--- INPUT

foo BAR

\

bar BAZ

\

--BAZ-QUX--

\

qux (MOZ)

\
{m}oz END
\

bar BAZ

\

bar BAZ

\

bar BAZ

\

-bar--BAZ---

OUTPUT end it 'adds permalinks to headings that contain man page references' do @markdown.render(heredoc(<<-INPUT)).must_equal(heredoc(<<-OUTPUT)) |## here is-a-reference(3) to another man page | |here is a paragraph containing is-a-reference(3) again | |here is another paragraph containing is-a-reference(3) yet again INPUT

here is-a-reference(3) to another man page

\

here is a paragraph containing is-a-reference(3) again

\

here is another paragraph containing is-a-reference(3) yet again

OUTPUT end end