AsciiDoctorでハイライトする方法。
開発環境
前回まで
AsciiDocとは
HTMLを出力するための軽量マークアップ言語。Markdownより高性能。
AsciiDoctorとは
AsciiDocからHTMLを出力するツール。Ruby製。
シンタックスハイライトとは
Syntax Highlight。各プログラミング言語の構文に応じてフォント書体や色を変える。ソースコードが見やすくなる。
AsciiDoctor最小コード
= test.asc :source-highlighter: highlightjs .test.py [source, python] ---- print('Hello Python !!') ----
変換
$ rbenv exec asciidoctor test.asc
HTML表示
off | on |
---|---|
ハイライト用ツール
ハイライター | 実行環境 | License | Copyright |
---|---|---|---|
coderay | Ruby | MIT | Copyright © 2005-2012 Kornelius Kalnbach murphy@rubychan.de (@murphy_karasu) |
highlightjs | JavaScript | BSD 3-clause | Copyright © 2006, Ivan Sagalaev |
prettify | JavaScript | Apache License 2.0 | Copyright 2011 Mike Samuel et al |
pygments | Python2 | MIT | Copyright © 2013 Pavan Kumar Sunkara |
rouge | Ruby | MIT | Copyright © 2012 Jeanine Adkisson. |
AsciiDocとハイライト用ツールの対応
ハイライター | 属性値 | Asciidoctor | AsciidoctorJ | Asciidoctor.js | Asciidoctor PDF |
---|---|---|---|---|---|
coderay | coderay |
✓ | ✓ | ✓ | |
highlightjs | highlightjs |
✓ | ✓ | ✓ | |
prettify | prettify |
✓ | ✓ | ✓ | |
pygments | pygments |
✓ | ✓ | ||
rouge | rouge |
✓ |
インストール
To use CodeRay, Pygments, or Rouge, you must have the appropriate library installed on your system. See the CodeRay or Pygments section to find installation instructions. (We don’t yet have a section about Rouge).
On the other hand, if you’re using a client-side syntax highlighting library like highlight.js or prettify, there’s no need to install additional libraries. The generated HTML will load the required source files from a CDN (or custom URL or file path).
JavaScript製ならインストール不要で使える。
所感
これで最低限ハイライトはできるはず。色など細かい調整はできるのだろうか?