Skip to content

Commit c3cb813

Browse files
committed
WIP: Switch to markdown and fix code blocks
TODO: 22/23 pages. TODO: maybe chose another syntax color (See README.md) I had a lot of difficulties while reading this great book, and most where related to code blocks being badly formatted. For instance, the `RCLASS(tmp)->iv_tbl` would render as `RCLASS->iv_tbl`. Rather than fixing textile which really is not the goto markup language nowadays. I've made another attempt to switch to markdown (seeing that the former wasn't successful). I've done that using the script below, and allowing myself a few changes: 1. add syntax highlighter (See README.md), 2. wrap images in `figure` html tags, and show captions below, 3. make a few small cosmetic changes (See styles.css), 4. remove the old textile related plugin, 5. remove differentiation between small and large code blocks. ```awk BEGIN { # Set it to 1 and remove the firt `!` of any rule to only print that rule. DEBUG = 0 figure_count = 0 } function esc(s) { gsub("%", "%%", s) return s } function print_all_but_first() { for (i=2; i<NF; i++) printf esc($i) " " printf esc($NF) "\n" } function print_header(char) { print_all_but_first() n = length - length($1) - 1 while(n--) printf(char) printf("\n") } !DEBUG && /^#/ { printf "* " print_all_but_first() next } !DEBUG && /^h1\./ { print_header("-"); next } !DEBUG && /^h2\./ { print_header("="); next } !DEBUG && /^h([3-9])\./ { n = substr($1, 2, 1) while(n--) printf("#") printf " " print_all_but_first() next } !DEBUG && /^<pre/ { print "```TODO-lang" next } !DEBUG && /^<\/pre/ { print "```" next } !DEBUG && /^!images\// { figure = ++figure_count match($0, /images\/[^(]+/) path = substr($0, RSTART, RLENGTH) match($0, /\([^)]+/) alt = substr($0, RSTART + 1, RLENGTH - 1) alt = "figure "figure": "alt print "<figure>" print "\thanks<img src=\""path"\" alt=\""alt"\">" print "\t<figcaption>"alt"</figcaption>" print "</figure>" next } !DEBUG { print } # default (thanks to `next` in every action) ``` Signed-off-by: Ulysse Buonomo <[email protected]>
1 parent 9e6340f commit c3cb813

10 files changed

+272
-167
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
_site
1+
/_site
2+
/.jekyll-cache
23
ebooks
34
*#
45
*~

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
source "https://rubygems.org"
22
gem "jekyll"
3-
gem "RedCloth"
3+
gem "rouge"

Gemfile.lock

+59-31
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,68 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
RedCloth (4.2.9)
5-
classifier (1.3.3)
6-
fast-stemmer (>= 1.0.0)
7-
colorator (0.1)
8-
commander (4.1.3)
9-
highline (~> 1.6.11)
10-
directory_watcher (1.4.1)
11-
fast-stemmer (1.0.2)
12-
highline (1.6.19)
13-
jekyll (1.0.3)
14-
classifier (~> 1.3)
15-
colorator (~> 0.1)
16-
commander (~> 4.1.3)
17-
directory_watcher (~> 1.4.1)
18-
kramdown (~> 1.0.2)
19-
liquid (~> 2.3)
20-
maruku (~> 0.5)
21-
pygments.rb (~> 0.5.0)
22-
safe_yaml (~> 0.7.0)
23-
kramdown (1.0.2)
24-
liquid (2.5.0)
25-
maruku (0.6.1)
26-
syntax (>= 1.0.0)
27-
posix-spawn (0.3.6)
28-
pygments.rb (0.5.2)
29-
posix-spawn (~> 0.3.6)
30-
yajl-ruby (~> 1.1.0)
31-
safe_yaml (0.7.1)
32-
syntax (1.0.0)
33-
yajl-ruby (1.1.0)
4+
addressable (2.7.0)
5+
public_suffix (>= 2.0.2, < 5.0)
6+
colorator (1.1.0)
7+
concurrent-ruby (1.1.8)
8+
em-websocket (0.5.2)
9+
eventmachine (>= 0.12.9)
10+
http_parser.rb (~> 0.6.0)
11+
eventmachine (1.2.7)
12+
ffi (1.15.0)
13+
forwardable-extended (2.6.0)
14+
http_parser.rb (0.6.0)
15+
i18n (1.8.10)
16+
concurrent-ruby (~> 1.0)
17+
jekyll (4.2.0)
18+
addressable (~> 2.4)
19+
colorator (~> 1.0)
20+
em-websocket (~> 0.5)
21+
i18n (~> 1.0)
22+
jekyll-sass-converter (~> 2.0)
23+
jekyll-watch (~> 2.0)
24+
kramdown (~> 2.3)
25+
kramdown-parser-gfm (~> 1.0)
26+
liquid (~> 4.0)
27+
mercenary (~> 0.4.0)
28+
pathutil (~> 0.9)
29+
rouge (~> 3.0)
30+
safe_yaml (~> 1.0)
31+
terminal-table (~> 2.0)
32+
jekyll-sass-converter (2.1.0)
33+
sassc (> 2.0.1, < 3.0)
34+
jekyll-watch (2.2.1)
35+
listen (~> 3.0)
36+
kramdown (2.3.1)
37+
rexml
38+
kramdown-parser-gfm (1.1.0)
39+
kramdown (~> 2.0)
40+
liquid (4.0.3)
41+
listen (3.5.1)
42+
rb-fsevent (~> 0.10, >= 0.10.3)
43+
rb-inotify (~> 0.9, >= 0.9.10)
44+
mercenary (0.4.0)
45+
pathutil (0.16.2)
46+
forwardable-extended (~> 2.6)
47+
public_suffix (4.0.6)
48+
rb-fsevent (0.10.4)
49+
rb-inotify (0.10.1)
50+
ffi (~> 1.0)
51+
rexml (3.2.5)
52+
rouge (3.26.0)
53+
safe_yaml (1.0.5)
54+
sassc (2.4.0)
55+
ffi (~> 1.9)
56+
terminal-table (2.0.0)
57+
unicode-display_width (~> 1.1, >= 1.1.1)
58+
unicode-display_width (1.7.0)
3459

3560
PLATFORMS
3661
ruby
3762

3863
DEPENDENCIES
39-
RedCloth
4064
jekyll
65+
rouge
66+
67+
BUNDLED WITH
68+
2.2.11

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ $ jekyll serve # this compiles files and starts a server on localhost:4000.
3737
[Jekyll usage](https://github.com/mojombo/jekyll/wiki/usage)
3838

3939

40+
<details>
41+
42+
<summary>Changing code style</summary>
43+
44+
```zsh
45+
function apply_style {
46+
pygmentize -S $1 -f html -a .highlight > css/highlight.css
47+
}
48+
while read -r style; do
49+
echo $style
50+
apply_style $style
51+
read -qs && echo $style >> t.preselection
52+
done < <(pygmentize -L styles | awk -F'[ :]' '/^\* / { print $2 }')
53+
```
54+
55+
</details>
56+
57+
4058
Reading in EPUB
4159
=========
4260

_config.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
redcloth:
2-
hard_breaks: false
31
exclude: ["ebooks", "script", "original_repo", "Gemfile", "Gemfile.lock", "dictionary.txt", "README.md"]
2+
markdown: kramdown
3+
highlighter: rouge
4+
pygments: true
5+
kramdown:
6+
syntax_highlighter: rouge
7+
input: GFM
8+
auto_ids: true
9+
toc_levels: 1..3

_layouts/default.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta charset="utf-8"/>
55
<title> {% if page.title %} {{ page.title }} | {% endif %} Ruby Hacking Guide </title>
66
<link rel="stylesheet" href="/css/styles.css" />
7+
<link rel="stylesheet" href="/css/highlight.css" />
78
</head>
89
<body>
910

_plugins/rhg_textile_converter.rb

-59
This file was deleted.

css/highlight.css

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
pre { line-height: 125%; }
2+
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
3+
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
4+
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
5+
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
6+
.highlight .hll { background-color: #ffffcc }
7+
.highlight { background: #f8f8f8; }
8+
.highlight .c { color: #8f5902; font-style: italic } /* Comment */
9+
.highlight .err { color: #a40000; border: 1px solid #ef2929 } /* Error */
10+
.highlight .g { color: #000000 } /* Generic */
11+
.highlight .k { color: #204a87; font-weight: bold } /* Keyword */
12+
.highlight .l { color: #000000 } /* Literal */
13+
.highlight .n { color: #000000 } /* Name */
14+
.highlight .o { color: #ce5c00; font-weight: bold } /* Operator */
15+
.highlight .x { color: #000000 } /* Other */
16+
.highlight .p { color: #000000; font-weight: bold } /* Punctuation */
17+
.highlight .ch { color: #8f5902; font-style: italic } /* Comment.Hashbang */
18+
.highlight .cm { color: #8f5902; font-style: italic } /* Comment.Multiline */
19+
.highlight .cp { color: #8f5902; font-style: italic } /* Comment.Preproc */
20+
.highlight .cpf { color: #8f5902; font-style: italic } /* Comment.PreprocFile */
21+
.highlight .c1 { color: #8f5902; font-style: italic } /* Comment.Single */
22+
.highlight .cs { color: #8f5902; font-style: italic } /* Comment.Special */
23+
.highlight .gd { color: #a40000 } /* Generic.Deleted */
24+
.highlight .ge { color: #000000; font-style: italic } /* Generic.Emph */
25+
.highlight .gr { color: #ef2929 } /* Generic.Error */
26+
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
27+
.highlight .gi { color: #00A000 } /* Generic.Inserted */
28+
.highlight .go { color: #000000; font-style: italic } /* Generic.Output */
29+
.highlight .gp { color: #8f5902 } /* Generic.Prompt */
30+
.highlight .gs { color: #000000; font-weight: bold } /* Generic.Strong */
31+
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
32+
.highlight .gt { color: #a40000; font-weight: bold } /* Generic.Traceback */
33+
.highlight .kc { color: #204a87; font-weight: bold } /* Keyword.Constant */
34+
.highlight .kd { color: #204a87; font-weight: bold } /* Keyword.Declaration */
35+
.highlight .kn { color: #204a87; font-weight: bold } /* Keyword.Namespace */
36+
.highlight .kp { color: #204a87; font-weight: bold } /* Keyword.Pseudo */
37+
.highlight .kr { color: #204a87; font-weight: bold } /* Keyword.Reserved */
38+
.highlight .kt { color: #204a87; font-weight: bold } /* Keyword.Type */
39+
.highlight .ld { color: #000000 } /* Literal.Date */
40+
.highlight .m { color: #0000cf; font-weight: bold } /* Literal.Number */
41+
.highlight .s { color: #4e9a06 } /* Literal.String */
42+
.highlight .na { color: #c4a000 } /* Name.Attribute */
43+
.highlight .nb { color: #204a87 } /* Name.Builtin */
44+
.highlight .nc { color: #000000 } /* Name.Class */
45+
.highlight .no { color: #000000 } /* Name.Constant */
46+
.highlight .nd { color: #5c35cc; font-weight: bold } /* Name.Decorator */
47+
.highlight .ni { color: #ce5c00 } /* Name.Entity */
48+
.highlight .ne { color: #cc0000; font-weight: bold } /* Name.Exception */
49+
.highlight .nf { color: #000000 } /* Name.Function */
50+
.highlight .nl { color: #f57900 } /* Name.Label */
51+
.highlight .nn { color: #000000 } /* Name.Namespace */
52+
.highlight .nx { color: #000000 } /* Name.Other */
53+
.highlight .py { color: #000000 } /* Name.Property */
54+
.highlight .nt { color: #204a87; font-weight: bold } /* Name.Tag */
55+
.highlight .nv { color: #000000 } /* Name.Variable */
56+
.highlight .ow { color: #204a87; font-weight: bold } /* Operator.Word */
57+
.highlight .w { color: #f8f8f8; text-decoration: underline } /* Text.Whitespace */
58+
.highlight .mb { color: #0000cf; font-weight: bold } /* Literal.Number.Bin */
59+
.highlight .mf { color: #0000cf; font-weight: bold } /* Literal.Number.Float */
60+
.highlight .mh { color: #0000cf; font-weight: bold } /* Literal.Number.Hex */
61+
.highlight .mi { color: #0000cf; font-weight: bold } /* Literal.Number.Integer */
62+
.highlight .mo { color: #0000cf; font-weight: bold } /* Literal.Number.Oct */
63+
.highlight .sa { color: #4e9a06 } /* Literal.String.Affix */
64+
.highlight .sb { color: #4e9a06 } /* Literal.String.Backtick */
65+
.highlight .sc { color: #4e9a06 } /* Literal.String.Char */
66+
.highlight .dl { color: #4e9a06 } /* Literal.String.Delimiter */
67+
.highlight .sd { color: #8f5902; font-style: italic } /* Literal.String.Doc */
68+
.highlight .s2 { color: #4e9a06 } /* Literal.String.Double */
69+
.highlight .se { color: #4e9a06 } /* Literal.String.Escape */
70+
.highlight .sh { color: #4e9a06 } /* Literal.String.Heredoc */
71+
.highlight .si { color: #4e9a06 } /* Literal.String.Interpol */
72+
.highlight .sx { color: #4e9a06 } /* Literal.String.Other */
73+
.highlight .sr { color: #4e9a06 } /* Literal.String.Regex */
74+
.highlight .s1 { color: #4e9a06 } /* Literal.String.Single */
75+
.highlight .ss { color: #4e9a06 } /* Literal.String.Symbol */
76+
.highlight .bp { color: #3465a4 } /* Name.Builtin.Pseudo */
77+
.highlight .fm { color: #000000 } /* Name.Function.Magic */
78+
.highlight .vc { color: #000000 } /* Name.Variable.Class */
79+
.highlight .vg { color: #000000 } /* Name.Variable.Global */
80+
.highlight .vi { color: #000000 } /* Name.Variable.Instance */
81+
.highlight .vm { color: #000000 } /* Name.Variable.Magic */
82+
.highlight .il { color: #0000cf; font-weight: bold } /* Literal.Number.Integer.Long */

css/styles.css

+20-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ body {
55
line-height: 140%;
66
margin-top: 5%;
77
margin-left: 2em;
8-
width: 40em;
8+
width: 35em;
99
}
1010

1111
h1 {
@@ -72,13 +72,16 @@ dd {
7272
}
7373

7474
p.caption {
75-
margin-botton: 0px;
75+
margin-bottom: 0px;
7676
}
7777

78-
pre {
79-
line-height: 120%;
78+
.highlight {
8079
padding: 8px;
81-
background: #eee;
80+
border-radius: 8px;
81+
}
82+
83+
.highlight pre {
84+
margin: 0;
8285
}
8386

8487
span.ami {
@@ -121,6 +124,18 @@ body {
121124
font-family: Georgia, serif;
122125
}
123126

127+
figcaption {
128+
font-size: 0.8em;
129+
font-style: italic;
130+
}
131+
132+
/* code inlined in text */
133+
code.highlighter-rouge {
134+
background: #33a2;
135+
border-radius: 2px;
136+
padding: 2px;
137+
}
138+
124139
h1 code, h2 code, h3 code, h4 code, h5 code{
125140
font-family: Menlo, Monaco, "Andale Mono", "Lucida console", "courier New", monospace;
126141
font-weight: normal;

0 commit comments

Comments
 (0)