[sgala]Do not depend on docutils if we don't use rst xhtml generator. See #316
This commit is contained in:
parent
d55e56f0b9
commit
53f8b119bc
|
@ -547,7 +547,7 @@ class ChatControlBase(MessageControl):
|
||||||
end = True
|
end = True
|
||||||
textview.print_conversation_line(text, jid, kind, name, tim,
|
textview.print_conversation_line(text, jid, kind, name, tim,
|
||||||
other_tags_for_name, other_tags_for_time, other_tags_for_text,
|
other_tags_for_name, other_tags_for_time, other_tags_for_text,
|
||||||
subject, old_kind, xhtml)
|
subject, old_kind, xhtml = xhtml)
|
||||||
|
|
||||||
if not count_as_new:
|
if not count_as_new:
|
||||||
return
|
return
|
||||||
|
@ -1254,7 +1254,9 @@ class ChatControl(ChatControlBase):
|
||||||
kind = 'outgoing'
|
kind = 'outgoing'
|
||||||
name = gajim.nicks[self.account]
|
name = gajim.nicks[self.account]
|
||||||
if not xhtml and not encrypted and gajim.config.get('rst_formatting_outgoing_messages'):
|
if not xhtml and not encrypted and gajim.config.get('rst_formatting_outgoing_messages'):
|
||||||
xhtml = '<body xmlns="%s">%s</body>' % (NS_XHTML, create_xhtml(text))
|
xhtml = create_xhtml(text)
|
||||||
|
if xhtml:
|
||||||
|
xhtml = '<body xmlns="%s">%s</body>' % (NS_XHTML, xhtml)
|
||||||
ChatControlBase.print_conversation_line(self, text, kind, name, tim,
|
ChatControlBase.print_conversation_line(self, text, kind, name, tim,
|
||||||
subject = subject, old_kind = self.old_msg_kind, xhtml = xhtml)
|
subject = subject, old_kind = self.old_msg_kind, xhtml = xhtml)
|
||||||
if text.startswith('/me ') or text.startswith('/me\n'):
|
if text.startswith('/me ') or text.startswith('/me\n'):
|
||||||
|
|
|
@ -678,7 +678,7 @@ class Connection(ConnectionHandlers):
|
||||||
user_nick = None, xhtml = None):
|
user_nick = None, xhtml = None):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
if not xhtml and gajim.config.get('rst_formatting_outgoing_messages'):
|
if msg and not xhtml and gajim.config.get('rst_formatting_outgoing_messages'):
|
||||||
xhtml = create_xhtml(msg)
|
xhtml = create_xhtml(msg)
|
||||||
if not msg and chatstate is None:
|
if not msg and chatstate is None:
|
||||||
return
|
return
|
||||||
|
|
|
@ -14,19 +14,23 @@
|
||||||
## GNU General Public License for more details.
|
## GNU General Public License for more details.
|
||||||
##
|
##
|
||||||
|
|
||||||
from docutils import io
|
try:
|
||||||
from docutils.core import Publisher
|
from docutils import io
|
||||||
from docutils.parsers.rst import roles
|
from docutils.core import Publisher
|
||||||
|
from docutils.parsers.rst import roles
|
||||||
def jep_reference_role(role, rawtext, text, lineno, inliner,
|
from docutils import nodes,utils
|
||||||
|
from docutils.parsers.rst.roles import set_classes
|
||||||
|
except:
|
||||||
|
def create_xhtml(text):
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
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.parsers.rst.roles import set_classes
|
|
||||||
|
|
||||||
jep_base_url = 'http://www.jabber.org/jeps/'
|
jep_base_url = 'http://www.jabber.org/jeps/'
|
||||||
jep_url = 'jep-%04d.html'
|
jep_url = 'jep-%04d.html'
|
||||||
|
@ -46,12 +50,12 @@ def jep_reference_role(role, rawtext, text, lineno, inliner,
|
||||||
**options)
|
**options)
|
||||||
return [node], []
|
return [node], []
|
||||||
|
|
||||||
roles.register_canonical_role('jep-reference', jep_reference_role)
|
roles.register_canonical_role('jep-reference', jep_reference_role)
|
||||||
from docutils.parsers.rst.languages.en import roles
|
from docutils.parsers.rst.languages.en import roles
|
||||||
roles['jep-reference'] = 'jep-reference'
|
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*
|
||||||
|
@ -68,12 +72,15 @@ class HTMLGenerator:
|
||||||
self.pub.set_components(reader_name='standalone',
|
self.pub.set_components(reader_name='standalone',
|
||||||
parser_name='restructuredtext',
|
parser_name='restructuredtext',
|
||||||
writer_name='html')
|
writer_name='html')
|
||||||
#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
|
||||||
# FIXME: 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)
|
||||||
|
@ -89,14 +96,17 @@ class HTMLGenerator:
|
||||||
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)
|
||||||
#kludge until we can get docutils to stop generating (rare) entities
|
# kludge until we can get docutils to stop generating (rare)
|
||||||
return u'\u00a0'.join(self.pub.writer.parts['fragment'].strip().split(' '))
|
# entities
|
||||||
|
return u'\u00a0'.join(self.pub.writer.parts['fragment'].strip().split(
|
||||||
|
' '))
|
||||||
|
|
||||||
Generator = HTMLGenerator()
|
Generator = HTMLGenerator()
|
||||||
|
|
||||||
def create_xhtml(text):
|
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::
|
||||||
|
|
Loading…
Reference in New Issue