Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More cleanup #42

Merged
merged 7 commits into from
Nov 9, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
More control over resulting HTML.
  • Loading branch information
sixtyfive committed Nov 4, 2016
commit 06787ed308a7a3526e68f454dcb5f3c2a93576ec
49 changes: 31 additions & 18 deletions tafaseer_group/postprocess_corpus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,40 @@ def clean_yaml
end

def clean_html
@html.css('font').each do |node|
node.remove if node.inner_text == ''
@doc = Nokogiri::HTML.fragment('') do |config|
config.strict.nonet.noent.noblanks
end
@html.css('section').each do |section|
nodes = section.css('div[align="right"][dir="rtl"] font[color]')
nodes.each do |node|
node.name = 'p'
case node['color']
when 'Olive'
node['class'] = 'poetry_or_grammar'
when 'Red'
node['class'] = 'hadith'
when 'ForestGreen'
node['class'] = 'quran'
end
node.xpath('@color|.//@color').remove
builder = Nokogiri::HTML::Builder.with(@doc) do |doc|
@html.css('section').each do |section|
doc.section {
nodes = section.css('div[align="right"][dir="rtl"] font[color]')
nodes.each do |node|
unless node.inner_text.empty?
case node['color']
when 'Olive'
css_class = 'poetry_or_grammar'
when 'Red'
css_class = 'hadith'
when 'ForestGreen'
css_class = 'quran'
end
if css_class.nil?
doc.p {
doc.text node.inner_text
}
else
doc.p(:class => css_class) {
doc.text node.inner_text
}
end
end
end
}
end
@yaml['text'] << nodes.to_html
end
@yaml['text'] << @doc.to_html
end
end

# TafsirFile.convert(testfile)
files.each {|f| TafsirFile.convert(f)}
TafsirFile.convert(testfile)
# files.each {|f| TafsirFile.convert(f)}