When you use the color editing code, it inserts characters into the string. That shifts all the character positions to the right. That's why I suggested you always go from the right and work left in the note at the end. That's the reason that you're seeing weird characters in the text. Those weird characters are parts the terminal commands that tell the terminal to change colors.
For example, suppose you wanted to highlight the string CAT every time it appears, and also that the terminal command for changing the color to normal is BEER and the command to change the color to highlight is KETCHUP. Then if your input string looks like this:
ATCGCGATCATCCATACTCATTAGThen the positions you're wanting to highlight are at 8, 12 and 18. If we apply the edits from left to right we get:
ATCGCGATBEERCATKETCHUPCCATACTCATTAG edit at 8 ATCGCGATBEEBEERRCAKETCHUPTKETCHUPCCATACTCATTAG then 12 ATCGCGATBEEBEERRCABEERKETKETCHUPCHUPTKETCHUPCCATACTCATTAG then 18 ???^^^^? ^^^^???vvvvvvv?????vvvvvvv
UGH! The string has garbage in it now. To point it out, I've marked the resulting string with ^^^^ to indicate the command to switch to bold, vvvvvvv to show the command that switches back to normal, and ? for any garbage characters. So we'd see BEE in the regular color, followed by RCAKET in bold, then CHUPTCCATACTCATTAG in regular color. However, if we do the edits from right to left, though, we get:
ATCGCGATCATCCATACTBEERCATKETCHUPTAG edit at 18 ATCGCGATCATCBEERCATKETCHUPACTBEERCATKETCHUPTAG then 12 ATCGCGATBEERCATKETCHUPCBEERCATKETCHUPACTBEERCATKETCHUPTAG then 8 ^^^^ vvvvvvv ^^^^ vvvvvvv ^^^^ vvvvvvv
So the three "CAT" sequences are in bold, and the rest of the string is displayed in regular color.
To convert your data to use HTML formatting instead, you can use roughly the same code, but instead of inserting BEER and KETCHUP from Term::ANSIColor (or whatever it is that it uses for your terminal), you could use <font color="red"> and </font> as Anonymous Monk indicated later in the thread. In that case, though, you'll *still* want to go from right to left!
Notes:
1) Now that the node is formatted, I'm really revolted by the pairing of beer and ketchup. But it was annoying enough to format that I'll leave it alone, nausea-inducing as it is.
2) If you had replied to my node instead of yourself, I'd've seen the message sooner and replied. (When time pressed, I generally only look at top-level nodes and replies to my nodes.)
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re^2: bold color text and export to file
by roboticus
in thread bold color text and export to file
by newtoperlprog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |