summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sphinx/builders/websupport.py6
-rw-r--r--sphinx/websupport/api.py7
-rw-r--r--sphinx/websupport/document.py22
-rw-r--r--sphinx/writers/websupport.py23
4 files changed, 30 insertions, 28 deletions
diff --git a/sphinx/builders/websupport.py b/sphinx/builders/websupport.py
index d39bbd6de..f6b64849c 100644
--- a/sphinx/builders/websupport.py
+++ b/sphinx/builders/websupport.py
@@ -26,7 +26,7 @@ class WebSupportBuilder(PickleHTMLBuilder):
self.translator_class = WebSupportTranslator
def write_doc(self, docname, doctree):
- # The translator needs the docuname to generate ids.
+ # The translator needs the docname to generate ids.
self.docname = docname
PickleHTMLBuilder.write_doc(self, docname, doctree)
@@ -38,10 +38,8 @@ class WebSupportBuilder(PickleHTMLBuilder):
self.app.emit('html-page-context', pagename, ctx)
# Instead of pickling ctx as PickleHTMLBuilder does, we
- # create a Document object and pickle that.
+ # have created a Document object and pickle that.
document = self.docwriter.visitor.support_document
- document.body = ctx['body'] if 'body' in ctx else ''
- document.title = ctx['title'] if 'title' in ctx else ''
doc_filename = path.join(self.outdir,
os_path(pagename) + self.out_suffix)
diff --git a/sphinx/websupport/api.py b/sphinx/websupport/api.py
index 3cf112a30..eca24fb5e 100644
--- a/sphinx/websupport/api.py
+++ b/sphinx/websupport/api.py
@@ -12,17 +12,14 @@
import cPickle as pickle
from os import path
-from jinja2 import Template
-
from sphinx.application import Sphinx
class WebSupport(object):
- def init(self, srcdir, outdir='', comment_html=''):
+ def init(self, srcdir, outdir=''):
self.srcdir = srcdir
self.outdir = outdir or path.join(self.srcdir, '_build',
'websupport')
- self.comment_template = Template(comment_html)
def build(self, **kwargs):
doctreedir = kwargs.pop('doctreedir',
@@ -35,6 +32,4 @@ class WebSupport(object):
infilename = path.join(self.outdir, docname + '.fpickle')
f = open(infilename, 'rb')
document = pickle.load(f)
- # The document renders the comment_template.
- document.comment_template = self.comment_template
return document
diff --git a/sphinx/websupport/document.py b/sphinx/websupport/document.py
index d1f5677bb..16a60934b 100644
--- a/sphinx/websupport/document.py
+++ b/sphinx/websupport/document.py
@@ -18,20 +18,14 @@ from sphinx import addnodes
class Document(object):
"""A single Document such as 'index'."""
def __init__(self):
- self.commentable_nodes = []
- self.template = None
+ self.slices = []
- def add_commentable(self, node_id, rst_source=''):
- node = CommentableNode(node_id, rst_source)
+ def add_slice(self, html, id=None, commentable=False):
+ slice = HTMLSlice(html, id, commentable)
+ self.slices.append(slice)
- def render_comment(self, id):
- return self.comment_template.render(id=id)
-
- def render_html(self, comments=False):
- template = Template(self.body)
- return template.render(render_comment=self.render_comment)
-
-class CommentableNode(object):
- def __init__(self, id, rst_source=''):
+class HTMLSlice(object):
+ def __init__(self, html, id, commentable):
+ self.html = html
self.id = id
- self.rst_source=''
+ self.commentable = commentable
diff --git a/sphinx/writers/websupport.py b/sphinx/writers/websupport.py
index 3b2507558..e712b1339 100644
--- a/sphinx/writers/websupport.py
+++ b/sphinx/writers/websupport.py
@@ -18,12 +18,27 @@ class WebSupportTranslator(HTMLTranslator):
"""
def __init__(self, builder, *args, **kwargs):
HTMLTranslator.__init__(self, builder, *args, **kwargs)
+ self.init_support()
+
+ def init_support(self):
self.support_document = Document()
self.current_id = 0
+
+ def handle_visit_commentable(self, node):
+ self.support_document.add_slice(''.join(self.body))
+ self.body = []
+
+ def handle_depart_commentable(self, node):
+ slice_id = '%s-%s' % (self.builder.docname, self.current_id)
+ self.support_document.add_slice(''.join(self.body),
+ slice_id, commentable=True)
+ self.body = []
+ self.current_id += 1
+
+ def visit_paragraph(self, node):
+ HTMLTranslator.visit_paragraph(self, node)
+ self.handle_visit_commentable(node)
def depart_paragraph(self, node):
HTMLTranslator.depart_paragraph(self, node)
- self.support_document.add_commentable(self.current_id)
- self.body.append("{{ render_comment('%s-p%s') }}" %
- (self.builder.docname, self.current_id))
- self.current_id += 1
+ self.handle_depart_commentable(node)