Skip to content

Commit

Permalink
[wip] presentation htmlsanity something something
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Jan 10, 2022
1 parent f04b68b commit 7f46036
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion plugins/m/htmlsanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,11 @@ def depart_image(self, node):

# Use HTML5 <section> tag for sections (instead of <div class="section">)
def visit_section(self, node):
atts = {}
if 'styles' in node: atts['styles'] = '; '.join(node['styles'])
self.section_level += 1
self.body.append(
self.starttag(node, 'section'))
self.starttag(node, 'section', **atts))

def depart_section(self, node):
self.section_level -= 1
Expand Down Expand Up @@ -636,6 +638,54 @@ def depart_title(self, node):
self.html_title.extend(self.body)
del self.body[:]

## h1–h6 elements must not be used to markup subheadings, subtitles,
## alternative titles and taglines unless intended to be the heading for a
## new section or subsection.
## -- http://www.w3.org/TR/html/sections.html#headings-and-sections
#def visit_subtitle(self, node):
#if isinstance(node.parent, nodes.sidebar):
#classes = 'sidebar-subtitle'
#elif isinstance(node.parent, nodes.document):
#classes = 'subtitle'
#self.in_document_title = len(self.body)
#elif isinstance(node.parent, nodes.section):
#classes = 'section-subtitle'
#self.body.append(self.starttag(node, 'p', '', CLASS=classes))

#def depart_subtitle(self, node):
#self.body.append('</p>\n')
#if self.in_document_title:
#self.subtitle = self.body[self.in_document_title:-1]
#self.in_document_title = 0
#self.body_pre_docinfo.extend(self.body)
#self.html_subtitle.extend(self.body)
#del self.body[:]
# Use <h*> for subtitles (deprecated in HTML 5)
def visit_subtitle(self, node):
if isinstance(node.parent, nodes.sidebar):
self.body.append(self.starttag(node, 'p', '',
CLASS='sidebar-subtitle'))
self.context.append('</p>\n')
elif isinstance(node.parent, nodes.document):
self.body.append(self.starttag(node, 'h2', '', CLASS='subtitle'))
self.context.append('</h2>\n')
self.in_document_title = len(self.body)
elif isinstance(node.parent, nodes.section):
tag = 'h%s' % (self.section_level + self.initial_header_level - 1)
self.body.append(
self.starttag(node, tag, '', CLASS='section-subtitle') +
self.starttag({}, 'span', '', CLASS='section-subtitle'))
self.context.append('</span></%s>\n' % tag)

def depart_subtitle(self, node):
self.body.append(self.context.pop())
if self.in_document_title:
self.subtitle = self.body[self.in_document_title:-1]
self.in_document_title = 0
self.body_pre_docinfo.extend(self.body)
self.html_subtitle.extend(self.body)
del self.body[:]

# <ul>, <ol>, <dl> -- verbatim copied, removing "simple" class. For <ol>
# also removing the enumtype
def visit_bullet_list(self, node):
Expand Down

0 comments on commit 7f46036

Please sign in to comment.