<span style>Hello,</span><div style><br></div><div style>I have a given piece of multiline HTML (which is generated using pandoc btw.) and I am trying to wrap certain elements (tags with a given class) with a <div>.</div>
<div style><br></div><div style>I already took a look at the Text.Regex.PCRE module which seemed a reasonable choice because I am already familiar with similar regex implementations in other languages.</div><div style><br>
</div><div style>I came up with the following function which takes a regex and replaces all matches within the given string using the provided function (which I would use to wrap the element)</div><div style><br></div><div style>
import Text.Regex.PCRE ((=~~))</div><div style><br></div><div style><div>-- Replaces the whole match for the given regex using the given function</div><div>regexReplace :: String -> (String -> String) -> String -> String</div>
<div>regexReplace regex replace text = go text</div><div> where</div><div> go text = case text =~~ regex of</div><div> Just (before, match, after) -></div><div> before ++ replace match ++ go after</div>
<div> _ -> text</div><div><br></div></div><div style>The problem with this function is, that it will not work on multiline strings. I would like to call it like this:</div><div style><br></div><div style>newBody = regexReplace "<table class=\"sourceCode\".*?table>" wrap body</div>
<div style>wrap x = "<div class=\"sourceCodeWrap\">" ++ x ++ "</div>"</div><div style><br></div><div style>Is there any way to easily pass some kind of multiline modifier to the regex in question?</div>
<div style><br></div><div style>Or is this approach completely off and would something else be more appropriate/haskelly for the problem at hand?</div><div style><br></div><div style>Thank you very much in advance.</div>