#StackBounty: #listings Line break in lstlisting inside of escaped text

Bounty: 50

I’ trying to fix the display of a line break inside an lstlisting environment, but more specifically in a part of the listing that is inside an escaped area:

documentclass{article}
usepackage[utf8]{inputenc}

usepackage[usenames,dvipsnames,table]{xcolor}
usepackage{listings}
lstset{}


definecolor{keywordColor}{HTML}{0033B3}
definecolor{parameterColor}{HTML}{067D17}
definecolor{commentColor}{HTML}{8C8C8C}
definecolor{scenarioColor}{HTML}{871094}

newcommand{lstKeyword}[1]{{textcolor{keywordColor}{#1}}}
newcommand{lstParameter}[1]{{textcolor{parameterColor}{#1}}}
newcommand{lstScenario}[1]{{textcolor{scenarioColor}{textit{#1}}}}

lstdefinestyle{bddStory}
{
  frame=single,
  captionpos=b,
  commentstyle=color{commentColor},
  keywordstyle=color{keywordColor},
  morekeywords={Given ,When ,Then ,And ,Narrative,Examples},
  escapeinside={<@}{@>},
  showspaces=false,
  showtabs=false,
  showstringspaces=false,
  breaklines=true,
  postbreak=mbox{textcolor{red}{$hookrightarrow$}space},
  breakatwhitespace=true
}

title{Example Issue}

begin{document}
begin{lstlisting}[style=bddStory]
<@lstScenario{Scenario: A scenario title is too long and can't fit into a single line which causes issues in the highlighting}@>
Given there is some further content
end{lstlisting}

end{document}

The content is renderd as follows – the two breaks in the box and the missing arrow in the new line is the issue:

wrong rendering of new line


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.