Last active
June 28, 2017 15:36
-
-
Save oziresrds/58fe6ec157aaf3ca7236c4e606dc61b5 to your computer and use it in GitHub Desktop.
Remove all blocks in rtf fonttbl code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function removeAllBlocksInRtfFonttblCode(rtf) { | |
let newRtf = '', firstIndex, lastIndex, count, tagOpen = 1; | |
firstIndex = rtf.indexOf('\\fonttbl'); | |
count = firstIndex; | |
while(count < rtf.length && tagOpen > 0) { | |
if(rtf[count] == '{') | |
tagOpen++; | |
else if(rtf[count] == '}') { | |
if(tagOpen > 1) | |
tagOpen--; | |
else { | |
tagOpen--; | |
newRtf += rtf[count]; | |
lastIndex = count; | |
} | |
} else | |
newRtf += rtf[count]; | |
count++; | |
} | |
return rtf.substring(0, firstIndex) + newRtf + rtf.substring(lastIndex+1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if(rtf.indexOf("\fonttbl{") == -1){
return rtf;
}