LoginSignup
0
0

sphinx:`code-block`ディレクティブに指定できる言語

Last updated at Posted at 2022-01-24

実行環境

  • Python 3.12.1
  • sphinx 7.3.7
  • Pygments 2.18.0

はじめに

sphinxのsphinxのcode-blockディレクティブでは、以下のようにhtmlなど言語を指定できます。

.. code-block:: html

    <img src="images/foo.png">

image.png

code-blockディレクティブで指定できる言語は、Pygmentsライブラリで提供しているlexerのエイリアスです。

The directive’s alias name sourcecode works as well. This directive takes a language name as an argument. It can be any lexer alias supported by Pygments.

具体的にどのような言語を指定できるか調べました。

Pygmentsのlexer alias

以下のドキュメントのShort namesがlexer aliasに対応します。

image.png

利用できるlexerの一覧は、以下のコードで取得できます。

from pygments.lexers import get_all_lexers
# `i[1]`は (name, aliases, filetypes, mimetypes) のaliases を選ぶため
alias_list = [i[1] for i in get_all_lexers()]
# 空のリストが存在したので、それを除外する
alias_list = [e for e in alias_list if len(e) > 0]

print(len(alias_list))
# 585

print(alias_list[0:10])
#[('abap',),
# ('amdgpu',),
# ('apl',),
# ('abnf',),
# ('actionscript3', 'as3'),
# ('actionscript', 'as'),
# ('ada', 'ada95', 'ada2005'),
# ('adl',),
# ('agda',),
# ('aheui',)]

lexerのaliasは全部で585個ありました。

lexar aliasで気になったこと

以下はPython関係のaliasです。

  ('pypylog', 'pypy'),
  ('python2', 'py2'),
  ('py2tb',),
  ('pycon', 'python-console'),
  ('python', 'py', 'sage', 'python3', 'py3', 'bazel', 'starlark'),
  ('pytb', 'py3tb'),
  ('py+ul4',),
  ['ipython2', 'ipython'],
  ['ipython3'],
  ['ipythonconsole']]

python-consoleipython3などコンソール用のaliasも用意されていました。

また、mojoは火の絵文字でも指定していできるようです。

('mojo', '🔥'),

lexar aliasの一覧

lexar aliasの一覧をgistに投稿しました。こちらを参照してください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0