Posted 19 years ago by Jakub Maly
Avatar
I am a newcomer to this site and I really like the CodeHighlighter, but I see one problem - the example on the sample page uses inline style atributes to color set colors and inline styles are not valid XHTML. Is there some option which makes the component to output styles in <style></style> tags? This would even make more sense to me - mark all the parts of the code with CSS classes - for example define class for variables, keywords, types, ... - and set their colors in <style> tag.

Comments (2)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Jakub,

Since CodeHighlighter is a control and doesn't generate the markup for a complete web page (<html>, <body> tags, etc.), it is only outputting what it needs to be able to display properly somewhere within a page. If we were generating <style> tags, there wouldn't be any way for us to get them up into the page's <head> area.


Actipro Software Support

Posted 19 years ago by Jakub Maly
Avatar
You are right, I forgot that <style> must be nested in <head> section.
But isn't it possible to add styles programatically using Page.Header.StyleSheet.CreateStyleRule(...) ?

MSDN: ...creates a style rule for the specified document language element type, or selector.

void CreateStyleRule (
Style style,
IUrlResolutionService urlResolver,
string selector
)


This comes from MSDN
// Create a Style object for the <BODY> section of the Web page.
Style bodyStyle = new Style();

bodyStyle.ForeColor = System.Drawing.Color.Blue;
bodyStyle.BackColor = System.Drawing.Color.LightGray;

// Add the style to the header of the current page.
Page.Header.StyleSheet.CreateStyleRule(bodyStyle, this, "BODY");
The latest build of this product (v4.0.59) was released 14 years ago, which was after the last post in this thread.