0

Starting from the answer to this question YAML Syntax Highlighting.

If I wanted to have "- name:" colored blue and not black, and "test" colored in blue, how is this possible?

spec:
 containers:
  - name: test

1 Answers1

4

I needed to achieve a similar result, for a docker-compose YAML, and it was not immediate to find an answer. Anyway, this is a method that could allow you to achieve a result similar to the desired one:

  • Define a custom language similar to the following
\usepackage{listingsutf8}
\usepackage[usenames]{color}
\usepackage{xcolor}

\lstdefinelanguage{my-yaml}{ keywords={spec, containers, name}, % ,... all the keyword you want keywordstyle=\color{blue}\bfseries, moredelim=[is][commentstyle]{||}{££}, % invisible custom delimiters identifierstyle=\color{black}, sensitive=false, comment=[l]{#}, commentstyle=\color{olive}\ttfamily, stringstyle=\color{orange}\ttfamily, morestring=[b]', morestring=[b]" }

  • use it as follows
\begin{lstlisting}[language=my-yaml,caption={Docker Compose YAML composing the various containers of the setup together.},numbers=left]
spec:
 containers:
  - name: ||test££
\end{lstlisting}

This is the end result: end result