Skip to content

Remove superfluous divs from RST generation #256

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

Merged
merged 2 commits into from
Feb 14, 2014
Merged
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
16 changes: 16 additions & 0 deletions lib/github/commands/rest2html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Brandon Keepers <bkeepers@github.com>
Bryan Veloso <bryan@revyver.com>
Chris Wanstrath <chris@ozmm.org>
Dave Abrahams <dave@boostpro.com>
Garen Torikian <garen@github.com>
Gasper Zejn <zejn@kiberpipa.org>
Michael Jones <m.pricejones@gmail.com>
Sam Whited <sam@samwhited.com>
Expand Down Expand Up @@ -50,6 +51,21 @@ SETTINGS = {
}

class GitHubHTMLTranslator(HTMLTranslator):
# removes the <div class="document"> tag wrapped around docs
# see also: http://bit.ly/1exfq2h (warning! sourceforge link.)
def depart_document(self, node):
HTMLTranslator.depart_document(self, node)
self.html_body.pop(0)
self.html_body.pop()

# technique for visiting sections, without generating additional divs
# see also: http://bit.ly/NHtyRx
def visit_section(self, node):
self.section_level += 1

def depart_section(self, node):
self.section_level -= 1

def visit_literal_block(self, node):
classes = node.attributes['classes']
if len(classes) >= 2 and classes[0] == 'code':
Expand Down
6 changes: 0 additions & 6 deletions test/markups/README.rst.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<div class="document">
<div class="section" id="header-1">
<h1>Header 1</h1>
<p>Example text.</p>
<div class="section" id="header-2">
<h2>Header 2</h2>
<ol class="arabic simple">
<li>Blah blah <tt class="docutils literal">code</tt> blah</li>
Expand Down Expand Up @@ -32,6 +29,3 @@ <h2>Header 2</h2>
</tr>
</tbody>
</table>
</div>
</div>
</div>
7 changes: 0 additions & 7 deletions test/markups/README.rst.txt.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
<div class="document">
<div class="section" id="header-1">
<h1>Header 1</h1>
<p>Example text.</p>
<div class="section" id="header-2">
<h2>Header 2</h2>
<ol class="arabic simple">
<li>Blah blah <tt class="docutils literal">code</tt> blah</li>
<li>More <tt class="docutils literal">code</tt>, hooray</li>
</ol>
</div>
</div>
</div>