I'm generating an email with an HTML mime attachment that needs to be available offline . The HTML requires some javascript, specifically jQuery and Date.js.
The problem I'm running into is that the javascript needs to be line wrapped after 72 characters, I'm told this is for CANSPAM reasons. Also some SMTP servers will force a line wrap after so many characters. If the forced line break happens in place where javascript can't have a newline, it breaks the javascript. (jQuery minified is 1 continuous line, wich exceeds 72 characters many times over).
Is there a library or tool that I can use to parse the text of the javascript, and insert newlines in javascript friendly places?
My application code is in Ruby.
Update
--line-break 72
was pretty generous in what it was considering to be 72 characters,开发者_StackOverflow社区 even leaving the curly brace for function definitions on the same line as the function arguments.
After running it through as --line-break 0
and doing a :s/\){/)\r{/g
in vim, the lines seem to be short enough
The YUI Compressor will allow you to specify a maximum column length for each line with the --line-break
option:
--line-break Some source control tools don't like files containing lines longer than, say 8000 characters. The linebreak option is used in that case to split long lines after a specific column. It can also be used to make the code more readable, easier to debug (especially with the MS Script Debugger) Specify 0 to get a line break after each semi-colon in JavaScript, and after each rule in CSS.
From experience, I've seen that it treats this more as a guideline than a strict rule. For instance, if you set line-break to 80 characters, and you have a 100-character string, it will not break that string up for you.
However, depending on your input files, you might be able to make it work.
精彩评论