'
+ return breadcrumbs
+
+
#
# Make an array of children attached to each node in the file structure
# (It's a quasi-tree structure, and can be traversed as such.)
@@ -215,36 +271,53 @@ def FindInternalLinks(fs):
for hdr in fs:
if 'link' in hdr:
- linkDict['@@' + hdr['link']] = '/' + hdr['filename'] + '/'
+ linkDict['"@@' + hdr['link'] + '"'] = '"/' + hdr['filename'] + '/"'
+ linkDict['"@@' + hdr['link'] + '#'] = '"/' + hdr['filename'] + '/index.html#'
return linkDict
#
-# Internal links are of the form '@@link-name', which are references to the
-# 'link:' field in the part header. We have to find all occurances and replace
-# them with the appropriate link.
+# Same as above, but create anchors (for the one-page version)
#
-def FixInternalLinks(links, content, title):
+def FindInternalAnchors(fs):
+ linkDict = {}
- # Make key1|key2|key3|... out of our links keys
- pattern = re.compile('|'.join(links.keys()))
+ for hdr in fs:
+ if 'link' in hdr:
+ linkDict['"@@' + hdr['link'] + '"'] = '"#' + hdr['link'] + '"'
+ linkDict['"@@' + hdr['link'] + '#'] = '"#' + hdr['link'] + '"'
- # Use a lambda callback to substitute each occurance found
- result = pattern.sub(lambda x: links[x.group()], content)
+ return linkDict
- # Check for missing link targets, and report them to the user
- match = re.findall('"@@.*"', result)
- if len(match) > 0:
- print('\nMissing link target' + ('s' if len(match) > 1 else '') + ' in "' + title + '":')
+#
+# Internal links are of the form '@@link-name', which are references to the
+# 'link:' field in the part header. We have to find all occurrences and replace
+# them with the appropriate link.
+#
+def FixInternalLinks(links, content, title):
+ global findLinks
+ match = findLinks.findall(content)
+ missing = []
+ if len(match) > 0:
for s in match:
- print(' ' + s[3:-1])
+ if s in links:
+ content = content.replace(s, links[s])
+ else:
+ missing.append(s)
+
+ # Report missing link targets to the user (if any)
+ if len(missing) > 0:
+ print('\nMissing link target' + ('s' if len(missing) > 1 else '') + ' in "' + title + '":')
+
+ for s in missing:
+ print(' ' + s)
print()
- return result
+ return content
#
@@ -252,14 +325,15 @@ def FixInternalLinks(links, content, title):
# looking at currently
#
def BuildList(lst, fs, pagePos, cList):
- content = '\n\n
\n'
+ content = '
\n'
for i in range(len(lst)):
curPos = lst[i]
- nextPos = lst[i + 1] if i + 1 < len(lst) else len(fs)
+ nextPos = lst[i + 1] if i + 1 < len(lst) else len(fs)
active = ' class=active' if curPos == pagePos else ''
- content = content + '
\n'
# If the current page is our page, and it has children, enumerate them
if curPos == pagePos:
@@ -271,12 +345,58 @@ def BuildList(lst, fs, pagePos, cList):
elif (pagePos > curPos) and (pagePos < nextPos):
content = content + BuildList(cList[curPos], fs, pagePos, cList)
- content = content + '
\n'
+ content = content + '
\n'
+
+ return content
+
+
+#
+# Builds the sidebar for the one-page version
+#
+def BuildOnePageSidebar(fs):
+
+ content = '\n\n
\n'
+ lvl = 0
+ levelNums = [0] * 5
+
+ for i in range(len(fs)):
+ # Handle Part/Chapter/subchapter/section/subsection numbering
+ level = fs[i]['level']
+
+ if level < 2:
+ levelNums[2] = 0
+
+ levelNums[level] = levelNums[level] + 1;
+ j = level
+ txtlevel = ''
+
+ while j > 0: #level 0 is the part number which is not shown
+ txtlevel = str(levelNums[j]) + '.' + txtlevel
+ j = j - 1
+
+ if len(txtlevel) > 0:
+ txtlevel = txtlevel[:-1] + ' - '
+
+ if 'link' in fs[i]:
+ anchor = fs[i]['link']
+ else:
+ anchor = fs[i]['filename']
+
+ while lvl < level:
+ content = content + '
\n'
+
+ content = content + '\n'
return content
+
#
# Create link sidebar given a position in the list.
#
@@ -284,8 +404,9 @@ def CreateLinkSidebar(fs, pos, childList):
# Build the list recursively from the top level nodes
content = BuildList(FindTopLevelNodes(fs), fs, pos, childList)
- # Shove the TOC link in the top...
- content = content[:7] + '