How to use \colorbox rather than \texttt for code in markdown cells when converting to latex?

This is an example of something that I think I’m going to need frequently in my current project: the ability to customize how cells are converted to latex. The specifics: currently if we have a markdown cell with some preformatted text in backticks like this:

foo

then it becomes

\texttt{foo}

in the latex output. In order to have more control over the color of the highlighting, I’d like to instead make it:

\colorbox{foo}

The three ways that I have figured out to do this so far are:

  • manually edit the latex in a text editor
  • write a standalone python program to edit the latex file
  • use latex itself to replace \texttt with \colorbox

The last solution currently seems best, but I would like more control - for example, I want different highlighting in markdown cells from in section headers.

So, what is the “correct” way to do this? I can’t figure out if this should be a filter, a preprocessor, a postprocessor, or something else entirely!