-
Notifications
You must be signed in to change notification settings - Fork 9
/
ronnpp
executable file
·32 lines (24 loc) · 1.07 KB
/
ronnpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env ruby
# frozen_string_literal: true
# ronnpp: a (crappy) preprocessor for ronn
# rules:
# 1. <foo> gets translated to <<foo>>
# 2. ![foo] gets translated to [foo]
# 3. [foo] gets translated to \[[foo]\]
# 4. {foo} gets translated to [foo](foo)
codeblock = false
STDIN.each_line do |line|
codeblock = !codeblock if /```/.match?(line)
# 1. i prefer explicit <required options>, so escape *and* emphasize them
line.gsub!(/<([^<>]+)>/, '<*\1*>') unless codeblock
# 2. i also prefer explicit [optional options], so escape those as well
line.gsub!(/(?<!\!)\[([^\[\]]+)\]/, '\[[\1]\]') unless codeblock
# 3. ronn will get confused with just #2 when trying to mark an option without
# a reference later in the file, so provide ![foo] for those
line.gsub!(/\!\[([^\[\]]+)\]/, '\[\1\]') unless codeblock
# 4. #2 and #3 both screw with normal markdown links, so provide {foo}
# instead. this is all we really need, since URL labels don't make any sense
# within roff output
line.gsub!(/\{([^\{\}]+)\}/, '[\1](\1)') unless codeblock
puts line
end