Migrate from GitHub to SourceForge with this tool. Check out all of SourceForge's recent improvements.
Close

#54 [RFE] Property output formatter

0.9.16
closed
RBRi
None
1
2015-06-01
2015-04-19
Vincent
No

Hi,

I'm using cssparser to inline some css files into HTML mail (with 'style' attributes). The library works fine. But the produced HTML email are not fully working when they are read by Lotus Notes mail client (v8).

As you can read here (http://www.emailonacid.com/blog/details/C13/hexadecimal_vs_rgb_values_in_html_emails), some mail client does not support the rgb() format for the colors (all is fine with #hexa format)

So, i wonder if cssparser could provide an option (a kind of formatter) to choose the output format of the properties (like color, but also maybe for something else)

Regards

Discussion

  • RBRi

    RBRi - 2015-04-20

    Hi Vincent,

    sounds reasonable.
    As for now CSSParser is a parser, at the moment all toString() methods are printing what the parser found. But maybe we can add a more enhanced version of conversion back to string that does some pretty printing.
    Can you please illustrate your current approach with some lines of (pseudo= code and maybe also your idea how the feature should look like from the api users point of view.

    RBRi
    --------------------------
    WETATOR
    Smart web application testing
    http://www.wetator.org
    
     
  • Vincent

    Vincent - 2015-04-20

    Hi,

    Thanks for your quick answer. Maybe my RFE is a bit too generic. My actual need is pretty simple: when i do inline css, i'd like color properties to be printed in the #hex format.

    I'm using a similar code to this one (second answer with jsoup+cssparser): http://stackoverflow.com/questions/4521557/automatically-convert-style-sheets-to-inline-style/4521740#answer-21757928

    As you can see, this code uses the 'getPropertyValue' to get the final value (which calls LexicalUnitImpl.toString which calls RGBColorImpl.toString which prints with the 'rgb()' format)

    A quick fix could be to change the RGBColorImpl.toString ;-) But i suppose you prefer do not change that :-) That's why, i'm wondering if we could have an "option" to change the color format:
    - with a map of options/booleand could be passed to the parser (then injected into the several lexical unit)?
    - with a CssFormatter knowing how to print to the LexicalUnits? (a bit overkill)
    - other idea?

     
  • Vincent

    Vincent - 2015-04-30

    Here is a possible patch to demonstrate the idea. The CSSOMParserOptions could be a simple Map if you prefer.

     
  • RBRi

    RBRi - 2015-05-03

    Thanks for the patch, will have some time the next days to work on this.
    At the moment the plan is to add a method toString(CCSFormat) to all relevant classes. The CSSFormat is a simple bean that offers different settings.
    What do you think?

     
  • Vincent

    Vincent - 2015-05-05

    Your plan seems fine to me.

    I didn't propose your solution because i thought it was a too much change for my small need. But, imho, from a long term point of view, i prefer your 'toString(CSSFormat)' solution.

     
  • RBRi

    RBRi - 2015-05-31
    • status: open --> pending
    • assigned_to: RBRi
    • Group: unassigned --> 0.9.16
     
  • RBRi

    RBRi - 2015-05-31

    Hi Vincent,

    again some delay because i was busy implementing FF38 support in HtmlUnit.
    But now i have finished a first impl.
    Can you please make sure that the impl solves your problem.
    (There is a sample in unit test CSSStyleSheetImplTest#getCssTextFormatedRgbAsHex()).

     
  • Vincent

    Vincent - 2015-06-01

    Hi,

    Thanks you for the enhancement. It works fine. I have a last issue, when the property is a shorthand, the color is not "hexa formatted":
    border-bottom: 1px solid rgb(224, 225, 221)

    I guess this is because cssparser does not (yet?) handle the shorthand?

     
  • RBRi

    RBRi - 2015-06-01

    Good guess but luckily you are wrong. Should be fixed now. New snapshot build is deployed.

     
  • Vincent

    Vincent - 2015-06-01

    Tested and validated :) All is fine now.

    Thanks

     
  • RBRi

    RBRi - 2015-06-01
    • status: pending --> closed
     

Anonymous
Anonymous

Cancel  Add attachments