Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/bin/check-indent.rb
1677 views
1
#!/usr/bin/env ruby
2
require 'find'
3
require 'nokogiri'
4
5
def check_indent(file)
6
doc = Nokogiri::HTML(File.open(file))
7
# Find all <pre> tags
8
# <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
9
ec = false
10
doc.css('div.language-plaintext.highlighter-rouge div.highlight pre.highlight code').each do |pre|
11
# Get the text content of the <pre> tag
12
content = pre.text
13
# Split the content by newlines
14
lines = content.split("\n")
15
16
# If all lines look like URLs:
17
if lines.all? { |line| line =~ %r{://} }
18
# If any are space indented
19
lines.each do |line|
20
if line =~ /^\s+/
21
puts "#{file}: Indentation error: #{line}"
22
ec = true
23
end
24
end
25
end
26
end
27
ec
28
end
29
30
should_exit = false
31
Find.find('./_site/training-material/topics/') do |path|
32
if path =~ (/tutorial.*\.html$/) && check_indent(path)
33
should_exit = true
34
end
35
end
36
37
if should_exit
38
exit 1
39
end
40
#
41
# check_indent(ARGV[0])
42
43