#mdbook

需要mdbook init --theme获取theme文件夹

字体调整

book.toml中新增对应配置, additional-css中新增"./theme/custom.css" 通过css进行配置

页面主题

./theme/css/variables.css中增加主题配置 ./theme/index.hbs, <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">中增加对应的theme

代码配色

如果使用了自定义主题, 代码配色基本上会使用highlight.css 需要在./theme/book.jsset_theme中进行硬编码的配置, 需要注意theme名称的大小写

mdbook-pagetoc - 页面内md小节导航

https://github.com/JorelAli/mdBook-pagetoc

./tehme中新增pagetoc.jspagetoc.css
book.toml中新增对应的[output.html]配置:

additional-css = ["./theme/pagetoc.css"]
additional-js = ["./theme/pagetoc.js"]
<div id="content" class="content">
    <main>
        <div class="content-wrap">
            {{{ content }}}
        </div>
        <div class="sidetoc">
            <nav class="pagetoc"></nav>
        </div>
    </main>
<div>

目前(20250313) mdbook-pagetoc明确支持至mdbook0.4.43, 还不支持0.4.45

highlight.js

highlight.min.js无法直接从repo中构建出来, 需要到 https://highlightjs.org/download/ 下载
选择语言并下载侯得到的highlight.min.js就已经包含了所选语言, 替换mdbook theme中的highlight.js即可

scheme highlight

其中scheme的lambda, define等关键字被分进built_in类型了, 可以改为keyword类型 参考

(() => {
    var e = (() => {
        "use strict"; return e => {
            const t = "[^\\(\\)\\[\\]\\{\\}\",'`;#|\\\\\\s]+", n = "(-|\\+)?\\d+([./]\\d+)?", r = {
                $pattern: t,
                built_in: "case-lambda call/cc class define-class exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax-case syntax-error unit/sig unless when with-syntax call-with-current-continuation call-with-input-file call-with-output-file define-syntax dynamic-wind for-each let-syntax letrec-syntax map syntax-rules ' * + , ,@ - ... / ; < <= = => > >= ` abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-input-file call-with-output-file call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero?",
                keyword: "define lambda let let* letrec if else cond case begin and or delay do quote quasiquote quasisyntax set! syntax unquote unquote-slicing unsyntax unsyntax-splicing"
            }, a = { className: "literal", begin: "(#t|#f|#\\\\" + t + "|#\\\\.)" }, i = {
                className: "number", variants: [{ begin: n, relevance: 0 }, {
                    begin: n + "[+\\-]" + n + "i",
                    relevance: 0
                }, { begin: "#b[0-1]+(/[0-1]+)?" }, { begin: "#o[0-7]+(/[0-7]+)?" }, {
                    begin: "#x[0-9a-f]+(/[0-9a-f]+)?"
                }]
            }, c = e.QUOTE_STRING_MODE, s = [e.COMMENT(";", "$", {
                relevance: 0
            }), e.COMMENT("#\\|", "\\|#")], l = { begin: t, relevance: 0 }, o = {
                className: "symbol", begin: "'" + t
            }, g = { endsWithParent: !0, relevance: 0 }, u = {
                variants: [{
                    begin: /'/
                }, { begin: "`" }], contains: [{
                    begin: "\\(", end: "\\)",
                    contains: ["self", a, c, i, l, o]
                }]
            }, d = {
                className: "name", relevance: 0, begin: t,
                keywords: r
            }, p = {
                variants: [{ begin: "\\(", end: "\\)" }, { begin: "\\[", end: "\\]" }],
                contains: [{
                    begin: /lambda/, endsWithParent: !0, returnBegin: !0, contains: [d, {
                        endsParent: !0, variants: [{ begin: /\(/, end: /\)/ }, { begin: /\[/, end: /\]/ }],
                        contains: [l]
                    }]
                }, d, g]
            }; 
            return g.contains = [a, i, c, l, o, u, p].concat(s), {
                name: "Scheme", aliases: ["scm"], illegal: /\S/,
                contains: [e.SHEBANG(), i, c, o, u, p].concat(s)
            }
        }
    })()
    ; hljs.registerLanguage("scheme", e)
})();