Rev 5223: Start implementing references, most of them are @uref ones. in file:///home/vila/src/bzr/bugs/219334-texinfo/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Jul 8 17:30:03 BST 2010


At file:///home/vila/src/bzr/bugs/219334-texinfo/

------------------------------------------------------------
revno: 5223
revision-id: v.ladeuil+lp at free.fr-20100708163003-4ry49f1u14uft2mt
parent: v.ladeuil+lp at free.fr-20100707150314-7i5po3dwg8umiv8x
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: texinfo
timestamp: Thu 2010-07-08 18:30:03 +0200
message:
  Start implementing references, most of them are @uref ones.
  
  * bzrlib/tests/doc_generate/writers/test_texinfo.py:
  (TestSections.test_sections): Start testing references.
  
  * bzrlib/doc_generate/writers/texinfo.py:
  (TexinfoTranslator.__init__): Add a 'builder' attribute.
  (TexinfoTranslator.depart_reference): Handles @uref references.
-------------- next part --------------
=== modified file 'bzrlib/doc_generate/writers/texinfo.py'
--- a/bzrlib/doc_generate/writers/texinfo.py	2010-07-05 17:05:31 +0000
+++ b/bzrlib/doc_generate/writers/texinfo.py	2010-07-08 16:30:03 +0000
@@ -59,9 +59,10 @@
 
     def __init__(self, document, builder):
         nodes.NodeVisitor.__init__(self, document)
+        self.builder = builder
         # toctree uses some nodes for different purposes (namely:
         # compact_paragraph, bullet_list) that needs to know when they are
-        # proessing a toctree. The following attributes take care of the needs.
+        # processing a toctree.
         self.in_toctree = False
         # sections can be embedded and produce different directives depending
         # on the depth.
@@ -121,6 +122,8 @@
             set_item_collector(node, 'reference')
 
     def depart_compact_paragraph(self, node):
+        # FIXME: Using a different visitor specific to toctree may be a better
+        # design and makes code clearer. -- vila 20100708
         if node.has_key('toctree'):
             node.parent.collect_text('@menu\n')
             node.parent.collect_text(''.join(node['text']))
@@ -438,13 +441,22 @@
         set_item_collector(node, 'text')
 
     def depart_reference(self, node):
+        anchorname = node.get('anchorname', None)
+        refuri = node.get('refuri', None)
+        refid = node.get('refid', None)
+        text = ''.join(node['text'])
         collect = getattr(node.parent, 'collect_reference', None)
         if collect is not None:
-            # FIXME: this handle only the toctree references so far.
-            collect((node.get('anchorname', ''),
-                     node.get('refuri', ''),
-                     ''.join(node['text']),
-                     ))
+            if not self.in_toctree:
+                raise AssertionError('collect_reference is specific to toctree')
+            # FIXME: this handles only the toctree references so far.
+            if anchorname is None:
+                anchorname = ''
+            if refuri is None:
+                refuri = ''
+            collect((anchorname, refuri, text))
+        elif refuri is not None:
+           node.parent.collect_text('@uref{%s,%s}' % (refuri, text))
 
     def visit_footnote_reference(self, node):
         raise nodes.SkipNode # Not implemented yet

=== modified file 'bzrlib/tests/doc_generate/writers/test_texinfo.py'
--- a/bzrlib/tests/doc_generate/writers/test_texinfo.py	2010-07-06 13:22:32 +0000
+++ b/bzrlib/tests/doc_generate/writers/test_texinfo.py	2010-07-08 16:30:03 +0000
@@ -278,3 +278,17 @@
 
 @heading thing one
 No idea how to call that, but sphinx says it's a paragraph.''')
+
+
+class TestReferences(test_dg.TestSphinx):
+
+    def test_uref(self):
+        self.create_content('''\
+The `example web site`_ is nice.
+
+.. _example web site: http://www.example.com/
+''')
+        self.assertContent('''\
+The @uref{http://www.example.com/,example web site} is nice.''')
+
+



More information about the bazaar-commits mailing list