Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strip trailing slashes and match \r\n line breaks
Unfortunately this commit introduces two changes because I haven't figured out how to make them independently of each other: * Strip trailing backslashes from the lines of an address * When replacing line breaks with "<br>"s in the parsing of address blocks, replace the whole "\r\n" line break and not just the "\n" character _Strip trailing backslashes from the lines of an address_ Kramdown has a feature where it will replace two trailing backslashes from the input Govspeak with a line break in the output HTML. I'm in the process of making some changes that will stop that feature from working inside address blocks. It doesn't appear to be used in the wild in any address blocks and we don't officially support the feature in address blocks, so I think that intentionally disabling it is reasonable. To be clear, while Kramdown only treats pairs of backslashes this way, we're actually removing all trailing backslashes because even an odd number of them interferes with our code that handles address blocks. _When replacing line breaks with "<br>"s in the parsing of address blocks, replace the whole "\r\n" line break and not just the "\n" character_ The line breaks in the Govspeak in Whitehall's database and in the strings that Govspeak Preview hands to the parser are composed of both a return char and a newline char. In the resulting HTML, address blocks contain the return chars still intact because the address block's search-and-replace code was only matching and removing the newline chars. The intact return chars might actually be serving the purpose of producing line breaks in our source HTML (i.e. not affecting the way the HTML is rendered in the browser, but admittedly producing more readable plain HTML). But if this is the case and if this turns out to have been desirable behaviour I'd prefer that we do that more deliberately. Since the example Govspeak in the test suite sometimes uses standalone newlines and sometimes uses combined returns-and-newlines, it seems safest to assume that both options are possible and so I've opted for optionally matching either.
- Loading branch information