html_renderer_spec.cr 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. require "./spec_helper"
  2. describe "Luce.to_html" do
  3. text = "# Hello **Markdown<em>!</em>**\n***"
  4. it "with no syntaxes" do
  5. result = Luce.to_html(text, with_default_block_syntaxes: false, with_default_inline_syntaxes: false, encode_html: false)
  6. result.should eq "# Hello **Markdown<em>!</em>**\n***\n"
  7. end
  8. it "with no default syntaxes but with custom syntax" do
  9. result = Luce.to_html(text,
  10. with_default_block_syntaxes: false,
  11. with_default_inline_syntaxes: false,
  12. encode_html: false,
  13. block_syntaxes: [Luce::HorizontalRuleSyntax.new],
  14. inline_syntaxes: [
  15. Luce::EmphasisSyntax.asterisk,
  16. ]
  17. )
  18. result.should eq "# Hello <strong>Markdown<em>!</em></strong>\n<hr />\n"
  19. end
  20. it "with only default block syntaxes" do
  21. result = Luce.to_html(text,
  22. with_default_inline_syntaxes: false,
  23. encode_html: false)
  24. result.should eq "<h1>Hello **Markdown<em>!</em>**</h1>\n<hr />\n"
  25. end
  26. it "with only default inline syntaxes" do
  27. result = Luce.to_html(text,
  28. with_default_block_syntaxes: false,
  29. encode_html: false)
  30. result.should eq "# Hello <strong>Markdown<em>!</em></strong>\n***\n"
  31. end
  32. it "with no default syntaxes, but with encode_html enabled" do
  33. result = Luce.to_html(text,
  34. with_default_block_syntaxes: false,
  35. with_default_inline_syntaxes: false)
  36. result.should eq "# Hello **Markdown&lt;em&gt;!&lt;/em&gt;**\n***\n"
  37. end
  38. end
  39. describe "test Luce::InlineSyntax case_sensitive parameter" do
  40. text = "one BREAK two"
  41. it "with case_sensitive enabled" do
  42. result = Luce.to_html(
  43. text,
  44. inline_only: true,
  45. inline_syntaxes: [BreakSyntax.new(true)]
  46. )
  47. result.should eq "one BREAK two"
  48. end
  49. it "with case_sensitive disabled" do
  50. result = Luce.to_html(
  51. text,
  52. inline_only: true,
  53. inline_syntaxes: [BreakSyntax.new(false)]
  54. )
  55. result.should eq "one <break /> two"
  56. end
  57. end
  58. private class BreakSyntax < Luce::InlineSyntax
  59. def initialize(case_sensitive : Bool)
  60. super("break", case_sensitive: case_sensitive)
  61. end
  62. def on_match(parser : Luce::InlineParser, match : Regex::MatchData) : Bool
  63. parser.add_node(Luce::Element.empty("break"))
  64. true
  65. end
  66. end