super(HtmlFormat, self).__init__(doc)
self.standalone = standalone
- def build(self):
+ def build(self, files_path=None):
if self.standalone:
tmpl = get_resource("formats/html/res/html_standalone.html")
else:
t = etree.parse(tmpl)
ctx = Context(format=self)
+ ctx.files_path = files_path
ctx.toc = TOC()
ctx.toc_level = 0
ctx.footnotes = Footnotes()
t.find('.//div[@id="content"]').extend(
self.render(self.doc.edoc.getroot(), ctx))
- t.find('.//div[@id="toc"]').append(ctx.toc.render())
+ #t.find('.//div[@id="toc"]').append(ctx.toc.render())
t.find('.//div[@id="footnotes"]').extend(ctx.footnotes.output)
return OutputFile.from_string(etree.tostring(
pass
+class Silent(TreeRenderer):
+ def render_text(self, text, ctx):
+ root, inner = self.text_container()
+ return root
+
+
class Footnotes(object):
def __init__(self):
self.counter = 0
# Renderers
HtmlFormat.renderers.register(core.Aside, None, NaturalText('aside'))
+HtmlFormat.renderers.register(core.Aside, 'comment', Silent())
class AsideFootnote(NaturalText):
def render(self, element, ctx):
return root
HtmlFormat.renderers.register(core.Aside, 'footnote', AsideFootnote())
+
+class Header(NaturalText):
+ def render(self, element, ctx):
+ root = super(Header, self).render(element, ctx)
+ if ctx.toc_level == 1:
+ d = etree.SubElement(root, 'div', {'class': "page-header"})
+ d.insert(0, root[0])
+ else:
+ root[0].tag = 'h2'
+ if root[0].text:
+ d = etree.SubElement(root[0], 'a', {'id': root[0].text, 'style': 'pointer: hand; color:#ddd; font-size:.8em'})
+ #d.text = "per"
+ return root
+
-HtmlFormat.renderers.register(core.Header, None, NaturalText('h1'))
+HtmlFormat.renderers.register(core.Header, None, Header('h1'))
HtmlFormat.renderers.register(core.Div, None, NaturalText('div'))
+
+class DivDefined(NaturalText):
+ def render(self, element, ctx):
+ output = super(DivDefined, self).render(element, ctx)
+ output[0].text = (output[0].text or '') + ':'
+ output[0].attrib['id'] = output[0].text # not so cool?
+ return output
+
+HtmlFormat.renderers.register(core.Div, 'defined', DivDefined('dt', {'style': 'display: inline-block'}))
+
+
+class DivImage(NaturalText):
+ def render(self, element, ctx):
+ output = super(DivImage, self).render(element, ctx)
+ src = element.attrib.get('src', '')
+ if src.startswith('file://'):
+ src = ctx.files_path + src[7:]
+ output[0].attrib['src'] = src
+ output[0].attrib['style'] = 'display: block; width: 60%; margin: 3em auto'
+ return output
+
+HtmlFormat.renderers.register(core.Div, 'img', DivImage('img'))
+
HtmlFormat.renderers.register(core.Div, 'item', NaturalText('li'))
HtmlFormat.renderers.register(core.Div, 'list', NaturalText('ul'))
+HtmlFormat.renderers.register(core.Div, 'list.enum', NaturalText('ol'))
+
+class DivListDefinitions(NaturalText):
+ def render(self, element, ctx):
+ output = super(DivListDefinitions, self).render(element, ctx)
+ #if ctx.toc_level > 2:
+ # output[0].attrib['style'] = 'float: right'
+ return output
+
+HtmlFormat.renderers.register(core.Div, 'list.definitions', DivListDefinitions('ul'))
HtmlFormat.renderers.register(core.Div, 'p', NaturalText('p'))
HtmlFormat.renderers.register(core.Span, 'cite', NaturalText('cite'))
HtmlFormat.renderers.register(core.Span, 'cite.code', LiteralText('code'))
HtmlFormat.renderers.register(core.Span, 'emph', NaturalText('em'))
+HtmlFormat.renderers.register(core.Span, 'emp', NaturalText('strong'))
class SpanUri(LiteralText):
def render(self, element, ctx):
root[0].attrib['href'] = element.text
return root
HtmlFormat.renderers.register(core.Span, 'uri', SpanUri('a'))
+
+class SpanLink(LiteralText):
+ def render(self, element, ctx):
+ root = super(SpanLink, self).render(element, ctx)
+ src = element.attrib.get('href', '')
+ if src.startswith('file://'):
+ src = ctx.files_path + src[7:]
+ root[0].attrib['href'] = src
+ return root
+HtmlFormat.renderers.register(core.Span, 'link', SpanLink('a'))
+