newtoperlprog:

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:

ATCGCGATCATCCATACTCATTAG

Then 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.