patternhtmlMinor
Code Prettify CSS template
Viewed 0 times
codeprettifytemplatecss
Problem
I've been working on implementing Google Code Prettify and finally got it to work correctly. You can see my test file here to see what it looks like. I worked from a template and tried to improve it.
There is a lot of HTML boilerplate code that apparently is needed (mostly JavaScript links). I tried to remove some of them to reduce clutter but it broke every time, so I left it all in from the template. For reference:
prettify-test.html
I would like mostly the CSS reviewed, although I am open for suggestions on HTML as well. I tried to make the template in a way that is simple to use. Please do note I have no control at all over the CSS class names (like
PS: There appear to be a few merge conflicts in the linked file. Please disregard them. I removed them i
There is a lot of HTML boilerplate code that apparently is needed (mostly JavaScript links). I tried to remove some of them to reduce clutter but it broke every time, so I left it all in from the template. For reference:
prettify-test.html
Google Prettify testing
Google Prettify Testing: Github default
Color Reference
Plain text
"String content"
Keyword
// Comment
Type name
Literal value 42
Punctuation...
Declaration
Variable name
Function name
Lisp {open bracket
Lisp close} bracket
<Markup tag name>
<Markup attribute-name="">
<Markup attribute="value">
C#/LINQ
// this is a comment
public static class Evaluate
{
public static string FizzBuzz(int start, int end)
{
return Enumerable.Range(start, (end - start) + 1)
.Select(FizzOrBuzz)
.Aggregate(String.Empty, (y, x) => String.Format("{0} {1}", y, x))
.Trim();
}
public static string FizzOrBuzz(int n)
{
if (n % 15 == 0) return "fizzbuzz";
if (n % 3 == 0) return "fizz";
if (n % 5 == 0) return "buzz";
return n.ToString();
}
}
window.jQuery || document.write('')
I would like mostly the CSS reviewed, although I am open for suggestions on HTML as well. I tried to make the template in a way that is simple to use. Please do note I have no control at all over the CSS class names (like
.str, .kwd, etc.) those are what Prettify uses and if you change them it breaks everything, unless you go and change all the JavaScript files that reference those classes.PS: There appear to be a few merge conflicts in the linked file. Please disregard them. I removed them i
Solution
For your li elements, unless you need to support IE8, it would be more elegant to use nth-child to do your alternating line styles:
It would be more elegant to use descendant selectors than to spell out each class individually:
Also, the contrast is rather poor for your
ul.linenums li:nth-child(odd) {
/* styles here */
}It would be more elegant to use descendant selectors than to spell out each class individually:
ul.linenums li {
/* styles here */
}Also, the contrast is rather poor for your
.typ class. To me, it is just barely distinguishable from the surrounding black text.Code Snippets
ul.linenums li:nth-child(odd) {
/* styles here */
}ul.linenums li {
/* styles here */
}Context
StackExchange Code Review Q#78770, answer score: 4
Revisions (0)
No revisions yet.