Skip to content

Commit c44fae0

Browse files
committed
add markdown to pdf tools.
1 parent 19d129e commit c44fae0

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

catmd.rb

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env ruby
2+
3+
require "liquid"
4+
5+
class Jekyll2Markdown
6+
def initialize
7+
@done = {}
8+
@markdown = ""
9+
end
10+
def to_markdown
11+
@markdown
12+
end
13+
def <<(file)
14+
cont = File.read(file)
15+
markdown = cont.split(/---\r?\n/, 3).last
16+
@markdown << parse_liquid(markdown)
17+
end
18+
def _parse_liquid(str)
19+
template = Liquid::Template.parse(str, :error_mode => :strict)
20+
template.render
21+
end
22+
def parse_liquid(str)
23+
str = str.gsub(/\{::comment\}.*?\{:\/comment\}/m, "")
24+
str = str.gsub("* Contents\n{:toc}", "")
25+
str = str.gsub("../assets/", "assets/")
26+
str = str.gsub(/{%\s*include\s+(.+?)\s*%}/) do |m|
27+
file = $1.dup
28+
if @done[file]
29+
""
30+
else
31+
@done[file] = true
32+
cont = File.read(File.join("_includes", file))
33+
template = Liquid::Template.parse(cont, :error_mode => :strict)
34+
str = template.render
35+
parse_liquid(str)
36+
end
37+
end
38+
end
39+
end
40+
41+
md = Jekyll2Markdown.new
42+
ARGV.each do |file|
43+
md << file
44+
end
45+
puts md.to_markdown

filtertex.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env ruby
2+
3+
puts <<'EOF'
4+
\documentclass[dvipdfmx]{jsarticle}
5+
\usepackage{graphicx}
6+
\usepackage{url}
7+
\usepackage{hyperref}
8+
\begin{document}
9+
\tableofcontents
10+
EOF
11+
ARGF.each do |line|
12+
line = line.gsub(/\\includegraphics{([^}]+)}/) do |m|
13+
file = $1.dup
14+
if file =~ /image_install_right_ctrl_[gm]\.png/
15+
"\\includegraphics[height=1em]{#{file}}"
16+
else
17+
"\\includegraphics[width=.6\\hsize]{#{file}}"
18+
end
19+
end
20+
#line = line.gsub(/\\url\b/, '\protect\url')
21+
line = line.gsub(/\\paragraph\b/, '\paragraph[]')
22+
puts line
23+
end
24+
puts '\end{document}'

0 commit comments

Comments
 (0)