Skip to content

Commit 36ecab2

Browse files
committed
add h2 from yaml in preprocess.rb; remove from sample sections
1 parent 6275eea commit 36ecab2

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

_scripts/preprocess.rb

+56-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,68 @@
11
#!/usr/bin/env ruby
22

3+
require 'yaml'
4+
35
@mainyamldone = false
46
@inyaml = false
7+
@inbox = false
8+
@yaml_block = ""
9+
@main_yaml = nil
10+
@section_yaml = nil
511

612
ARGF.each_with_index do |line, idx|
13+
14+
# handle yaml blocks
715
if /^---$/.match(line)
16+
# pass the main yaml block through
817
print line if !@mainyamldone
918
@inyaml = !@inyaml
10-
@mainyamldone = true if !@inyaml
19+
if @inyaml
20+
# we're starting a yaml block
21+
@yaml_block = line + "\n"
22+
else
23+
# we've reached end of yaml block
24+
@yaml_block = @yaml_block + line + "\n"
25+
if @main_yaml.nil?
26+
@main_yaml = YAML.load(@yaml_block)
27+
else
28+
@section_yaml = YAML.load(@yaml_block)
29+
# add section h2 header to output
30+
# note: can't get header_attributes to work, so have to create
31+
# section anchor explicitly
32+
print "\n\n\\newpage\n"
33+
print "\\hypertarget{" + @section_yaml['id'].to_s + "}{}"
34+
print "\n\n## " + @section_yaml['title'].to_s + "\n"
35+
36+
end
37+
@mainyamldone = true
38+
end
39+
elsif @inyaml
40+
print line unless @mainyamldone
41+
@yaml_block = @yaml_block + line + "\n"
1142
else
12-
print line unless (@inyaml && @mainyamldone)
43+
44+
# replace internal links
45+
# match [text](./03-chapter2.html#s03n6) -> \hyperlink{s03n6}{text}
46+
line.gsub!(/\[([^\]]*)\]\(\.\/.+?\.html#(.+?)\)/, "\\hyperlink{\\2}{\\1}")
47+
# match [text](./03-chapter2.html) -> \hyperlink{s03}{text}
48+
line.gsub!(/\[([^\]]*)\]\(\.\/([0-9]*).+?\.html\)/, "\\hyperlink{s\\2}{\\1}")
49+
# match <span name="s00n3"></span> -> \hypertarget{s00n3}{}
50+
line.gsub!(/\<span name=['"]([A-Za-z0-9]*)['"]\>\<\/span\>/, "\\hypertarget{\\1}{} ")
51+
52+
# handle catalog-card boxes
53+
if /<p class=\"right\".*/.match(line)
54+
print "\\rightline{\\texttt{" + /\>(.*)\</.match(line)[1] + "}}\n"
55+
elsif /^\<div class=\"box\"/.match(line)
56+
@inbox = true
57+
print "\\fboxsep=10pt\n\\fbox{\\begin{minipage}{30em}\n"
58+
elsif /^\<\/div\>/.match(line)
59+
@inbox = false
60+
print "\\end{minipage}}\n"
61+
elsif @inbox
62+
# handle text lines in catalogue card box
63+
print "\\texttt{" + line.gsub(/\*(.+?)\*/,"\\underline{\\1}").sub(/^(\ )*/,"\\hspace*{0.5ex}") + "\\\\}\n"
64+
else
65+
print line
66+
end
1367
end
1468
end

sections/01-section1.md

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ id: s01
66
group: sections
77
---
88

9-
## Chapter 1: Lorem Ipsum
10-
119
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent pretium arcu diam, sit amet porta ligula porta at. *Duis lobortis tellus in lacus dictum, vitae consequat sapien facilisis. Duis ullamcorper neque nec purus ultrices, at porttitor ex varius.* **Mauris sed convallis odio. Praesent sagittis enim sed tempor pretium.** Morbi eget volutpat neque. Proin accumsan odio purus, ut mattis tortor imperdiet a. Nulla facilisi. Morbi ac enim aliquet mauris pulvinar vestibulum. Aliquam blandit ante eget accumsan dictum. Ut hendrerit ipsum quis dictum rutrum. Integer in metus tincidunt, dictum nibh at, efficitur ex. Duis porttitor purus quis pretium suscipit. Proin placerat volutpat congue. Nulla interdum pretium velit, vitae lobortis arcu vehicula vitae.[^note-02-1]
1210

1311
[^note-02-1]: This is a footnote.

sections/02-section2.md

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ id: s02
66
group: sections
77
---
88

9-
## Chapter 2: Tables
10-
119
Markdown does tables in several ways, but getting a format that works well for HTML and PDF is not easy. Here are samples of the different formats. The sample tables are copied from the [Pandoc readme](http://pandoc.org/README.html#tables), where more details may be found.
1210

1311
### Simple table (with alignment)

0 commit comments

Comments
 (0)