mdbook preprocessor

mdbook-toc

mdbook-toc 將 html 註解的 toc 轉成目錄格式

install

cargo install mdbook-toc

book.toml

[preprocessor.toc]
command = "mdbook-toc"
renderer = ["html"]

最簡單 python 版本

Preprocessor in Python? #975 - mdbook

#[preprocessor.minipp]
# 
#command = "src/mdbook/preprocessor.py"
#command = "src/mdbook/preprocessor.sh"
#renderer = ["html"]

A minimal preprocessor in Python

#!/usr/bin/env python

import json
import sys

if len(sys.argv) > 1:
    if sys.argv[1] == 'supports':
        # sys.argv[2] is the renderer name
        sys.exit(0)

context, book = json.load(sys.stdin)
json.dump(book, sys.stdout)

A minimal preprocessor in Bash

#!/bin/bash
#
jq . | tee /tmp/dump.json

rootbook : python add tabs

GooFit/rootbook

注意:這 tabs 新語法可將多個區塊用 tab 呈現比較精簡 UI,但列印成 PDF 模式無法全部列印內容出來。

{{#tabs}}
{{#tab Classic ROOT}}
  blah
{{#tab Modern ROOT}}
  blah
{{#tab Python}}
  def f(x):
    return y
{{#endtabs}}

book.toml

[output.html]
additional-css = ["includes/css/tabs.css"]
additional-js = ["includes/js/tabs.js"]

[preprocessor.tabs]
command = "python3 ./plugins/transform_tabs.py"
renderer = ["html", "epub"]