[gnuplot] Dedent code blocks

pull/1158/head
Jed Fox 5 years ago
parent 712ff2ae3d
commit 5adb7a7b32

@ -36,6 +36,10 @@ module Docs
node.remove if node.content.strip.empty? node.remove if node.content.strip.empty?
end end
css('pre').each do |node|
node.content = dedent(node.content)
end
# links generated are of the form (NB: some might have been removed): # links generated are of the form (NB: some might have been removed):
# <B>{text} (p.&nbsp;<A HREF="{target}"><IMG ALT="[*]" SRC="crossref.png"></A>)<A NAME="{anchor}"></A></B> # <B>{text} (p.&nbsp;<A HREF="{target}"><IMG ALT="[*]" SRC="crossref.png"></A>)<A NAME="{anchor}"></A></B>
# transform to <b><a href="{target}>{text}</a></b> # transform to <b><a href="{target}>{text}</a></b>
@ -56,6 +60,25 @@ module Docs
doc doc
end end
private
def dedent string
lines = string.split "\n"
indent = lines.reduce Float::INFINITY do |least, line|
if line == ''
least
else
[least, line.index(line.lstrip)].min
end
end
if indent == Float::INFINITY
string
else
lines
.map { |line| line[indent..] || '' }
.join("\n")
end
end
end end
end end
end end

Loading…
Cancel
Save