Sphinx: List of supported languages for highlighting? - documentation-generation

I'm using Sphinx for code documentation and use several languages within the code, I would like to setup highlighting for all of that code. Sphinx briefly mentions a few of the languages it supports (on this page), and then mentions that it uses Pygments for lexical analysis and highlighting. Sifting through the documentation for both Sphinx and Pygments yielded me no clue on how to do something like highlight objective-c code.
Pygments does mention the list of languages it supports, here, however that doesn't tell me the exact syntax that I must use within Sphinx (.rst files) to tell the code block to highlight for a specific language. For example, to highlight c++ code you simply use this before your code block:
.. highlight:: c++
However after trying these I cannot seem to highlight Objective-C code:
.. highlight:: Objective-C
.. highlight:: objective-c
.. highlight:: Obj-C
.. highlight:: obj-c
Can anyone supply me with the list of languages (as you would refer to them within documentation)?

pygmentize -L lexers lists all supported lexers.
http://pygments.org/languages/
http://pygments.org/docs/lexers/
http://pygments.org/docs/cmdline/#getting-help

As far as I can tell, the list is in the file pygments/lexers/_mapping.py, in the (autogenerated) dictionary LEXERS. In my copy, I see a line
'ObjectiveCLexer': ('pygments.lexers.compiled', 'Objective-C', ('objective-c', 'objectivec', 'obj-c', 'objc'), ('*.m',), ('text/x-objective-c',)),
I think this should mean that any of the tags objective-c, objectivec, obj-c, or objc should work, as long as your version of Pygments is up-to-date. They work for me.

If you install pygments module. You can use this script to get a list of supported highlighters:
from pygments.lexers import get_all_lexers
lexers = get_all_lexers()
for lexer in lexers:
print "-\t" + lexer[0] + "\n"
print "\t-\t" + "\n\t-\t".join(lexer[1]) + "\n"
First indent level of output will be general name and second level will be short names of highlighters that you can use.
Example Output
Debian Sourcelist
sourceslist
sources.list
Delphi
delphi
pas
pascal
objectpascal
Source

Related

How to add a custom tmLanguage syntax to Sphinx/RST

Is there a method to import a tmLanguage.json into Sphinx to add support for a new/custom language for RST?
There is not directly; if necessary you'll have to write a lexer for a new language in Python. I say if necessary because Sphinx's syntax highlighting is provided under the hood by Pygments, which supports a huge number of languages; you just need to turn support on in Sphinx using the highlight_language config value. The short names for all the various lexers are shown here.
If, somehow, your language doesn't have a lexer already, there are instructions on how to write your own. It's largely (but not entirely) a process of translating the Oniguruma regexes in the .tmLanguage.json file to Python-flavored ones.
One would also hope that you'd contribute it to the pygments Github project, too.

Sublime text 3 ugly syntax highlighting

I'm learning Ruby and I'm using Sublime Text 3 but I find the syntax highlighting really strange.
For example :
Ugly syntax
Even after setting the syntax to ruby.
Ruby syntax set
I'd like to know if this is normal, or if I need to change something on the users
settings or something like that.
The syntax file for Ruby (Ruby.sublime-syntax) contains a list of unresolved issues. Among them is:
text:
"p << end
print me!
end"
symptoms:
not recognized as a heredoc
solution:
there is no way to distinguish perfectly between the << operator and the start
of a heredoc. Currently, we require assignment to recognize a heredoc. More
refinement is possible.
• Heredocs with indented terminators (<<-) are always distinguishable, however.
• Nested heredocs are not really supportable at present
So yeah, it's normal.
You could visit https://packagecontrol.io/ and use something like Railscast Colour Scheme
The basic syntax highlighting that comes w/ sublime is pretty sparse - these packages usually do a better job. Also this is just one example. There's plenty of themes and color schemes.
To install package control ctrl+ and past in the snippet according to your version of sublime from this page https://packagecontrol.io/installation#st3

A List of Google Prettify Language Codes

I cannot find this anywhere and I swear I used to be able to very simply without much prying. Can anyone help me? Thanks. I would appreciate it. Also, does prettify support Batch?
I thought it would be helpful to have an actual list rather than just a link. I found it in the loader directory that #MikeSamuel linked to from Javascript code prettifier. As the readme states, the prettify.js comments are the authoritative source. However, What is syntax highlighting and how does it work? provided a better formatted list, so I will copy that below. Refer to the the links for the most up-to-date information.
If you are using the Prettify codes to markup Stack Overflow code, you use
<!-- language: lang-or-tag-here -->
your code
Language Codes:
Let Prettify interpret the code and guess.
default
Explicitly do not use any syntax highlighting.
lang-none
Bash and other Shell scripting
lang-bash, lang-bsh, lang-csh, lang-sh
C, C++, et al
lang-c, lang-cc, lang-cpp, lang-cxx, lang-cyc, lang-m
C#
lang-cs
Clojure
lang-clj
CoffeeScript
lang-coffee
CSS
lang-css
Dart
lang-dart
Delphi
lang-pascal
Erlang
lang-erl, lang-erlang
Go
lang-go
Haskell
lang-hs
HTML
lang-html
Java
lang-java
JavaScript
lang-js, lang-javascript
JSON
lang-json
LaTeX and TeX
lang-latex, lang-tex
Lisp and Scheme
lang-cl, lang-el, lang-lisp, lang-lsp, lang-scm, lang-ss, lang-rkt
Lua
lang-lua
OCaml, SML, F#, et al
lang-fs, lang-ml
Pascal
lang-pascal
Perl
lang-pl, lang-perl
PHP
lang-php
Protocol buffers
lang-proto
Python
lang-py, lang-python, lang-cv
R and S
lang-r, lang-s
Regex
lang-regex
Ruby
lang-rb, lang-ruby
Rust
lang-rc, lang-rs, lang-rust
Scala
lang-scala
SQL
lang-sql
VHDL
lang-vhdl, lang-vhd
Visual Basic
lang-vb, lang-vbs
XML
lang-xml
You can find a table in the FAQ, under the header For which languages does it work?:
The comments in prettify.js are authoritative but the lexer should work on a number of languages including C and friends, Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, Makefiles, and Rust. It works passably on Ruby, PHP, VB, and Awk and a decent subset of Perl and Ruby, but, because of commenting conventions, but doesn't work on Smalltalk.
Other languages are supported via extensions: ...
You can find the handlers, with their extensions in the loader directory
For the mapping from extensions to builtin languages, see the registerLangHandler calls in prettify.js

Do you know an alternative ctags generator for Ruby

Exumerant Ctags does not work well with Ruby, you can see there are many hacks in the ruby.c code and basically it fails recognizing many cases. One of the most important is this bit:
class SomeModule::SomeClass
end
Ctags generates:
SomeModule someclass.rb /^class SomeModule::SomeClass$/;" c
which is wrong. The correct and expected entry is:
SomeClass someclass.rb /^class SomeModule::SomeClass$/;" c
This is very limiting. There are some patches for ctags available which does not work, e.g. https://github.com/xtao/overlay/blob/master/dev-util/ctags/files/ctags-5.5.4-ruby-classes.patch but looking on the ctags ruby codebase, this really needs complete rewrite.
So I have been playing with other option which is https://github.com/rdoc/rdoc-tags which works nicer, but it is slow. I mean really SLOW. Generating tags on my project is 2 seconds with ctags but one hour with this tool. Really.
I found one old project that was parsing Ruby on it's own and generating tags, but it was only for Ruby 1.8. It was slower than ctags, but not that bad.
So I am searching for some alternatives. Do you know about any other working ruby ctags generators which give you proper output and are fast?
Thanks!
Edit: I have found very nice project that works with Ruby 1.9+ and is accurate and fast. I recommend it:
https://github.com/tmm1/ripper-tags
Ripper-tags effort does solve everything described here. It is based on official Ruby parser which is also quite fast. https://github.com/tmm1/ripper-tags
gem install ripper-tags
cd your_project/
ripper-tags -R
It does also support Emacs as well.
Exuberant ctags out of the box doesn’t do a number of useful things:
It doesn’t deal with:
module A::B
It doesn’t tag (at least some of) the “operator” methods like ‘==’
It doesn’t support qualified tags, —type=+
It doesn’t output tags for constants or attributes.
Patch available, but it is only for version 5.5 and does not work anymore.
Other projects:
https://github.com/tmm1/ripper-tags (best option for Ruby 1.9+)
https://rubygems.org/gems/rdoc-tags (very slow but works with 1.8)
Source
Add following to your ~/.ctags
--regex-ruby=/(^|;)[ \t]*(class|module)[ \t]+([A-Z][[:alnum:]_]+(::[A-Z][[:alnum:]_]+)+)/\3/c,class,constant/
So you can:
deal with: module A::B
See more here: https://github.com/bltavares/dot-files/blob/master/ctags
A patch is available as of 2013-02
https://github.com/fishman/ctags (ctags patch for Ruby, including rspec)
the rspec tag generator will not properly recognize describe blocks that start with semicolor (:some-method), but other than that, it's great.
There is also https://github.com/eapache/starscope
It doesn't support the extended tag format (yet) but it does other things such as exporting cscope databases.

TeX compiler in ruby

I'm looking for a gem that allows to compile tex files (TeLaTeX or just LaTeX) into pdf. I don't need any templating or partial rendering, just simple compiler. Is there any bindings for latex2pdf or something.
Are you looking for a TeX-Compiler written in ruby or a ruby script, that calls LaTeX?
If you look for the 2nd one:
http://rubygems.org/gems/rake4latex
Defines a rake-task to generate a pdf, based on tex-sources. It checks, how many TeX-runs are needed, makeindex, bibtex... is done if required.
Supports splitindex, gloss...
Can be used with LaTeX, pdfLaTeX, XeLaTeX...
Can't you just call the command line directly with backtick notation?
`latex2pdf <options>`
It shows that TeX's syntax is so horrible flexible, that you actually will need TeX or any of its variants to interpret TeX files in general.
So actually calling the command line pdflatex or xelatex (or any wrapper around this, like in peakxu's answer) is the best bet here.
I have no idea if someone packaged a TeX distribution (like TeX Live) into a Ruby Gem, I suppose not.

Resources