Skip to content

Commit

Permalink
#29: fix some option list issues, in HTML, LaTeX and text writers.
Browse files Browse the repository at this point in the history
  • Loading branch information
birkenfeld committed Nov 3, 2008
1 parent 25f63fe commit 3241458
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ New features added
Bugs fixed
----------

* Support option lists in the text writer. Make sure that dashes
introducing long option names are not contracted to en-dashes.

* Support the "scale" option for images in HTML output.

* Properly escape quotes in HTML help attribute values.
Expand Down
7 changes: 7 additions & 0 deletions sphinx/htmlwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,13 @@ def visit_productionlist(self, node):
finally:
self.no_smarty -= 1

def visit_option(self, node):
self.no_smarty += 1
HTMLTranslator.visit_option(self, node)
def depart_option(self, node):
self.no_smarty -= 1
HTMLTranslator.depart_option(self, node)

def bulk_text_processor(self, text):
if self.no_smarty <= 0:
return sphinx_smarty_pants(text)
Expand Down
6 changes: 3 additions & 3 deletions sphinx/latexwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,9 +1069,9 @@ def depart_option_list_item(self, node):
pass

def visit_option_string(self, node):
pass
def depart_option_string(self, node):
pass
ostring = node.astext()
self.body.append(self.encode(ostring.replace('--', u'--')))
raise nodes.SkipNode

def visit_description(self, node):
self.body.append( ' ' )
Expand Down
40 changes: 40 additions & 0 deletions sphinx/textwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,46 @@ def depart_citation(self, node):
def visit_label(self, node):
raise nodes.SkipNode

# XXX: option list could use some better styling

def visit_option_list(self, node):
pass
def depart_option_list(self, node):
pass

def visit_option_list_item(self, node):
self.new_state(0)
def depart_option_list_item(self, node):
self.end_state()

def visit_option_group(self, node):
self._firstoption = True
def depart_option_group(self, node):
self.add_text(' ')

def visit_option(self, node):
if self._firstoption:
self._firstoption = False
else:
self.add_text(', ')
def depart_option(self, node):
pass

def visit_option_string(self, node):
pass
def depart_option_string(self, node):
pass

def visit_option_argument(self, node):
self.add_text(node['delimiter'])
def depart_option_argument(self, node):
pass

def visit_description(self, node):
pass
def depart_description(self, node):
pass

def visit_tabular_col_spec(self, node):
raise nodes.SkipNode

Expand Down
2 changes: 2 additions & 0 deletions sphinx/util/texescape.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
(u'±', ur'\(\pm\)'),
(u'→', ur'\(\rightarrow\)'),
(u'‣', ur'\(\rightarrow\)'),
# used to separate -- in options
(u'', ur'{}'),
# map some special Unicode characters to similar ASCII ones
(u'─', ur'-'),
(u'⎽', ur'\_'),
Expand Down
5 changes: 5 additions & 0 deletions tests/root/markup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ This is a side note.

This tests :CLASS:`role names in uppercase`.

Option list:

-h help
--help also help

.. centered:: LICENSE AGREEMENT

.. acks::
Expand Down
1 change: 1 addition & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
".//meta[@name='keywords'][@content='docs, sphinx']": '',
".//a[@href='contents.html#ref1']": '',
".//div[@id='label']": '',
".//span[@class='option']": '--help',
},
'desc.html': {
".//dt[@id='mod.Cls.meth1']": '',
Expand Down

0 comments on commit 3241458

Please sign in to comment.