Any Pygments lexer for the Mustache templating language? - syntax-highlighting

I'd like to list source code of Mustache templates in my paper, and I'm using the minted package for highlighting code in my LaTeX source. The minted package simply uses Pygments. But there isn't any Pygments lexer for Mustache at the moment. Does anyone know an easy solution for my use case? For example, is there any existing Mustache lexer that is implemented in Python and is ready to use for Pygments?
Any suggestion or thoughts will be highly appreciated!
Best, Nicole

There is already a Handlebars lexer which you can use, as Handlebars is more or less a superset of Mustache. I say “more or less” because, last time I checked, Handlebars did not have Inverted Selections. The lexer in Pygments does not seem to support them, either. If your code uses them, you should be able to easily implement your own Mustache lexer by extending HandlebarsLexer and HandlebarsHtmlLexer. See also https://pygments.org/docs/lexerdevelopment/.
Here is an example:
\documentclass[preview]{standalone}
\usepackage[newfloat]{minted}
\begin{document}
\begin{minted}{html+handlebars}
<div id="cart">
{{#cart_items}}
<div class="cart-item">
<span>{{name}}</span>
<span>{{quantity}}</span>
<span>{{price}}</span>
</div>
{{/cart_items}}
</div>
\end{minted}
\end{document}
Which results in:

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.

Javascript to FHIRPath

We have existing Form(s) with embedded javascript validation expressions. We are trying to convert these expressions to FHIRPath, so that we can embed them as FHIRPath expressions in our Questionnaire responses.
At present, we are attempting to parse these javascript blocks into FHIRPath, but it is challenging and does not seem to be the best way to proceed.
Are there any suggestions on how to tackle this - is there a Javascript to FHIRPath converter that could be used or any other solutions?
I don't think there is an existing javascript to fhirpath converter out there - haven't heard of one. If I were to go about doing this, I'd convert Javascript AST to FHIRpath, that would be the most foulproof way to do it. You can find quite a few libraries that can parse Javascript into AST out there.
In general, this is very difficult. FHIRPath and Javascript are just so radically different in how they go about things - an object based procedural language, and a path based query language with no variables. XPath --> FHIRPath, I could imagine trying to have a go at that. And FHIRPath --> Javascript, yes, I could imagine that too. but not the other way

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

ruby markdown processor that does footnotes?

Do any of the maintained decent ruby markdown processors do an extension for footnotes? I know some markdown processors in other languages do (although I'm not sure which ones).
The ruby ones aren't so great at documenting what markdown extensions they might support. (Heck, neither are the ones in other languages).
anyone know?
I have used kramdown, and it's my library of choice for markdown. It actually provides a superset of Markdown syntax, borrowing additional functionality from other libraries. For example, the footnote capability was borrowed from PHP Markdown Extra package.
Example syntax:
That's some text with a footnote.[^1]
[^1]: And that's the footnote.

How to build AST by S-expression in Ruby?

I have no idea how to build S-exp.
I want to do it, because I need to build AST for my langauge.
At the beginning I used RubyParser to parse it to sexp then code gen.
But it must be ruby's subset I think.I cant define the language what I want.
Now I need to implement parser for my language.
So anyone could recommend any ruby tool that building AST for S-expression ?
Thanks!
It is not very clear from your question what exactly do you need, but simple Google search gives some interesting links to check. Maybe after checking these links, if they are not the answer to your question, you can edit question and make it more precise and concrete.
http://thingsaaronmade.com/blog/writing-an-s-expression-parser-in-ruby.html
https://github.com/aarongough/sexpistol
You might try the sxp-ruby gem at http://github.com/bendiken/sxp-ruby. I use it for SPARQL S-Expressions (SSE) and similar methods for managing Abstract Syntax Trees in Ruby.
Maybe you could have a look at this gem named Astrapi.
This is just an experiment :
describe your language elements (concepts) in a "mm" file (abstract syntax)
run astrapi on this file
astrapi generates a parser that is able to fill up your AST, from your input source expressed in s-expression (concrete syntax of your concepts).
I have put a modest documentation here.

Resources