|
// retoor <retoor@molodetz.nl>
|
|
|
|
import "jinja" for Environment, DictLoader
|
|
|
|
System.print("=" * 60)
|
|
System.print("JINJA MARKDOWN - Markdown/HTML Conversion in Templates")
|
|
System.print("=" * 60)
|
|
|
|
var templates = {
|
|
"md_to_html": "{\% markdowntohtml \%}# {{ title }}
|
|
|
|
{{ description }}
|
|
|
|
- Item **one**
|
|
- Item **two**
|
|
- Item **three**
|
|
{\% endmarkdowntohtml \%}",
|
|
|
|
"html_to_md": "{\% markdownfromhtml \%}<h1>{{ title }}</h1>
|
|
<p>This is a <strong>paragraph</strong> with <em>formatting</em>.</p>
|
|
<ul>
|
|
<li>First</li>
|
|
<li>Second</li>
|
|
</ul>{\% endmarkdownfromhtml \%}",
|
|
|
|
"filter_md": "{{ content|markdown }}",
|
|
|
|
"filter_fromhtml": "{{ content|markdownfromhtml }}",
|
|
|
|
"mixed": "<div class=\"article\">
|
|
{\% markdowntohtml \%}## {{ article.title }}
|
|
|
|
{{ article.body }}
|
|
{\% endmarkdowntohtml \%}
|
|
</div>"
|
|
}
|
|
|
|
var env = Environment.new(DictLoader.new(templates))
|
|
|
|
System.print("\n--- Markdown to HTML (block tag) ---")
|
|
System.print(env.getTemplate("md_to_html").render({
|
|
"title": "Welcome",
|
|
"description": "This is a *template* with markdown support."
|
|
}))
|
|
|
|
System.print("\n--- HTML to Markdown (block tag) ---")
|
|
System.print(env.getTemplate("html_to_md").render({
|
|
"title": "Documentation"
|
|
}))
|
|
|
|
System.print("\n--- Markdown filter ---")
|
|
System.print(env.getTemplate("filter_md").render({
|
|
"content": "**Bold** and *italic* text."
|
|
}))
|
|
|
|
System.print("\n--- Markdown from HTML filter ---")
|
|
System.print(env.getTemplate("filter_fromhtml").render({
|
|
"content": "<h2>Section</h2><p>A paragraph.</p>"
|
|
}))
|
|
|
|
System.print("\n--- Mixed HTML and Markdown ---")
|
|
System.print(env.getTemplate("mixed").render({
|
|
"article": {
|
|
"title": "Getting Started",
|
|
"body": "Read the **documentation** for details."
|
|
}
|
|
}))
|