|
// retoor <retoor@molodetz.nl>
|
|
|
|
import "markdown" for Markdown
|
|
|
|
var nested = Markdown.fromHtml("<p><strong>Bold <em>and italic</em> text</strong></p>")
|
|
System.print(nested.contains("**Bold *and italic* text**")) // expect: true
|
|
|
|
var mixed = Markdown.fromHtml("<p>Normal <strong>bold</strong> and <em>italic</em> and <code>code</code></p>")
|
|
System.print(mixed.contains("Normal **bold** and *italic* and `code`")) // expect: true
|
|
|
|
var codeBlock = Markdown.fromHtml("<pre><code>function test() {\n return true;\n}</code></pre>")
|
|
System.print(codeBlock.contains("```")) // expect: true
|
|
System.print(codeBlock.contains("function test()")) // expect: true
|
|
|
|
var script = Markdown.fromHtml("<p>Hello</p><script>alert('xss');</script><p>World</p>")
|
|
System.print(script.contains("Hello")) // expect: true
|
|
System.print(script.contains("World")) // expect: true
|
|
System.print(script.contains("alert")) // expect: false
|
|
System.print(script.contains("script")) // expect: false
|
|
|
|
var style = Markdown.fromHtml("<p>Content</p><style>.red { color: red; }</style>")
|
|
System.print(style.contains("Content")) // expect: true
|
|
System.print(style.contains("color")) // expect: false
|
|
|
|
var entities = Markdown.fromHtml("<p>5 > 3 && 3 < 5</p>")
|
|
System.print(entities.contains(">")) // expect: true
|
|
System.print(entities.contains("<")) // expect: true
|
|
System.print(entities.contains("&")) // expect: true
|
|
|
|
var doc = """
|
|
<html>
|
|
<head><title>Test</title></head>
|
|
<body>
|
|
<h1>Main Title</h1>
|
|
<p>Introduction paragraph with <strong>bold</strong> text.</p>
|
|
<h2>Section One</h2>
|
|
<ul>
|
|
<li>Item A</li>
|
|
<li>Item B</li>
|
|
</ul>
|
|
<blockquote>A wise quote</blockquote>
|
|
<hr>
|
|
<p>Footer content</p>
|
|
</body>
|
|
</html>
|
|
"""
|
|
var result = Markdown.fromHtml(doc)
|
|
System.print(result.contains("# Main Title")) // expect: true
|
|
System.print(result.contains("**bold**")) // expect: true
|
|
System.print(result.contains("## Section One")) // expect: true
|
|
System.print(result.contains("- Item A")) // expect: true
|
|
System.print(result.contains("> A wise quote")) // expect: true
|
|
System.print(result.contains("---")) // expect: true
|
|
|
|
var linkNested = Markdown.fromHtml("<a href=\"/page\"><strong>Bold Link</strong></a>")
|
|
System.print(linkNested.contains("[**Bold Link**](/page)")) // expect: true
|
|
|
|
var container = Markdown.fromHtml("<div><section><article>Content</article></section></div>")
|
|
System.print(container.contains("Content")) // expect: true
|
|
System.print(container.contains("<div>")) // expect: false
|
|
System.print(container.contains("<section>")) // expect: false
|
|
|
|
System.print(Markdown.fromHtml("<img src=\"a.png\" alt=\"test\"/>").contains("")) // expect: true
|
|
System.print(Markdown.fromHtml("<br/>").trim() == "") // expect: true
|
|
|
|
System.print(Markdown.fromHtml("<p></p>").trim() == "") // expect: true
|
|
System.print(Markdown.fromHtml("<strong></strong>").trim() == "****") // expect: true
|
|
|
|
var ws = Markdown.fromHtml("<p> spaced content </p>")
|
|
System.print(ws.contains("spaced content")) // expect: true
|
|
|
|
var multi = Markdown.fromHtml("<p>Para 1</p><p>Para 2</p><p>Para 3</p>")
|
|
var lines = multi.split("\n")
|
|
var nonEmpty = 0
|
|
for (line in lines) {
|
|
if (line.trim().count > 0) nonEmpty = nonEmpty + 1
|
|
}
|
|
System.print(nonEmpty >= 3) // expect: true
|