Skip to content

Instantly share code, notes, and snippets.

@ucarion
Last active December 26, 2024 03:46
Show Gist options
  • Save ucarion/1ad28c36667fa39d448b to your computer and use it in GitHub Desktop.
Save ucarion/1ad28c36667fa39d448b to your computer and use it in GitHub Desktop.
Composing programs to PDF
require 'nokogiri'
input = $stdin.readlines.join
page = Nokogiri::HTML(input)
page.css('.example').each do |elem|
elem.inner_html = '<i>Environment diagram omitted.</i>'
end
page.css('img').remove
puts page.css('.inner-content').inner_html
set -e
pages="11-getting-started
12-elements-of-programming
13-defining-new-functions
14-designing-functions
15-control
16-higher-order-functions
17-recursive-functions"
function html_to_pdf {
pandoc -f html -o "$1" --latex-engine=xelatex
}
while read -r page; do
url="http://composingprograms.com/pages/$page.html"
curl -s $url | ruby html_cleanup.rb | html_to_pdf "output/$page.pdf"
echo "Done with $page"
done <<< "$pages"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment