coding standards et all
This commit is contained in:
		
							parent
							
								
									817a8f6849
								
							
						
					
					
						commit
						9c13aae8ba
					
				
					 1 changed files with 43 additions and 27 deletions
				
			
		| 
						 | 
					@ -1,14 +1,30 @@
 | 
				
			||||||
 | 
					##	rst_xhtml_generator.py
 | 
				
			||||||
 | 
					##
 | 
				
			||||||
 | 
					## Copyright (C) 2006 Yann Le Boulanger <asterix@lagaule.org>
 | 
				
			||||||
 | 
					## Copyright (C) 2006 Nikos Kouremenos <kourem@gmail.com>
 | 
				
			||||||
 | 
					## Copyright (C) 2006 Santiago Gala
 | 
				
			||||||
 | 
					##
 | 
				
			||||||
 | 
					## This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					## it under the terms of the GNU General Public License as published
 | 
				
			||||||
 | 
					## by the Free Software Foundation; version 2 only.
 | 
				
			||||||
 | 
					##
 | 
				
			||||||
 | 
					## This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					## but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					## GNU General Public License for more details.
 | 
				
			||||||
 | 
					##
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from docutils import io
 | 
					from docutils import io
 | 
				
			||||||
from docutils.core import Publisher
 | 
					from docutils.core import Publisher
 | 
				
			||||||
from docutils.parsers.rst import roles
 | 
					from docutils.parsers.rst import roles
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def jep_reference_role(role, rawtext, text, lineno, inliner,
 | 
					def jep_reference_role(role, rawtext, text, lineno, inliner,
 | 
				
			||||||
	options={}, content=[]):
 | 
						options={}, content=[]):
 | 
				
			||||||
	"""Role to make handy references to Jabber Enhancement Proposals (JEP).
 | 
						'''Role to make handy references to Jabber Enhancement Proposals (JEP).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	 	Use as :JEP:`71` (or jep, or jep-reference).
 | 
						 	Use as :JEP:`71` (or jep, or jep-reference).
 | 
				
			||||||
		Modeled after the sample in docutils documentation.
 | 
							Modeled after the sample in docutils documentation.
 | 
				
			||||||
	"""
 | 
						'''
 | 
				
			||||||
	from docutils import nodes,utils
 | 
						from docutils import nodes,utils
 | 
				
			||||||
	from docutils.parsers.rst.roles import set_classes
 | 
						from docutils.parsers.rst.roles import set_classes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,11 +52,11 @@ roles['jep-reference'] = 'jep-reference'
 | 
				
			||||||
roles['jep'] = 'jep-reference'
 | 
					roles['jep'] = 'jep-reference'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class HTMLGenerator:
 | 
					class HTMLGenerator:
 | 
				
			||||||
	"""Really simple HTMLGenerator starting from publish_parts.
 | 
						'''Really simple HTMLGenerator starting from publish_parts.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	It reuses the docutils.core.Publisher class, which means it is *not*
 | 
						It reuses the docutils.core.Publisher class, which means it is *not*
 | 
				
			||||||
	threadsafe.
 | 
						threadsafe.
 | 
				
			||||||
	"""
 | 
						'''
 | 
				
			||||||
	def __init__(self,
 | 
						def __init__(self,
 | 
				
			||||||
		settings_spec=None,
 | 
							settings_spec=None,
 | 
				
			||||||
		settings_overrides=dict(report_level=5, halt_level=5),
 | 
							settings_overrides=dict(report_level=5, halt_level=5),
 | 
				
			||||||
| 
						 | 
					@ -55,9 +71,9 @@ class HTMLGenerator:
 | 
				
			||||||
		#hack: JEP-0071 does not allow HTML char entities, so we hack our way out of it.
 | 
							#hack: JEP-0071 does not allow HTML char entities, so we hack our way out of it.
 | 
				
			||||||
		# — == u"\u2014"
 | 
							# — == u"\u2014"
 | 
				
			||||||
		# a setting to only emit charater entities in the writer would be nice
 | 
							# a setting to only emit charater entities in the writer would be nice
 | 
				
			||||||
		# TODO: several   are emitted, and they are explicitly forbidden in the JEP
 | 
							# FIXME: several   are emitted, and they are explicitly forbidden in the JEP
 | 
				
			||||||
		#   ==  u"\u00a0"
 | 
							#   ==  u"\u00a0"
 | 
				
			||||||
		self.pub.writer.translator_class.attribution_formats["dash"] = (u"\u2014", "")
 | 
							self.pub.writer.translator_class.attribution_formats['dash'] = (u'\u2014', '')
 | 
				
			||||||
		self.pub.process_programmatic_settings(settings_spec,
 | 
							self.pub.process_programmatic_settings(settings_spec,
 | 
				
			||||||
			settings_overrides,
 | 
								settings_overrides,
 | 
				
			||||||
			config_section)
 | 
								config_section)
 | 
				
			||||||
| 
						 | 
					@ -67,9 +83,9 @@ class HTMLGenerator:
 | 
				
			||||||
		destination=None,
 | 
							destination=None,
 | 
				
			||||||
		destination_path=None,
 | 
							destination_path=None,
 | 
				
			||||||
		enable_exit_status=None):
 | 
							enable_exit_status=None):
 | 
				
			||||||
		""" Create xhtml for a fragment of IM dialog.
 | 
							''' Create xhtml for a fragment of IM dialog.
 | 
				
			||||||
		We can use the source_name to store info about
 | 
							We can use the source_name to store info about
 | 
				
			||||||
		the message."""
 | 
							the message.'''
 | 
				
			||||||
		self.pub.set_source(text, None)
 | 
							self.pub.set_source(text, None)
 | 
				
			||||||
		self.pub.set_destination(destination, destination_path)
 | 
							self.pub.set_destination(destination, destination_path)
 | 
				
			||||||
		output = self.pub.publish(enable_exit_status=enable_exit_status)
 | 
							output = self.pub.publish(enable_exit_status=enable_exit_status)
 | 
				
			||||||
| 
						 | 
					@ -82,7 +98,7 @@ def create_xhtml(text):
 | 
				
			||||||
	return Generator.create_xhtml(text)
 | 
						return Generator.create_xhtml(text)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
	print Generator.create_xhtml("""
 | 
						print Generator.create_xhtml('''
 | 
				
			||||||
test::
 | 
					test::
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  >>> print 1
 | 
					  >>> print 1
 | 
				
			||||||
| 
						 | 
					@ -92,9 +108,9 @@ test::
 | 
				
			||||||
 | 
					
 | 
				
			||||||
this `` should    trigger`` should trigger the   problem.
 | 
					this `` should    trigger`` should trigger the   problem.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
""")
 | 
					''')
 | 
				
			||||||
	print Generator.create_xhtml("""
 | 
						print Generator.create_xhtml('''
 | 
				
			||||||
*test1
 | 
					*test1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
test2_
 | 
					test2_
 | 
				
			||||||
""")
 | 
					''')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue