mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-04 18:28:02 +00:00
fix: build pdf docs (#1864)
Some checks are pending
tinymist::ci / Duplicate Actions Detection (push) Waiting to run
tinymist::ci / Check Clippy, Formatting, Completion, Documentation, and Tests (Linux) (push) Waiting to run
tinymist::ci / Check Minimum Rust version and Tests (Windows) (push) Waiting to run
tinymist::ci / E2E Tests (darwin-arm64 on macos-latest) (push) Blocked by required conditions
tinymist::ci / E2E Tests (linux-x64 on ubuntu-22.04) (push) Blocked by required conditions
tinymist::ci / E2E Tests (linux-x64 on ubuntu-latest) (push) Blocked by required conditions
tinymist::ci / E2E Tests (win32-x64 on windows-2022) (push) Blocked by required conditions
tinymist::ci / E2E Tests (win32-x64 on windows-latest) (push) Blocked by required conditions
tinymist::ci / prepare-build (push) Waiting to run
tinymist::ci / build-binary (push) Blocked by required conditions
tinymist::ci / build-vsc-assets (push) Blocked by required conditions
tinymist::ci / build-vscode (push) Blocked by required conditions
tinymist::ci / build-vscode-others (push) Blocked by required conditions
tinymist::ci / publish-vscode (push) Blocked by required conditions
tinymist::gh_pages / build-gh-pages (push) Waiting to run
Some checks are pending
tinymist::ci / Duplicate Actions Detection (push) Waiting to run
tinymist::ci / Check Clippy, Formatting, Completion, Documentation, and Tests (Linux) (push) Waiting to run
tinymist::ci / Check Minimum Rust version and Tests (Windows) (push) Waiting to run
tinymist::ci / E2E Tests (darwin-arm64 on macos-latest) (push) Blocked by required conditions
tinymist::ci / E2E Tests (linux-x64 on ubuntu-22.04) (push) Blocked by required conditions
tinymist::ci / E2E Tests (linux-x64 on ubuntu-latest) (push) Blocked by required conditions
tinymist::ci / E2E Tests (win32-x64 on windows-2022) (push) Blocked by required conditions
tinymist::ci / E2E Tests (win32-x64 on windows-latest) (push) Blocked by required conditions
tinymist::ci / prepare-build (push) Waiting to run
tinymist::ci / build-binary (push) Blocked by required conditions
tinymist::ci / build-vsc-assets (push) Blocked by required conditions
tinymist::ci / build-vscode (push) Blocked by required conditions
tinymist::ci / build-vscode-others (push) Blocked by required conditions
tinymist::ci / publish-vscode (push) Blocked by required conditions
tinymist::gh_pages / build-gh-pages (push) Waiting to run
* fix: pdf docs * fix: dirty change * fix: pollyfill theme-box * fix: pollyfill rules * fix: rules * fix: again * fix: 2019 retired
This commit is contained in:
parent
eedcbc477c
commit
9ca77d5382
7 changed files with 380 additions and 160 deletions
6
.github/workflows/build-vsc-assets.yml
vendored
6
.github/workflows/build-vsc-assets.yml
vendored
|
@ -42,6 +42,12 @@ jobs:
|
|||
curl -L https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.1.2/font-assets.tar.gz | tar -xvz -C assets/fonts
|
||||
curl -L https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.1.0/charter-font-assets.tar.gz | tar -xvz -C assets/fonts
|
||||
curl -L https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.1.5/source-han-serif-font-assets.tar.gz | tar -xvz -C assets/fonts
|
||||
- name: Download & install shiroa
|
||||
run: |
|
||||
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.3.1-rc3/shiroa-installer.sh | sh
|
||||
- name: Build Book
|
||||
run: |
|
||||
shiroa build --font-path ./assets/typst-fonts/ --font-path ./assets/fonts/ --path-to-root /tinymist/ -w . docs/tinymist --mode=static-html
|
||||
- name: Build PDF Documentation
|
||||
run: |
|
||||
prebuilts/tinymist compile --font-path assets/fonts --root . docs/tinymist/ebook.typ tinymist-docs.pdf
|
||||
|
|
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -103,7 +103,7 @@ jobs:
|
|||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-2019
|
||||
- os: windows-2022
|
||||
rust-target: x86_64-pc-windows-msvc
|
||||
platform: win32
|
||||
arch: x64
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
// #get-book-meta()
|
||||
|
||||
// re-export page template
|
||||
#import "/typ/templates/page.typ": project, is-md-target
|
||||
#import "/typ/templates/page.typ": is-md-target, project
|
||||
#let book-page = project
|
||||
#let cross-link = if is-md-target {
|
||||
let md-cross-link(lnk, reference: none, content) = {
|
||||
|
|
|
@ -6,5 +6,7 @@
|
|||
|
||||
#show: ebook.project.with(title: [Tinymist Documentation (v#tinymist-package.version)], spec: "book.typ")
|
||||
|
||||
#external-book(spec: include "/docs/tinymist/book.typ")
|
||||
|
||||
// set a resolver for inclusion
|
||||
#ebook.resolve-inclusion(it => include it)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#import "@preview/shiroa:0.2.3": *
|
||||
#import "/typ/templates/page.typ": project, part-style, heading-sizes, main-color
|
||||
#import "/typ/templates/page.typ": heading-sizes, main-color, part-style, project
|
||||
#import "tinymist-version.typ": tinymist-package
|
||||
|
||||
#let _page-project = project
|
||||
|
@ -8,7 +8,7 @@
|
|||
|
||||
#let resolve-inclusion(inc) = _resolve-inclusion-state.update(it => inc)
|
||||
|
||||
#let project(title: "", authors: (), spec: "", content) = {
|
||||
#let project(title: "", authors: (), spec: "", body) = {
|
||||
// Set document metadata early
|
||||
set document(
|
||||
author: authors,
|
||||
|
@ -31,13 +31,11 @@
|
|||
[
|
||||
#tinymist-package.description
|
||||
|
||||
Visit tinymist repository: #link(tinymist-package.repository)[main branch, ] or #link(
|
||||
{
|
||||
tinymist-package.repository
|
||||
"/tree/v"
|
||||
tinymist-package.version
|
||||
},
|
||||
)[v#tinymist-package.version.]
|
||||
Visit tinymist repository: #link(tinymist-package.repository)[main branch, ] or #link({
|
||||
tinymist-package.repository
|
||||
"/tree/v"
|
||||
tinymist-package.version
|
||||
})[v#tinymist-package.version.]
|
||||
]
|
||||
|
||||
{
|
||||
|
@ -66,7 +64,11 @@
|
|||
show link: set text(fill: main-color)
|
||||
|
||||
if has-part == none {
|
||||
outline-counter.step(level: it.level + 1)
|
||||
if it.element.numbering == none {
|
||||
outline-counter.step(level: it.level + 1)
|
||||
} else {
|
||||
outline-counter.step(level: it.level + 2)
|
||||
}
|
||||
layout(shape => {
|
||||
context {
|
||||
let lnk = link(it.element.location(), [#outline-counter.display(outline-numbering) #it.element.body])
|
||||
|
@ -88,10 +90,10 @@
|
|||
outline(depth: 1)
|
||||
}
|
||||
|
||||
body
|
||||
|
||||
context {
|
||||
let inc = _resolve-inclusion-state.final()
|
||||
external-book(spec: inc(spec))
|
||||
|
||||
let mt = book-meta-state.final()
|
||||
let styles = (inc: inc, part: part-style, chapter: it => it)
|
||||
|
||||
|
@ -99,6 +101,4 @@
|
|||
mt.summary.map(it => visit-summary(it, styles)).sum()
|
||||
}
|
||||
}
|
||||
|
||||
content
|
||||
}
|
||||
|
|
|
@ -1,21 +1,14 @@
|
|||
// This is important for shiroa to produce a responsive layout
|
||||
// and multiple targets.
|
||||
#import "@preview/shiroa:0.2.3": (
|
||||
get-page-width,
|
||||
target,
|
||||
is-web-target,
|
||||
is-pdf-target,
|
||||
is-html-target,
|
||||
plain-text,
|
||||
shiroa-sys-target,
|
||||
templates,
|
||||
get-page-width, is-html-target, is-pdf-target, is-web-target, plain-text, shiroa-sys-target, target, templates,
|
||||
)
|
||||
#import templates: *
|
||||
#import "@preview/numbly:0.1.0": numbly
|
||||
#import "theme.typ": *
|
||||
|
||||
#let use-theme = "starlight"
|
||||
#let is-starlight-theme = use-theme == "starlight"
|
||||
#let web-theme = "starlight"
|
||||
#let is-starlight-theme = web-theme == "starlight"
|
||||
|
||||
// Metadata
|
||||
#let page-width = get-page-width()
|
||||
|
@ -25,11 +18,22 @@
|
|||
#let is-md-target = target == "md"
|
||||
#let sys-is-html-target = ("target" in dictionary(std))
|
||||
|
||||
#let part-counter = counter("shiroa-part-counter")
|
||||
/// Creates an embedded block typst frame.
|
||||
#let div-frame(content, attrs: (:), tag: "div") = html.elem(tag, html.frame(content), attrs: attrs)
|
||||
#let span-frame = div-frame.with(tag: "span")
|
||||
#let p-frame = div-frame.with(tag: "p")
|
||||
// Theme (Colors)
|
||||
#let themes = theme-box-styles-from(toml("theme-style.toml"), read: it => read(it))
|
||||
#let (
|
||||
default-theme: (
|
||||
style: theme-style,
|
||||
is-dark: is-dark-theme,
|
||||
is-light: is-light-theme,
|
||||
main-color: main-color,
|
||||
dash-color: dash-color,
|
||||
code-extra-colors: code-extra-colors,
|
||||
),
|
||||
) = themes;
|
||||
#let (
|
||||
default-theme: default-theme,
|
||||
) = themes;
|
||||
#let theme-box = theme-box.with(themes: themes)
|
||||
|
||||
// Fonts
|
||||
#let main-font = (
|
||||
|
@ -44,59 +48,85 @@
|
|||
"DejaVu Sans Mono",
|
||||
)
|
||||
|
||||
#let part-counter = counter("shiroa-part-counter")
|
||||
|
||||
#let md-equation-rules(body) = {
|
||||
// equation setting
|
||||
show math.equation: it => theme-box(
|
||||
tag: if it.block { "p" } else { "span" },
|
||||
theme => {
|
||||
set text(fill: if theme.is-dark { gh-dark-fg } else { theme.main-color })
|
||||
html.frame(it)
|
||||
},
|
||||
)
|
||||
|
||||
body
|
||||
}
|
||||
|
||||
// Sizes
|
||||
#let main-size = if is-web-target {
|
||||
16pt
|
||||
} else {
|
||||
10.5pt
|
||||
}
|
||||
// ,
|
||||
#let heading-sizes = (22pt, 18pt, 14pt, 12pt, main-size)
|
||||
#let heading-sizes = if is-web-target {
|
||||
(2, 1.5, 1.17, 1, 0.83).map(it => it * main-size)
|
||||
} else {
|
||||
(26pt, 22pt, 14pt, 12pt, main-size)
|
||||
}
|
||||
#let list-indent = 0.5em
|
||||
#let in-heading = state("shiroa:in-heading", false)
|
||||
|
||||
#let mdbook-heading-rule(it) = {
|
||||
let it = {
|
||||
set text(size: heading-sizes.at(it.level))
|
||||
if is-web-target {
|
||||
heading-hash(it, hash-color: dash-color)
|
||||
#let markup-rules(
|
||||
body,
|
||||
dash-color: none,
|
||||
web-theme: "starlight",
|
||||
main-size: main-size,
|
||||
heading-sizes: heading-sizes,
|
||||
list-indent: list-indent,
|
||||
starlight: "@preview/shiroa-starlight:0.2.3",
|
||||
) = {
|
||||
assert(dash-color != none, message: "dash-color must be set")
|
||||
|
||||
let is-starlight-theme = web-theme == "starlight"
|
||||
let in-heading = state("shiroa:in-heading", false)
|
||||
|
||||
let mdbook-heading-rule(it) = {
|
||||
let it = {
|
||||
set text(size: heading-sizes.at(it.level))
|
||||
if is-web-target {
|
||||
heading-hash(it, hash-color: dash-color)
|
||||
}
|
||||
|
||||
in-heading.update(true)
|
||||
it
|
||||
in-heading.update(false)
|
||||
}
|
||||
|
||||
in-heading.update(true)
|
||||
it
|
||||
in-heading.update(false)
|
||||
block(
|
||||
spacing: 0.7em * 1.5 * 1.2,
|
||||
below: 0.7em * 1.2,
|
||||
it,
|
||||
)
|
||||
}
|
||||
|
||||
block(
|
||||
spacing: 0.7em * 1.5 * 1.2,
|
||||
below: 0.7em * 1.2,
|
||||
it,
|
||||
)
|
||||
}
|
||||
let starlight-heading-rule(it) = context if shiroa-sys-target() == "html" {
|
||||
import starlight: builtin-icon
|
||||
|
||||
#let starlight-heading-rule(it) = context if shiroa-sys-target() == "html" {
|
||||
// // Render a dash to hint headings instead of bolding it as well.
|
||||
// show link: static-heading-link(it)
|
||||
// // Render the heading hash
|
||||
// heading-hash(it, hash-color: dash-color)
|
||||
in-heading.update(true)
|
||||
html.elem("div", attrs: (class: "sl-heading-wrapper level-h" + str(it.level + 1)))[
|
||||
#it
|
||||
#html.elem(
|
||||
"h" + str(it.level + 1),
|
||||
attrs: (class: "sl-heading-anchor not-content", role: "presentation"),
|
||||
static-heading-link(it, body: builtin-icon("anchor"), canonical: true),
|
||||
)
|
||||
]
|
||||
in-heading.update(false)
|
||||
} else {
|
||||
mdbook-heading-rule(it)
|
||||
}
|
||||
|
||||
import "@preview/shiroa-starlight:0.2.3": builtin-icon
|
||||
|
||||
in-heading.update(true)
|
||||
html.elem("div", attrs: (class: "sl-heading-wrapper level-h" + str(it.level + 1)))[
|
||||
#it
|
||||
#html.elem(
|
||||
"h" + str(it.level + 1),
|
||||
attrs: (class: "sl-heading-anchor not-content", role: "presentation"),
|
||||
static-heading-link(it, body: builtin-icon("anchor"), canonical: true),
|
||||
)
|
||||
]
|
||||
in-heading.update(false)
|
||||
} else {
|
||||
mdbook-heading-rule(it)
|
||||
}
|
||||
|
||||
#let markup-rules(body) = {
|
||||
// Set main spacing
|
||||
set enum(
|
||||
indent: list-indent * 0.618,
|
||||
|
@ -125,8 +155,95 @@
|
|||
body
|
||||
}
|
||||
|
||||
#let code-block-rules(body, code-font: none, themes: none, set-raw-theme: none, zebraw: "@preview/zebraw:0.5.2") = {
|
||||
import zebraw: zebraw-init, zebraw
|
||||
#let equation-rules(
|
||||
body,
|
||||
web-theme: "starlight",
|
||||
theme-box: none,
|
||||
) = {
|
||||
// import "supports-html.typ": add-styles
|
||||
let is-starlight-theme = web-theme == "starlight"
|
||||
let in-heading = state("shiroa:in-heading", false)
|
||||
|
||||
/// Creates an embedded block typst frame.
|
||||
let div-frame(content, attrs: (:), tag: "div") = html.elem(tag, html.frame(content), attrs: attrs)
|
||||
let span-frame = div-frame.with(tag: "span")
|
||||
let p-frame = div-frame.with(tag: "p")
|
||||
|
||||
|
||||
let get-main-color(theme) = {
|
||||
if is-starlight-theme and theme.is-dark and in-heading.get() {
|
||||
white
|
||||
} else {
|
||||
theme.main-color
|
||||
}
|
||||
}
|
||||
|
||||
show math.equation: set text(weight: 400)
|
||||
show math.equation.where(block: true): it => context if shiroa-sys-target() == "html" {
|
||||
theme-box(tag: "div", theme => {
|
||||
set text(fill: get-main-color(theme))
|
||||
p-frame(attrs: ("class": "block-equation", "role": "math"), it)
|
||||
})
|
||||
} else {
|
||||
it
|
||||
}
|
||||
show math.equation.where(block: false): it => context if shiroa-sys-target() == "html" {
|
||||
theme-box(tag: "span", theme => {
|
||||
set text(fill: get-main-color(theme))
|
||||
span-frame(attrs: (class: "inline-equation", "role": "math"), it)
|
||||
})
|
||||
} else {
|
||||
it
|
||||
}
|
||||
|
||||
// add-styles(
|
||||
// ```css
|
||||
// .inline-equation {
|
||||
// display: inline-block;
|
||||
// width: fit-content;
|
||||
// }
|
||||
// .block-equation {
|
||||
// display: grid;
|
||||
// place-items: center;
|
||||
// overflow-x: auto;
|
||||
// }
|
||||
// ```,
|
||||
// )
|
||||
body
|
||||
}
|
||||
|
||||
#let code-block-rules(
|
||||
body,
|
||||
web-theme: "starlight",
|
||||
code-font: none,
|
||||
themes: none,
|
||||
zebraw: "@preview/zebraw:0.5.5",
|
||||
) = {
|
||||
import zebraw: zebraw, zebraw-init
|
||||
|
||||
let with-raw-theme = (theme, it) => {
|
||||
if theme.len() > 0 {
|
||||
raw(
|
||||
align: it.align,
|
||||
tab-size: 2,
|
||||
block: it.block,
|
||||
lang: it.lang,
|
||||
syntaxes: it.syntaxes,
|
||||
theme: theme,
|
||||
it.text,
|
||||
)
|
||||
} else {
|
||||
raw(
|
||||
align: it.align,
|
||||
tab-size: 2,
|
||||
block: it.block,
|
||||
lang: it.lang,
|
||||
syntaxes: it.syntaxes,
|
||||
theme: auto,
|
||||
it.text,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
let (
|
||||
default-theme: (
|
||||
|
@ -176,23 +293,20 @@
|
|||
tag: "div",
|
||||
inline: false,
|
||||
) = {
|
||||
theme-box(
|
||||
tag: tag,
|
||||
theme => {
|
||||
show: init-with-theme(theme)
|
||||
let code-extra-colors = theme.code-extra-colors
|
||||
let use-fg = not inline and code-extra-colors.fg != none
|
||||
set text(fill: code-extra-colors.fg) if use-fg
|
||||
set text(fill: if theme.is-dark { rgb("dfdfd6") } else { black }) if not use-fg
|
||||
set par(justify: false)
|
||||
zebraw(
|
||||
block-width: 100%,
|
||||
// line-width: 100%,
|
||||
wrap: false,
|
||||
set-raw-theme(theme.style.code-theme, it),
|
||||
)
|
||||
},
|
||||
)
|
||||
theme-box(tag: tag, theme => {
|
||||
show: init-with-theme(theme)
|
||||
let code-extra-colors = theme.code-extra-colors
|
||||
let use-fg = not inline and code-extra-colors.fg != none
|
||||
set text(fill: code-extra-colors.fg) if use-fg
|
||||
set text(fill: if theme.is-dark { rgb("dfdfd6") } else { black }) if not use-fg
|
||||
set par(justify: false)
|
||||
zebraw(
|
||||
block-width: 100%,
|
||||
// line-width: 100%,
|
||||
wrap: false,
|
||||
with-raw-theme(theme.style.code-theme, it),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
show raw: set text(font: code-font) if code-font != none
|
||||
|
@ -202,54 +316,17 @@
|
|||
mk-raw(it, tag: "span", inline: true)
|
||||
}
|
||||
show raw.where(block: true, tab-size: 114): it => context if shiroa-sys-target() == "paged" {
|
||||
show raw: set-raw-theme.with(theme-style.code-theme)
|
||||
rect(
|
||||
width: 100%,
|
||||
inset: (x: 4pt, y: 5pt),
|
||||
radius: 4pt,
|
||||
fill: code-extra-colors.bg,
|
||||
[
|
||||
#set text(fill: code-extra-colors.fg) if code-extra-colors.fg != none
|
||||
#set par(justify: false)
|
||||
#it
|
||||
],
|
||||
)
|
||||
rect(width: 100%, inset: (x: 4pt, y: 5pt), radius: 4pt, fill: code-extra-colors.bg, {
|
||||
set text(fill: code-extra-colors.fg) if code-extra-colors.fg != none
|
||||
set par(justify: false)
|
||||
with-raw-theme(theme-style.code-theme, it)
|
||||
})
|
||||
} else {
|
||||
mk-raw(it)
|
||||
}
|
||||
body
|
||||
}
|
||||
|
||||
#let equation-rules(body) = {
|
||||
// equation setting
|
||||
show math.equation: set text(weight: 400)
|
||||
show math.equation.where(block: true): it => context if shiroa-sys-target() == "html" {
|
||||
div-frame(attrs: ("style": "display: flex; justify-content: center; overflow-x: auto;"), it)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
show math.equation.where(block: false): it => context if shiroa-sys-target() == "html" {
|
||||
span-frame(attrs: ("style": "overflow-x: auto;"), it)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
|
||||
body
|
||||
}
|
||||
|
||||
#let md-equation-rules(body) = {
|
||||
// equation setting
|
||||
show math.equation: it => theme-box(
|
||||
tag: if it.block { "p" } else { "span" },
|
||||
theme => {
|
||||
set text(fill: if theme.is-dark { gh-dark-fg } else { theme.main-color })
|
||||
html.frame(it)
|
||||
},
|
||||
)
|
||||
|
||||
body
|
||||
}
|
||||
|
||||
/// The project function defines how your document looks.
|
||||
/// It takes your content and some metadata and formats it.
|
||||
/// Go ahead and customize it to your liking!
|
||||
|
@ -301,7 +378,6 @@
|
|||
starlight.with(
|
||||
include "/docs/tinymist/book.typ",
|
||||
title: title,
|
||||
site-title: [Tinymist Docs],
|
||||
description: description,
|
||||
github-link: "https://github.com/Myriad-Dreamin/tinymist",
|
||||
)
|
||||
|
@ -320,13 +396,21 @@
|
|||
show: if is-md-target {
|
||||
it => it
|
||||
} else {
|
||||
markup-rules
|
||||
markup-rules.with(web-theme: web-theme, dash-color: dash-color)
|
||||
}
|
||||
show: if is-md-target {
|
||||
it => it
|
||||
} else {
|
||||
it => {
|
||||
set heading(numbering: "1.") if is-pdf-target and not is-main
|
||||
it
|
||||
}
|
||||
}
|
||||
|
||||
show: if is-md-target {
|
||||
md-equation-rules
|
||||
} else {
|
||||
equation-rules
|
||||
equation-rules.with(theme-box: theme-box)
|
||||
}
|
||||
|
||||
show: if is-md-target {
|
||||
|
@ -336,29 +420,6 @@
|
|||
zebraw: "@preview/zebraw:0.5.5",
|
||||
themes: themes,
|
||||
code-font: code-font,
|
||||
set-raw-theme: (theme, it) => {
|
||||
if theme.len() > 0 {
|
||||
raw(
|
||||
align: it.align,
|
||||
tab-size: 2,
|
||||
block: it.block,
|
||||
lang: it.lang,
|
||||
syntaxes: it.syntaxes,
|
||||
theme: theme,
|
||||
it.text,
|
||||
)
|
||||
} else {
|
||||
raw(
|
||||
align: it.align,
|
||||
tab-size: 2,
|
||||
block: it.block,
|
||||
lang: it.lang,
|
||||
syntaxes: it.syntaxes,
|
||||
theme: auto,
|
||||
it.text,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -378,7 +439,7 @@
|
|||
}
|
||||
|
||||
if kind == "page" and is-pdf-target and not is-main {
|
||||
heading(level: 1, numbering: none, text(size: 32pt, title))
|
||||
text(size: 32pt, heading(level: 1, numbering: none, title))
|
||||
}
|
||||
|
||||
// Main body.
|
||||
|
@ -386,6 +447,17 @@
|
|||
|
||||
body
|
||||
|
||||
// todo: ...
|
||||
// Put your custom CSS here.
|
||||
// add-styles(
|
||||
// ```css
|
||||
// .site-title {
|
||||
// font-size: 1.2rem;
|
||||
// font-weight: 600;
|
||||
// font-style: italic;
|
||||
// }
|
||||
// ```,
|
||||
|
||||
// Put your custom CSS here.
|
||||
context if shiroa-sys-target() == "html" {
|
||||
html.elem(
|
||||
|
|
|
@ -1,9 +1,149 @@
|
|||
#import "@preview/shiroa:0.2.3": templates, book-sys
|
||||
#import "@preview/shiroa:0.2.3": book-sys, templates
|
||||
#import templates: *
|
||||
#import "target.typ": sys-is-html-target, is-md-target
|
||||
#import "target.typ": is-md-target, sys-is-html-target
|
||||
|
||||
/// Reads a theme from a preset dictionary and returns a structured theme object.
|
||||
///
|
||||
/// - preset (dictionary): A dictionary containing theme presets.
|
||||
/// - xml (function): (Deprecated, passing `read` intead) A function to parse XML data.
|
||||
/// - read (function): A function to read theme files.
|
||||
/// - target (string): The target platform or style, such as "web-light", "web-dark", or "pdf".
|
||||
/// -> dictionary
|
||||
#let book-theme-from(preset, xml: xml, read: none, target: target) = {
|
||||
// todo: move theme style parser to another lib file
|
||||
let theme-target = if target.contains("-") {
|
||||
target.split("-").at(1)
|
||||
} else {
|
||||
"light"
|
||||
}
|
||||
let theme-style = preset.at(theme-target)
|
||||
|
||||
let is-dark-theme = theme-style.at("color-scheme") == "dark"
|
||||
let is-light-theme = not is-dark-theme
|
||||
|
||||
let main-color = rgb(theme-style.at("main-color"))
|
||||
let dash-color = rgb(theme-style.at("dash-color"))
|
||||
|
||||
let code-theme-file = theme-style.at("code-theme")
|
||||
|
||||
let code-extra-colors = if code-theme-file.len() > 0 {
|
||||
if read != none {
|
||||
theme-style.insert("code-theme", bytes(read(code-theme-file)))
|
||||
}
|
||||
let data = xml(theme-style.at("code-theme")).first()
|
||||
|
||||
let find-child(elem, tag) = {
|
||||
elem.children.find(e => "tag" in e and e.tag == tag)
|
||||
}
|
||||
|
||||
let find-kv(elem, key, tag) = {
|
||||
let idx = elem.children.position(e => "tag" in e and e.tag == "key" and e.children.first() == key)
|
||||
elem.children.slice(idx).find(e => "tag" in e and e.tag == tag)
|
||||
}
|
||||
|
||||
let plist-dict = find-child(data, "dict")
|
||||
let plist-array = find-child(plist-dict, "array")
|
||||
let theme-setting = find-child(plist-array, "dict")
|
||||
let theme-setting-items = find-kv(theme-setting, "settings", "dict")
|
||||
let background-setting = find-kv(theme-setting-items, "background", "string")
|
||||
let foreground-setting = find-kv(theme-setting-items, "foreground", "string")
|
||||
(bg: rgb(background-setting.children.first()), fg: rgb(foreground-setting.children.first()))
|
||||
} else {
|
||||
(bg: rgb(239, 241, 243), fg: none)
|
||||
}
|
||||
|
||||
|
||||
(
|
||||
style: theme-style,
|
||||
is-dark: is-dark-theme,
|
||||
is-light: is-light-theme,
|
||||
main-color: main-color,
|
||||
dash-color: dash-color,
|
||||
code-extra-colors: code-extra-colors,
|
||||
)
|
||||
}
|
||||
|
||||
/// Reads themes from a preset dictionary and returns structured theme objects.
|
||||
///
|
||||
/// - preset (dictionary): A dictionary containing theme presets.
|
||||
/// - read (function): A function to read theme files.
|
||||
/// - target (string): The target platform or style, such as "web-light", "web-dark", or "pdf".
|
||||
/// -> dictionary
|
||||
#let theme-box-styles-from(
|
||||
preset,
|
||||
read: read,
|
||||
target: target,
|
||||
light-theme: none,
|
||||
dark-theme: none,
|
||||
) = {
|
||||
let sys-is-html-target = ("target" in dictionary(std))
|
||||
|
||||
if light-theme == none {
|
||||
for (name, it) in preset.pairs() {
|
||||
if it.at("color-scheme") == "light" {
|
||||
light-theme = name
|
||||
}
|
||||
}
|
||||
}
|
||||
if dark-theme == none {
|
||||
for (name, it) in preset.pairs() {
|
||||
if it.at("color-scheme") == "dark" and dark-theme != "ayu" {
|
||||
dark-theme = name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if light-theme == none {
|
||||
light-theme = "light"
|
||||
}
|
||||
if dark-theme == none {
|
||||
dark-theme = "dark"
|
||||
}
|
||||
|
||||
let book-theme-from = book-theme-from.with(xml: xml, read: read)
|
||||
|
||||
// Theme (Colors)
|
||||
let dark-theme = book-theme-from(preset, target: "web-" + dark-theme)
|
||||
let light-theme = book-theme-from(preset, target: if sys-is-html-target { "web-" + light-theme } else { "pdf" })
|
||||
let default-theme = book-theme-from(preset, target: target)
|
||||
|
||||
(
|
||||
dark-theme: dark-theme,
|
||||
light-theme: light-theme,
|
||||
default-theme: default-theme,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
#let theme-box(render, tag: "div", themes: none, class: none, theme-tag: none) = {
|
||||
let (
|
||||
dark-theme: dark-theme,
|
||||
light-theme: light-theme,
|
||||
default-theme: default-theme,
|
||||
) = themes
|
||||
let is-md-target = target == "md"
|
||||
let sys-is-html-target = ("target" in dictionary(std))
|
||||
|
||||
if is-md-target {
|
||||
show: html.elem.with(tag)
|
||||
show: html.elem.with("picture")
|
||||
html.elem("m1source", attrs: (media: "(prefers-color-scheme: dark)"), render(dark-theme))
|
||||
render(light-theme)
|
||||
} else if sys-is-html-target {
|
||||
if theme-tag == none {
|
||||
theme-tag = tag
|
||||
}
|
||||
html.elem(tag, attrs: (class: "code-image themed" + if class != none { " " + class }), {
|
||||
html.elem(theme-tag, render(dark-theme), attrs: (class: "dark"))
|
||||
html.elem(theme-tag, render(light-theme), attrs: (class: "light"))
|
||||
})
|
||||
} else {
|
||||
render(default-theme)
|
||||
}
|
||||
}
|
||||
|
||||
// Theme (Colors)
|
||||
#let themes = theme-box-styles-from(toml("theme-style.toml"), xml: it => xml(it))
|
||||
#let themes = theme-box-styles-from(toml("theme-style.toml"), read: it => read(it))
|
||||
#let (
|
||||
default-theme: (
|
||||
style: theme-style,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue