Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Sources/AsciiDocRender/DocumentRender.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ public final class DocumentRenderer {
if let pageCSS = pageCSS(from: templateDocument) {
templateContext["pageCSS"] = pageCSS
}
if let styleCSS = styleCSS(from: templateDocument) {
templateContext["styleCSS"] = styleCSS
}
xadContext["template"] = templateContext
}

Expand Down Expand Up @@ -941,6 +944,38 @@ public final class DocumentRenderer {
return lines.joined(separator: "\n")
}

private func styleCSS(from template: XADTemplateDocument) -> String? {
guard let styleValue = template.typedAttributes["style"] else { return nil }
guard case .dictionary(let style) = styleValue else { return nil }

var lines: [String] = [":root {"]

if case .dictionary(let font)? = style["font"] {
if let body = stringValue(font["body"]) { lines.append(" --xad-font-body: \"\(body)\";") }
if let heading = stringValue(font["heading"]) { lines.append(" --xad-font-heading: \"\(heading)\";") }
if let mono = stringValue(font["mono"]) { lines.append(" --xad-font-mono: \"\(mono)\";") }
}

if case .dictionary(let size)? = style["size"] {
if let body = stringValue(size["body"]) { lines.append(" --xad-size-body: \(body);") }
if let h1 = stringValue(size["h1"]) { lines.append(" --xad-size-h1: \(h1);") }
if let h2 = stringValue(size["h2"]) { lines.append(" --xad-size-h2: \(h2);") }
}

if case .dictionary(let line)? = style["line"] {
if let leading = stringValue(line["leading"]) { lines.append(" --xad-line-leading: \(leading);") }
}

if case .dictionary(let color)? = style["color"] {
if let text = stringValue(color["text"]) { lines.append(" --xad-color-text: \(text);") }
if let muted = stringValue(color["muted"]) { lines.append(" --xad-color-muted: \(muted);") }
}

guard lines.count > 1 else { return nil }
lines.append("}")
return lines.joined(separator: "\n")
}

private func formatAuthor(_ author: AdocAuthor) -> String {
if let fullname = author.fullname, !fullname.isEmpty {
return appendAddress(fullname, address: author.address)
Expand Down
50 changes: 50 additions & 0 deletions Templates/html5/document.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
{% if xad and xad.template and xad.template.pageCSS %}
{{ xad.template.pageCSS }}
{% endif %}
{% if xad and xad.template and xad.template.styleCSS %}
{{ xad.template.styleCSS }}
{% endif %}

:root {
--surface: #ffffff;
Expand All @@ -27,6 +30,15 @@
--accent-soft: rgba(37, 99, 235, 0.1);
--shadow-soft: 0 10px 25px rgba(15, 23, 42, 0.08);
--monospace: "SFMono-Regular", "Roboto Mono", ui-monospace, Menlo, Monaco, "Liberation Mono", monospace;
--xad-font-body: "Times New Roman";
--xad-font-heading: "Times New Roman";
--xad-font-mono: "SFMono-Regular", "Roboto Mono", ui-monospace, Menlo, Monaco, "Liberation Mono", monospace;
--xad-size-body: 11pt;
--xad-size-h1: 20pt;
--xad-size-h2: 14pt;
--xad-line-leading: 1.35;
--xad-color-text: #111827;
--xad-color-muted: #4b5563;
}

@media (prefers-color-scheme: dark) {
Expand Down Expand Up @@ -57,6 +69,20 @@
line-height: 1.65;
}

.xad-doc {
font-family: var(--xad-font-body, "Times New Roman");
font-size: var(--xad-size-body, 11pt);
line-height: var(--xad-line-leading, 1.35);
color: var(--xad-color-text, #111827);
}

.xad-doc h1, .xad-doc h2, .xad-doc h3, .xad-doc h4, .xad-doc h5, .xad-doc h6 {
font-family: var(--xad-font-heading, "Times New Roman");
}

.xad-doc h1 { font-size: var(--xad-size-h1, 20pt); }
.xad-doc h2 { font-size: var(--xad-size-h2, 14pt); }

a {
color: var(--accent);
text-decoration: none;
Expand Down Expand Up @@ -107,6 +133,30 @@
min-width: 0;
}

.xad-flow[data-slot="title"] .doc-title p {
font-family: var(--xad-font-heading, "Times New Roman");
font-size: var(--xad-size-h1, 2.2rem);
font-weight: 700;
line-height: 1.1;
margin: 0;
}

.xad-flow[data-slot="authors"] .author p {
margin: 0.25rem 0;
color: var(--xad-color-muted, #4b5563);
}

.xad-flow[data-slot="abstract"] .block.paragraph {
background: var(--surface-muted);
border: 1px solid var(--border-soft);
border-radius: 12px;
padding: 1rem 1.25rem;
}

.xad-flow[data-slot="abstract"] .block.paragraph p {
margin: 0;
}

.xad-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
Expand Down
1 change: 1 addition & 0 deletions Templates/xad/default/template.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= Default Template
:page.masters: {"default": {"size": "A4", "margins": {"top": "18mm", "right": "18mm", "bottom": "20mm", "left": "18mm"}, "duplex": false}}
:style: {"font": {"body": "Libertinus Serif", "heading": "Libertinus Sans", "mono": "Iosevka"}, "size": {"body": "11pt", "h1": "20pt", "h2": "14pt"}, "line": {"leading": 1.35}, "color": {"text": "#111827", "muted": "#4b5563"}}

[layout]
----
Expand Down
1 change: 1 addition & 0 deletions Templates/xad/double-column-explicit/template.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= Double Column Explicit Template
:page.masters: {"default": {"size": "A4", "margins": {"top": "18mm", "right": "18mm", "bottom": "20mm", "left": "18mm"}, "duplex": false}}
:style: {"font": {"body": "Libertinus Serif", "heading": "Libertinus Sans", "mono": "Iosevka"}, "size": {"body": "11pt", "h1": "20pt", "h2": "14pt"}, "line": {"leading": 1.35}, "color": {"text": "#111827", "muted": "#4b5563"}}

[layout]
----
Expand Down
1 change: 1 addition & 0 deletions Templates/xad/double-column-flow/template.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= Double Column Flow Template
:page.masters: {"default": {"size": "A4", "margins": {"top": "18mm", "right": "18mm", "bottom": "20mm", "left": "18mm"}, "duplex": false}}
:style: {"font": {"body": "Libertinus Serif", "heading": "Libertinus Sans", "mono": "Iosevka"}, "size": {"body": "11pt", "h1": "20pt", "h2": "14pt"}, "line": {"leading": 1.35}, "color": {"text": "#111827", "muted": "#4b5563"}}

[layout]
----
Expand Down
9 changes: 8 additions & 1 deletion Templates/xad/trivial/template.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
= Trivial Template
:page.masters: {"default": {"size": "A4", "margins": {"top": "18mm", "right": "18mm", "bottom": "20mm", "left": "18mm"}, "duplex": false}}
:page.masters: {
default: {
size: "A4",
margins: { top: "18mm", right: "18mm", bottom": "20mm", left: "18mm"},
duplex: false
}
}
:style: {"font": {"body": "Libertinus Serif", "heading": "Libertinus Sans", "mono": "Iosevka"}, "size": {"body": "11pt", "h1": "20pt", "h2": "14pt"}, "line": {"leading": 1.35}, "color": {"text": "#111827", "muted": "#4b5563"}}

[layout]
----
Expand Down
Loading