# styling verbatim with background color

I am using pandoc to convert Markdown documents containing code blocks to PDF, and the intermediate TeX surrounds the code with \begin{verbatim}...\end{verbatim}. How can I stylize and format these sections to have a background color or a frame around it? I've tried fancyvrb, but the background color does not extend behind the text itself.

I've tried using the verbatim package and after reading the manual was able to modify \verbatim@processline to change the font color or add text in front of each line: \def\verbatim@processline{\fbox{\\$ \the\verbatim@line}\par}. I would like to this for the entire chunk and modify other properties (frame, centering, etc) in the future. I thought the best way to do this would be to add a \begin{shaded} into \verbatim and add \end{shaded} into endverbatim. However, I run into an error when I do that:

\makeatletter
\frenchspacing\@vobeyspaces\verbatim@start}
\makeatother


And the error message:

! Missing \endcsname inserted.
\protect
l.1 \begin{verbatim}

1. Is there a way to insert enclose the verbatim text in an environment that I can stylize later?
2. If not, is there a better way of stylizing the verbatim environment? I cannot change to listings or similar packages that use \begin{lstlisting} since pandoc automatically inserts \begin{verbatim}?

MWE:

\documentclass{beamer}
\usepackage{xcolor, framed}

\begin{document}

\begin{frame}[fragile]

\begin{verbatim}
\end{verbatim}

\begin{verbatim}

• Do you truly need a verbatim environment? For example, are you using any particular characters that are otherwise disallowed? Or are you merely interested in a typewriter style formatting of the text? – Werner Mar 15 '18 at 23:30
• pandoc automatically uses a verbatim environment when converting from Markdown – Chris Mar 15 '18 at 23:32
• You can probably change what Pandoc does; it's worth looking into that. (In the worst case you can completely redefine the meaning of verbatim in the preamble that Pandoc lets you add.) – ShreevatsaR Mar 16 '18 at 0:34
• Actually, I realized that I can specify a --listings argument while calling pandoc which uses the listings package instead of verbatim and that helped my issue a lot! – Chris Apr 18 '18 at 3:12