Open
Description
Background
Fabric must support custom formatting of specific elements and the documents, to allow for custom corporate styling. Since the content blocks / documents can be rendered into various formats (Markdown, HTML, etc), the format template should be format-specific.
This issue surpasses #240 as much more flexible approach
Design
We introduce format <format>
block:
format html {
value = <<-EOT
<div class="section">
<h3>{{ .title.as_text }}</h3>
<p class="font-mono text-sm">{{ .content.text.foo.as_text }}</p>
<div class="subsection">
{{ .section.subsec.as_html }}
</div>
</div>
EOT
}
- different formats might support different arguments (for example, DOCX format will have
template_file
argument) - there can be only one
format <format>
block per format on the same level (root level, section block, content block) - the format block defines the format of the block in which it is defined
- the format template can access the data context and all subtrees of rendered content
Example
format html "custom_section" {
template = <<-EOT
<div class="section">
<h2>{{ .content.title.as_text }}</h2>
<p>{{ .content.text.bar.as_text }}</p>
</div>
EOT
}
document "test-doc" {
vars {
x = 1
}
title = "Doc title"
content text "foo" {
value = "Some content text"
}
section "sec1" {
title = "Section title 1"
content text "bar" {
value = "Nested content inside a section 1"
}
format html ref {
base = format.html.custom_section
}
}
section "sec2" {
title = "Section title 2"
content text "baz" {
value = "Nested content inside a section 2"
}
format html ref {
base = format.html.custom_section
}
}
format html {
template = <<-EOT
<!DOCTYPE html>
<html lang="en" class="h-full text-black bg-white dark:bg-raisinBlack dark:text-raisinBlack-50">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title id="page-title">{{ .content.title.as_text }}</title>
<link href="./styles.css" rel="stylesheet"/>
</head>
<body class="h-full">
<h1>{{ .content.title.as_text }} with {{ .vars.x }}</h1>
<p>{{ .content.text.foo.as_text }}</p>
<!-- Specifying exact sections or looping over all sections -->
{{ .section.sec1.as_html }}
{{ .section.sec2.as_html }}
</body>
</html>
EOT
}
format docx {
template_file = "./template.docx"
}
}