# encoding: utf-8 require 'test_helper' require 'tilt' begin require 'tilt/pandoc' class PandocTemplateTest < Minitest::Test test "preparing and evaluating templates on #render" do template = Tilt::PandocTemplate.new { |t| "# Hello World!" } assert_equal "

Hello World!

", template.render end test "can be rendered more than once" do template = Tilt::PandocTemplate.new { |t| "# Hello World!" } 3.times { assert_equal "

Hello World!

", template.render } end test "smartypants when :smartypants is set" do template = Tilt::PandocTemplate.new(:smartypants => true) { |t| "OKAY -- 'Smarty Pants'" } assert_equal "

OKAY – ‘Smarty Pants’

", template.render end test "stripping HTML when :escape_html is set" do template = Tilt::PandocTemplate.new(:escape_html => true) { |t| "HELLO WORLD" } assert_equal "

HELLO <blink>WORLD</blink>

", template.render end # Pandoc has tons of additional markdown features (see http://pandoc.org/README.html#pandocs-markdown). # The test for footnotes should be seen as a general representation for all of them. # use markdown_strict => true to disable additional markdown features describe "passing in Pandoc options" do test "generates footnotes" do template = Tilt::PandocTemplate.new { |t| "Here is an inline note.^[Inlines notes are cool!]" } assert_equal "

Here is an inline note.1

\n
\n
\n
    \n
  1. Inlines notes are cool!

  2. \n
\n
", template.render end test "doesn't generate footnotes with markdown_strict option" do template = Tilt::PandocTemplate.new(:markdown_strict => true) { |t| "Here is an inline note.^[Inlines notes are cool!]" } assert_equal "

Here is an inline note.^[Inlines notes are cool!]

", template.render end test "doesn't generate footnotes with commonmark option" do template = Tilt::PandocTemplate.new(:commonmark => true) { |t| "Here is an inline note.^[Inlines notes are cool!]" } assert_equal "

Here is an inline note.^[Inlines notes are cool!]

", template.render end test "accepts arguments with values (e.g. :id_prefix => 'xyz')" do # Table of contents isn't on by default template = Tilt::PandocTemplate.new { |t| "# This is a heading" } assert_equal "

This is a heading

", template.render # But it can be activated template = Tilt::PandocTemplate.new(:id_prefix => 'test-') { |t| "# This is a heading" } assert_equal "

This is a heading

", template.render end test "requires arguments without value (e.g. --standalone) to be passed as hash keys (:standalone => true)" do template = Tilt::PandocTemplate.new(:standalone => true) { |t| "# This is a heading" } assert_match(/^This is a heading<\/h1>.*<\/html>$/m, template.render) end end end rescue LoadError warn "Tilt::PandocTemplate (disabled)" end