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

Backmatter Support #116

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions lib/polytexnic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def default_language_labels
{"chapter"=>{"word"=>"Chapter", "order"=>"standard"},
"section"=>"Section", "table"=>"Table", "figure"=>"Figure",
"fig"=>"Fig", "aside"=>"Box", "listing"=>"Listing",
"equation"=>"Equation", "eq"=>"Eq", "frontmatter"=>"Frontmatter",
"contents"=>"Contents"}
"equation"=>"Equation", "eq"=>"Eq", "frontmatter"=>"Frontmatter",
"backmatter"=>"Backmatter", "contents"=>"Contents"}
end

def markdown?
Expand Down
26 changes: 26 additions & 0 deletions lib/polytexnic/postprocessors/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def xml_to_html(xml)
math(doc)
frontmatter(doc)
mainmatter(doc)
backmatter(doc)
footnotes(doc)
table_of_contents(doc)
add_noindent(doc)
Expand Down Expand Up @@ -285,6 +286,17 @@ def frontmatter(doc)
end
end

# Handles backmatter (if any).
def backmatter(doc)
doc.xpath('//backmatter').each do |node|
node.name = 'div'
node['id'] = 'backmatter'
node['data-number'] = 99999
node.parent << node.dup()
node.remove
end
end

# Handles mainmatter.
def mainmatter(doc)
doc.xpath('//mainmatter').each do |node|
Expand Down Expand Up @@ -1342,6 +1354,9 @@ def table_of_contents(doc)
toc.remove_attribute 'depth'
html = []
current_depth = 0
found_backmatter_start = false
found_fragment_links = false

doc.css('div').each do |node|
case node['class']
when 'chapter'
Expand All @@ -1359,6 +1374,17 @@ def table_of_contents(doc)
current_depth -= 1
end
current_depth = 1

# Handle backmatter table of contents
# to track start of backmatter plus
# making sure the links are working
if node.parent['data-number'] == "99999"
if not found_backmatter_start
node['class'] += ' backmatter-start'
found_backmatter_start = true
end
node['class'] += ' backmatter'
end
insert_li(html, node)
when 'section'
html << '<ul>' if article? && current_depth == 0
Expand Down