getzola / zola

A fast static site generator in a single binary with everything built-in. https://www.getzola.org
https://www.getzola.org
MIT License
13.61k stars 950 forks source link

Question about `regex_replace` #2487

Open wermos opened 5 months ago

wermos commented 5 months ago

The docs don't mention anything about this, but it looks to me like the pattern= needs backslashes to be escaped, but the rep= part doesn't need any special escaping.

I feel that this is inconsistent behavior, but it's not a big deal. I do think, however, it would be great to mention this in the docs.

For context, I was replacing \\ with \\\\ because of the markdown parser gobbling up the first backslash as an escaping character. I also did the same with for \, => \\, and \! => \\!. These are commonly used in LaTeX, and due to the unexpected backslash consumption, the MathJax wasn't coming out the way you'd expect.

Keats commented 5 months ago

We are not doing anything special with either value: just getting the string value and using those: https://github.com/getzola/zola/blob/master/components/templates/src/filters.rs#L96-L129 no escape in sight, unless it's the regex crate that handles the escaping.