I am trying to format some text based on some patterns.
Clear[highlight]; SetAttributes[highlight, HoldAll]; highlight[pattern_, style_] := s_String :> Row[List @@ StringReplace[s, t : pattern :> style[t]]]
This works fine and dandy if a match is found:
"foo bar baz" /. highlight["foo", Style[#, Red] &]
But doesn't if no match is found:
"fu bar baz" /. highlight["foo", Style[#, Red] &]
Row["fu bar baz"]
The failure to match has left us with an ugly
Row. I'm having a bit of trouble fixing this case, perhaps you can help?