How to Handle Hex values inside style text content.

64 views
Skip to first unread message

kalyani Shinde

unread,
Nov 3, 2023, 11:05:22 AM11/3/23
to blink-dev
Hi Team,

I am facing weird issue while creating style node with text node in it as follows:

I want to add below rule to style tag for example:

/*

.my-class:before {

    content: "\F1F0"

}

*/

And here is my code

  Element* style = document->CreateRawElement(html_names::kStyleTag, CreateElementFlags::ByCreateElement());

 // Append the style element to the head

headElement->appendChild(style);

std::string text=".myclass:before {\n    content: \"\\F1F0\"\n}\n"; 

// it should be as below

style->ParserAppendChild(static_cast<blink::Node*>(document->createTextNode(text.c_str())));


This code turns my style node having data as below:

my-class:before { content: ""; }


I have noticed, inside StyleSheetContents:ParseString this rule gets received as 

my-class:before { content: \"\u00EF\u\0087\u\00B0"; }\n"


Why is this text node creation causing my Hex value to change, And if it is so, then how should I handle this.


Thanks


Mathias Bynens

unread,
Nov 6, 2023, 2:16:40 AM11/6/23
to kalyani Shinde, blink-dev
Make sure the document uses UTF-8. In HTML, you’d add

<meta charset="utf-8">

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/4623d61c-212f-4a02-92d0-24e0e23976a2n%40chromium.org.

kalyani Shinde

unread,
Nov 8, 2023, 12:10:19 PM11/8/23
to blink-dev, Mathias Bynens, blink-dev, kalyani Shinde
Hi,

This doesn't seem to work. 
Can I try anything else. and how does then blink process any external stylesheet which is having such Hex values and show them correctly in ParseStylesheet. and if I take rules from same point and add them to new style node,
the text is getting converted to unicode chars. is there anything I am missing in the process.?
Reply all
Reply to author
Forward
0 new messages