updated from Docutils
This commit is contained in:
parent
4e06fbde27
commit
461747e153
|
@ -122,29 +122,37 @@ _directives = {}
|
|||
def directive(directive_name, language_module, document):
|
||||
"""
|
||||
Locate and return a directive function from its language-dependent name.
|
||||
If not found in the current language, check English.
|
||||
If not found in the current language, check English. Return None if the
|
||||
named directive cannot be found.
|
||||
"""
|
||||
normname = directive_name.lower()
|
||||
messages = []
|
||||
msg_text = []
|
||||
if _directives.has_key(normname):
|
||||
return _directives[normname], messages
|
||||
canonicalname = None
|
||||
try:
|
||||
canonicalname = language_module.directives[normname]
|
||||
except (KeyError, AttributeError):
|
||||
msg_text = ('No directive entry for "%s" in module "%s".'
|
||||
except AttributeError, error:
|
||||
msg_text.append('Problem retrieving directive entry from language '
|
||||
'module %r: %s.' % (language_module, error))
|
||||
except KeyError:
|
||||
msg_text.append('No directive entry for "%s" in module "%s".'
|
||||
% (directive_name, language_module.__name__))
|
||||
if not canonicalname:
|
||||
try:
|
||||
canonicalname = _fallback_language_module.directives[normname]
|
||||
msg_text += ('\nUsing English fallback for directive "%s".'
|
||||
msg_text.append('Using English fallback for directive "%s".'
|
||||
% directive_name)
|
||||
except KeyError:
|
||||
msg_text += ('\nTrying "%s" as canonical directive name.'
|
||||
msg_text.append('Trying "%s" as canonical directive name.'
|
||||
% directive_name)
|
||||
# The canonical name should be an English name, but just in case:
|
||||
canonicalname = normname
|
||||
warning = document.reporter.warning(
|
||||
msg_text, line=document.current_line)
|
||||
messages.append(warning)
|
||||
if msg_text:
|
||||
message = document.reporter.info(
|
||||
'\n'.join(msg_text), line=document.current_line)
|
||||
messages.append(message)
|
||||
try:
|
||||
modulename, functionname = _directive_registry[canonicalname]
|
||||
except KeyError:
|
||||
|
|
|
@ -16,6 +16,9 @@ _languages = {}
|
|||
def get_language(language_code):
|
||||
if _languages.has_key(language_code):
|
||||
return _languages[language_code]
|
||||
try:
|
||||
module = __import__(language_code, globals(), locals())
|
||||
except ImportError:
|
||||
return None
|
||||
_languages[language_code] = module
|
||||
return module
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
# Author: Miroslav Vasko
|
||||
# Contact: zemiak@zoznam.sk
|
||||
# Revision: $Revision$
|
||||
# Date: $Date$
|
||||
# Copyright: This module has been placed in the public domain.
|
||||
|
||||
"""
|
||||
Slovak-language mappings for language-dependent features of
|
||||
reStructuredText.
|
||||
"""
|
||||
|
||||
__docformat__ = 'reStructuredText'
|
||||
|
||||
|
||||
directives = {
|
||||
u'pozor': 'attention',
|
||||
u'opatrne': 'caution',
|
||||
u'nebezpe\xe8enstvo': 'danger',
|
||||
u'chyba': 'error',
|
||||
u'rada': 'hint',
|
||||
u'd\xf4le\x9eit\xe9': 'important',
|
||||
u'pozn\xe1mka': 'note',
|
||||
u'tip': 'tip',
|
||||
u'varovanie': 'warning',
|
||||
u't\xe9ma': 'topic',
|
||||
u'blok-riadkov': 'line-block',
|
||||
u'parsed-literal': 'parsed-literal',
|
||||
#u'questions': 'questions',
|
||||
#u'qa': 'questions',
|
||||
#u'faq': 'questions',
|
||||
u'meta': 'meta',
|
||||
#u'imagemap': 'imagemap',
|
||||
u'obr\xe1zok': 'image',
|
||||
u'tvar': 'figure',
|
||||
u'vlo\x9ei\x9d': 'include',
|
||||
u'raw': 'raw',
|
||||
u'nahradi\x9d': 'replace',
|
||||
u'obsah': 'contents',
|
||||
u'\xe8as\x9d': 'sectnum',
|
||||
u'\xe8as\x9d-\xe8\xedslovanie': 'sectnum',
|
||||
u'cie\xbeov\xe9-pozn\xe1mky': 'target-notes',
|
||||
#u'footnotes': 'footnotes',
|
||||
#u'citations': 'citations',
|
||||
}
|
||||
"""Slovak name to registered (in directives/__init__.py) directive name
|
||||
mapping."""
|
|
@ -21,19 +21,18 @@ directives = {
|
|||
u'notera': 'note',
|
||||
u'tips': 'tip',
|
||||
u'varning': 'warning',
|
||||
u'fr\u00e5gor': 'questions',
|
||||
# u'fr\u00e5gor': 'questions',
|
||||
# NOTE: A bit long, but recommended by http://www.nada.kth.se/dataterm/:
|
||||
u'fr\u00e5gor-och-svar': 'questions',
|
||||
u'vanliga-fr\u00e5gor': 'questions',
|
||||
# u'fr\u00e5gor-och-svar': 'questions',
|
||||
# u'vanliga-fr\u00e5gor': 'questions',
|
||||
u'meta': 'meta',
|
||||
# u'bildkarta': 'imagemap', # FIXME: Translation might be too literal.
|
||||
u'bild': 'image',
|
||||
u'figur': 'figure',
|
||||
# u'r\u00e5': 'raw', # FIXME: Translation might be too literal.
|
||||
u'r\u00e5': 'raw', # FIXME: Translation might be too literal.
|
||||
u'inneh\u00e5ll': 'contents',
|
||||
# u'fotnoter': 'footnotes',
|
||||
# u'citeringar': 'citations',
|
||||
# u'\u00e4mne': 'topic',
|
||||
u'restructuredtext-test-directive': 'restructuredtext-test-directive' }
|
||||
u'\u00e4mne': 'topic'}
|
||||
"""Swedish name to registered (in directives/__init__.py) directive name
|
||||
mapping."""
|
||||
|
|
|
@ -534,9 +534,17 @@ class Inliner:
|
|||
non_whitespace_after = r'(?![ \n])'
|
||||
# Alphanumerics with isolated internal [-._] chars (i.e. not 2 together):
|
||||
simplename = r'(?:(?!_)\w)+(?:[-._](?:(?!_)\w)+)*'
|
||||
# Valid URI characters (see RFC 2396 & RFC 2732):
|
||||
uric = r"""[-_.!~*'()[\];/:@&=+$,%a-zA-Z0-9]"""
|
||||
urilast = r"""[_~/\]a-zA-Z0-9]""" # no punctuation
|
||||
# Last URI character; same as uric but no punctuation:
|
||||
urilast = r"""[_~/a-zA-Z0-9]"""
|
||||
emailc = r"""[-_!~*'{|}/#?^`&=+$%a-zA-Z0-9]"""
|
||||
email_pattern = r"""
|
||||
%(emailc)s+(?:\.%(emailc)s+)* # name
|
||||
@ # at
|
||||
%(emailc)s+(?:\.%(emailc)s*)* # host
|
||||
%(urilast)s # final URI char
|
||||
"""
|
||||
parts = ('initial_inline', start_string_prefix, '',
|
||||
[('start', '', non_whitespace_after, # simple start-strings
|
||||
[r'\*\*', # strong
|
||||
|
@ -581,6 +589,18 @@ class Inliner:
|
|||
)
|
||||
%(end_string_suffix)s
|
||||
""" % locals(), re.VERBOSE | re.UNICODE),
|
||||
embedded_uri=re.compile(
|
||||
r"""
|
||||
(
|
||||
[ \n]+ # spaces or beginning of line
|
||||
< # open bracket
|
||||
%(non_whitespace_after)s
|
||||
([^<>\0]+) # anything but angle brackets & nulls
|
||||
%(non_whitespace_before)s
|
||||
> # close bracket w/o whitespace before
|
||||
)
|
||||
$ # end of string
|
||||
""" % locals(), re.VERBOSE),
|
||||
literal=re.compile(non_whitespace_before + '(``)'
|
||||
+ end_string_suffix),
|
||||
target=re.compile(non_whitespace_escape_before
|
||||
|
@ -588,8 +608,9 @@ class Inliner:
|
|||
substitution_ref=re.compile(non_whitespace_escape_before
|
||||
+ r'(\|_{0,2})'
|
||||
+ end_string_suffix),
|
||||
email=re.compile(email_pattern % locals() + '$', re.VERBOSE),
|
||||
uri=re.compile(
|
||||
r"""
|
||||
(r"""
|
||||
%(start_string_prefix)s
|
||||
(?P<whole>
|
||||
(?P<absolute> # absolute URI
|
||||
|
@ -615,14 +636,11 @@ class Inliner:
|
|||
)
|
||||
| # *OR*
|
||||
(?P<email> # email address
|
||||
%(emailc)s+(\.%(emailc)s+)* # name
|
||||
@ # at
|
||||
%(emailc)s+(\.%(emailc)s*)* # host
|
||||
%(urilast)s # final URI char
|
||||
""" + email_pattern + r"""
|
||||
)
|
||||
)
|
||||
%(end_string_suffix)s
|
||||
""" % locals(), re.VERBOSE),
|
||||
""") % locals(), re.VERBOSE),
|
||||
pep=re.compile(
|
||||
r"""
|
||||
%(start_string_prefix)s
|
||||
|
@ -736,7 +754,7 @@ class Inliner:
|
|||
prb = self.problematic(text, text, msg)
|
||||
return string[:rolestart], [prb], string[textend:], [msg]
|
||||
return self.phrase_ref(string[:matchstart], string[textend:],
|
||||
rawsource, text)
|
||||
rawsource, escaped, text)
|
||||
else:
|
||||
return self.interpreted(string[:rolestart], string[textend:],
|
||||
rawsource, text, role, position)
|
||||
|
@ -747,16 +765,46 @@ class Inliner:
|
|||
prb = self.problematic(text, text, msg)
|
||||
return string[:matchstart], [prb], string[matchend:], [msg]
|
||||
|
||||
def phrase_ref(self, before, after, rawsource, text):
|
||||
def phrase_ref(self, before, after, rawsource, escaped, text):
|
||||
match = self.patterns.embedded_uri.search(escaped)
|
||||
if match:
|
||||
text = unescape(escaped[:match.start(0)])
|
||||
uri_text = match.group(2)
|
||||
uri = ''.join(uri_text.split())
|
||||
uri = self.adjust_uri(uri)
|
||||
if uri:
|
||||
target = nodes.target(match.group(1), refuri=uri)
|
||||
else:
|
||||
raise ApplicationError('problem with URI: %r' % uri_text)
|
||||
else:
|
||||
target = None
|
||||
refname = normalize_name(text)
|
||||
reference = nodes.reference(rawsource, text)
|
||||
node_list = [reference]
|
||||
if rawsource[-2:] == '__':
|
||||
if target:
|
||||
reference['refuri'] = uri
|
||||
else:
|
||||
reference['anonymous'] = 1
|
||||
self.document.note_anonymous_ref(reference)
|
||||
else:
|
||||
if target:
|
||||
reference['refuri'] = uri
|
||||
target['name'] = refname
|
||||
self.document.note_external_target(target)
|
||||
self.document.note_explicit_target(target, self.parent)
|
||||
node_list.append(target)
|
||||
else:
|
||||
reference['refname'] = refname
|
||||
self.document.note_refname(reference)
|
||||
return before, [reference], after, []
|
||||
return before, node_list, after, []
|
||||
|
||||
def adjust_uri(self, uri):
|
||||
match = self.patterns.email.match(uri)
|
||||
if match:
|
||||
return 'mailto:' + uri
|
||||
else:
|
||||
return uri
|
||||
|
||||
def interpreted(self, before, after, rawsource, text, role, position):
|
||||
if role:
|
||||
|
@ -1639,8 +1687,12 @@ class Body(RSTState):
|
|||
name = normalize_name(unescape(targetname))
|
||||
target['name'] = name
|
||||
if refuri:
|
||||
target['refuri'] = refuri
|
||||
uri = self.inliner.adjust_uri(refuri)
|
||||
if uri:
|
||||
target['refuri'] = uri
|
||||
self.document.note_external_target(target)
|
||||
else:
|
||||
raise ApplicationError('problem with URI: %r' % refuri)
|
||||
else:
|
||||
self.document.note_internal_target(target)
|
||||
self.document.note_explicit_target(target, self.parent)
|
||||
|
|
|
@ -170,6 +170,7 @@ class TargetNotes(Transform):
|
|||
if not refsect:
|
||||
refsect = nodes.section()
|
||||
refsect += nodes.title('', 'References')
|
||||
doc.set_id(refsect)
|
||||
if copyright:
|
||||
# Put the new "References" section before "Copyright":
|
||||
doc.insert(copyright, refsect)
|
||||
|
|
|
@ -134,12 +134,13 @@ class HTMLTranslator(nodes.NodeVisitor):
|
|||
option) disables list whitespace optimization.
|
||||
"""
|
||||
|
||||
xml_declaration = '<?xml version="1.0" encoding="%s"?>\n'
|
||||
xml_declaration = '<?xml version="1.0" encoding="%s" ?>\n'
|
||||
doctype = ('<!DOCTYPE html'
|
||||
' PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
|
||||
' "http://www.w3.org/TR/xhtml1/DTD/'
|
||||
'xhtml1-transitional.dtd">\n')
|
||||
html_head = '<html lang="%s">\n<head>\n'
|
||||
html_head = ('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="%s" '
|
||||
'lang="%s">\n<head>\n')
|
||||
content_type = ('<meta http-equiv="Content-Type" content="text/html; '
|
||||
'charset=%s" />\n')
|
||||
generator = ('<meta name="generator" content="Docutils %s: '
|
||||
|
@ -153,11 +154,12 @@ class HTMLTranslator(nodes.NodeVisitor):
|
|||
def __init__(self, document):
|
||||
nodes.NodeVisitor.__init__(self, document)
|
||||
self.settings = settings = document.settings
|
||||
self.language = languages.get_language(settings.language_code)
|
||||
lcode = settings.language_code
|
||||
self.language = languages.get_language(lcode)
|
||||
self.head_prefix = [
|
||||
self.xml_declaration % settings.output_encoding,
|
||||
self.doctype,
|
||||
self.html_head % settings.language_code,
|
||||
self.html_head % (lcode, lcode),
|
||||
self.content_type % settings.output_encoding,
|
||||
self.generator % docutils.__version__]
|
||||
self.head = []
|
||||
|
@ -167,7 +169,10 @@ class HTMLTranslator(nodes.NodeVisitor):
|
|||
self.stylesheet = [self.embedded_stylesheet % stylesheet_text]
|
||||
else:
|
||||
stylesheet = self.get_stylesheet_reference()
|
||||
if stylesheet:
|
||||
self.stylesheet = [self.stylesheet_link % stylesheet]
|
||||
else:
|
||||
self.stylesheet = []
|
||||
self.body_prefix = ['</head>\n<body>\n']
|
||||
self.body_pre_docinfo = []
|
||||
self.docinfo = []
|
||||
|
|
Loading…
Reference in New Issue