Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
issue #9: don't blow up on no TOC elements
Browse files Browse the repository at this point in the history
  • Loading branch information
trentm committed Feb 15, 2012
1 parent 4071c47 commit 4ab2b49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## restdown 1.2.16 (not yet released)

(nothing yet)
- [issue #9] Fix breakage if there are no TOC sections, i.e. no second h1 in
the input restdown content.


## restdown 1.2.15

Expand Down
15 changes: 9 additions & 6 deletions bin/restdown
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class RestdownError(StandardError):
class Restdowner(Markdown):
"""Markdown subclass that tweaks API TOC entries for some REST API
TOC love.
@param api_sections {list} A list of h1 section names that are API
sections, as opposed to prose introductory or explanatory sections.
If not given, or None, then all sections except the first (presumed
Expand All @@ -76,11 +76,11 @@ class Restdowner(Markdown):
def __init__(self, api_sections=None, **kwargs):
self.api_sections = api_sections
Markdown.__init__(self, **kwargs)

def reset(self):
super(Restdowner, self).reset()
self.methods = OrderedDict()

# Use this Markdown hook to:
# - exclude first h1 section from the TOC
# - do custom translation of h2 text to id (h2's are the API endpoints)
Expand Down Expand Up @@ -144,7 +144,7 @@ class Restdowner(Markdown):
break
super(Restdowner, self)._toc_add_entry(n, id, name)


_method_header_re = re.compile(
r'''^(<h2.*?>)(.*?)(</h2>)$''', re.M)
def _method_header_sub(self, match):
Expand Down Expand Up @@ -244,8 +244,11 @@ def restdown(metadata, markdown, brand_dir=None):
html = restdowner.convert(markdown)
# Add a wrapper <div> around the links in TOC elements. This allows
# full width styling of 'li' lines, even if they contain children.
metadata["toc_html"] = re.sub(r'(<a href=".*?">.*?</a>)', r'<div>\1</div>',
html.toc_html)
if html.toc_html:
metadata["toc_html"] = re.sub(r'(<a href=".*?">.*?</a>)',
r'<div>\1</div>', html.toc_html)
else:
metadata["toc_html"] = ""

# Custom css for the document based on metadata.
doc_css = ""
Expand Down

0 comments on commit 4ab2b49

Please sign in to comment.