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:
listings
and 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 onpygments
under the hood and it has built-in YAML support.listings
'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.key: value
andkey: "value"
are equivalent,value
is 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.