Skip to content

Commit c1bf005

Browse files
committed
mkexam: CSSify the enscript output
mkexam.pl now converts the enscript output from using hard-coded font color values to instead use <span> with specific class names for different code sections. example.css is a new CSS file with the styles for the examples, with some minor ajustments to work better in dark mode: primarily the comment style is now using a lighter red. Closes #515
1 parent e7bfe5a commit c1bf005

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

libcurl/c/_example-templ.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head> <title>libcurl example - %cfile%</title>
44
#include "css.t"
5+
<link rel="stylesheet" type="text/css" href="example.css">
56
</head>
67

78
#define LIBCURL_EXAMPLE

libcurl/c/example.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
span.comment {
3+
color: #B22222;
4+
font-style: italic;
5+
}
6+
span.cpp {
7+
color: #5F9EA0;
8+
}
9+
span.type {
10+
color: #228B22;
11+
font-weight: bold;
12+
}
13+
span.expr {
14+
color: #A020F0;
15+
font-weight: bold;
16+
}
17+
span.string {
18+
color: #BC8F8F;
19+
}
20+
span.function {
21+
color: #a0a000;
22+
}
23+
24+
/* DARK MODE PROPERTIES */
25+
/* These will override all settings above */
26+
@media (prefers-color-scheme: dark) {
27+
28+
span.comment {
29+
color: #ff8080;
30+
font-style: italic;
31+
}
32+
span.function {
33+
color: #ffff00;
34+
}
35+
}

libcurl/c/mkexam.pl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@
4747
# now run enscript and extract the PRE part and linkify some of the libcurl
4848
# stuff
4949
#
50+
51+
# enscript generates hard-coded font colors. Replace each such <font>
52+
# instruction with a dedicated <span> tag.
53+
my %color2tag = ('B22222' => 'comment',
54+
'5F9EA0' => 'cpp',
55+
'228B22' => 'type',
56+
'A020F0' => 'expr',
57+
'BC8F8F' => 'string',
58+
'0000FF' => 'function');
5059
open(ET, ">$encfile");
5160
open(CMD, "$cmd|");
5261
my $show=0;
@@ -58,6 +67,13 @@
5867
if($show) {
5968
my $l=$_;
6069

70+
$l =~ s/\<FONT COLOR=\"\#([0-9A-F]+)\"\>/sprintf "<span class=\"".$color2tag{$1}."\">";/ge;
71+
$l =~ s:\</FONT>:</span>:g;
72+
$l =~ s:<B>::g;
73+
$l =~ s:</B>::g;
74+
$l =~ s:<I>::g;
75+
$l =~ s:</I>::g;
76+
6177
# find curl_ function invokes
6278
if($l =~ /^(.*)(curl_[a-z_]*)( *\(.*)/) {
6379
$l = "$1<a href=\"$manpage/$2.html\">$2</a>$3\n";

0 commit comments

Comments
 (0)