(html, keepStyles)
| 34 | // get whaterever rubbish is inserted in chrome |
| 35 | // should be passed an html string, returns an html string |
| 36 | var taFixChrome = function(html, keepStyles){ |
| 37 | if(!html || !angular.isString(html) || html.length <= 0) return html; |
| 38 | // grab all elements with a style attibute |
| 39 | // a betterSpanMatch matches only a style=... with matching quotes |
| 40 | // this captures the whole: |
| 41 | // 'style="background-color: rgb(255, 255, 255);"' |
| 42 | var betterSpanMatch = /style\s?=\s?(["'])(?:(?=(\\?))\2.)*?\1/ig; |
| 43 | // where the original spanMatch = /<([^>\/]+?)style=("([^\"]+)"|'([^']+)')([^>]*)>/ig; |
| 44 | // captures too much and includes the front tag! |
| 45 | var spanMatch = /<([^>\/]+?)style=("([^\"]+)"|'([^']+)')([^>]*)>/ig; |
| 46 | var appleConvertedSpaceMatch = /<span class="Apple-converted-space">([^<]+)<\/span>/ig; |
| 47 | var match, styleVal, appleSpaceVal, newTag, finalHtml = '', lastIndex = 0; |
| 48 | // remove all the Apple-converted-space spans and replace with the content of the span |
| 49 | //console.log('before:', html); |
| 50 | /* istanbul ignore next: apple-contereted-space span match */ |
| 51 | while(match = appleConvertedSpaceMatch.exec(html)){ |
| 52 | appleSpaceVal = match[1]; |
| 53 | appleSpaceVal = appleSpaceVal.replace(/ /ig, ' '); |
| 54 | finalHtml += html.substring(lastIndex, match.index) + appleSpaceVal; |
| 55 | lastIndex = match.index + match[0].length; |
| 56 | } |
| 57 | /* istanbul ignore next: apple-contereted-space span has matched */ |
| 58 | if (lastIndex) { |
| 59 | // modified.... |
| 60 | finalHtml += html.substring(lastIndex); |
| 61 | html=finalHtml; |
| 62 | finalHtml=''; |
| 63 | lastIndex=0; |
| 64 | } |
| 65 | ///////////////////////////////////////////////////////////// |
| 66 | // |
| 67 | // Allow control of this modification |
| 68 | // taKeepStyles: False - removes these modification |
| 69 | // |
| 70 | // taFixChrome removes the following styles: |
| 71 | // font-family: inherit; |
| 72 | // line-height: <number> |
| 73 | // color: inherit; |
| 74 | // color: rgb( <rgb-component>#{3} ) |
| 75 | // background-color: rgb( <rgb-component>#{3} ) |
| 76 | // |
| 77 | ///////////////////////////////////////////////////////////// |
| 78 | if (!keepStyles) { |
| 79 | while (match = betterSpanMatch.exec(html)) { |
| 80 | finalHtml += html.substring(lastIndex, match.index-1); |
| 81 | styleVal = match[0]; |
| 82 | // test for chrome inserted junk |
| 83 | match = /font-family: inherit;|line-height: 1.[0-9]{3,12};|color: inherit; line-height: 1.1;|color: rgb\(\d{1,3}, \d{1,3}, \d{1,3}\);|background-color: rgb\(\d{1,3}, \d{1,3}, \d{1,3}\);/gi.exec(styleVal); |
| 84 | if (match) { |
| 85 | styleVal = styleVal.replace(/( |)font-family: inherit;|( |)line-height: 1.[0-9]{3,12};|( |)color: inherit;|( |)color: rgb\(\d{1,3}, \d{1,3}, \d{1,3}\);|( |)background-color: rgb\(\d{1,3}, \d{1,3}, \d{1,3}\);/ig, ''); |
| 86 | //console.log(styleVal, styleVal.length); |
| 87 | if (styleVal.length > 8) { |
| 88 | finalHtml += ' ' + styleVal; |
| 89 | } |
| 90 | } else { |
| 91 | finalHtml += ' ' + styleVal; |
| 92 | } |
| 93 | lastIndex = betterSpanMatch.lastIndex; |
no outgoing calls
no test coverage detected