I'm trying to highlight simple YAML (the markup language, not the CSS framework) code. I know that there is a solution using pygments and minted, however, I would prefer a solution with \lstdefinelanguage.
This is my code so far:
\lstdefinelanguage{yaml}{
keywords={true,false,null,y,n},
keywordstyle=\color{darkgray}\bfseries,
ndkeywords={},
ndkeywordstyle=\color{black}\bfseries,
identifierstyle=\color{black},
sensitive=false,
%moredelim=[l]{}{:},
comment=[l]{#},
morecomment=[s]{/*}{*/},
commentstyle=\color{purple}\ttfamily,
stringstyle=\color{blue}\ttfamily,
%morestring=[l]{-}{},
morestring=[b]',
morestring=[b]"
}
Two things are missing, though:
- I would like to print all keys bold
- I would like to print all strings, also the ones without qotes, to be blue.
I tried to accomplish these two things with the commented lines in the code above. Unfortunately, they did not work. Any suggestions on how I can make this work?
Here is a small YAML example:
key: value
map:
key1: value1
key2: value2
list:
- element1
- element2
# This is a comment
listOfMaps:
- key1: value1a
key2: value1b
- key1: value2a
key2: value2b
This is the output I currently get:


listingsand YAML in a manual I wrote; I used some delimiters in order to achieve syntax highlighting, but it's quite messy. Take a look atminted, it relies onpygmentsunder the hood and it has built-in YAML support. – Paulo Cereda Jan 07 '14 at 16:28listings'keywords, and set the style for those keywords as you wish. Not a very satisfying solution but viable if the number of distinct key names is small. – jub0bs Jan 07 '14 at 16:33key: valueandkey: "value"are equivalent,valueis a string for both. I would like to color strings, either with or without quotes, in the same color. I hope, this makes it clear. – Jan 07 '14 at 16:40key: valueandkey: "value"are indeed equivalent, but a value can only contain colon(s) if it's delimited by double quotes (see http://stackoverflow.com/questions/8783705/how-could-should-i-state-colon-punctuation-in-a-yaml-file). – jub0bs Jan 07 '14 at 16:47