I want to write a simple Markdown to LaTex converter and chose sed
as the core component of the converter. It was suitable for everything until now when I hit the following problem: I want to convert a markdown code block (3 backticks) into a LaTex listing. The problem is that I want to work on multiple lines here. I tried the following command but it does not work since sed
is processing the input line by line:
sed -E 's/```([[:print:]]*)```/\\begin{lstlisting}/1\\end{lstlisting}/g'
Another idea would be to try to only search and replace only the three backticks, but since every other occurrence needs to be replaced with \end{lstlisting}
I do not know if it is possible. A hacky way would be to use three backticks for the start of the code block and four for the end, but that is quite a dirty solution in my opinion.