Help us understand the problem. What is going on with this article?

mix docs で生成されるドキュメントの見た目をカスタマイズする

More than 1 year has passed since last update.

独自のスタイルシート

mix docs コマンドは mix.exs に定義された project/0:docs エントリーに設定を書くことができる。:assets オプションと :before_closing_head_tag オプションを組み合わせることで、独自のスタイルシートを追加できる。

def project do
  [
    apps_path: "apps",
    build_embedded: Mix.env() == :prod,
    start_permanent: Mix.env() == :prod,
    aliases: aliases(),
    deps: deps(),

    # Docs
    name: "MyProject",
    docs: [
      assets: "etc/assets",
      before_closing_head_tag: &docs_before_closing_head_tag/1
    ]
  ]
end

etc/assets/doc.css を配置し、docs_before_closing_head_tag/1 関数は以下のように定義する。

defp docs_before_closing_head_tag(:html) do
  ~s{<link rel="stylesheet" href="assets/doc.css">}
end
defp docs_before_closing_head_tag(_), do: ""

各オプションの詳細は mix docs コマンドのリファレンスを参照してほしい。

HTML 要素のクラスや属性のカスタマイズ

ExDocs はデフォルトで pragdave/earmark を Markdown レンダラに使っており、独自拡張を使うと任意のブロック要素にクラスや属性を指定できる。たとえば、以下の例では、コードブロックの pre 要素に class="diagram" を指定している。

```
Code text
```
{: .diagram }
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away