Changeset - 588a160dbb9a
[Not reviewed]
stable
0 1 0
Andrew Shadura - 11 years ago 2015-05-05 17:38:10
andrew@shadura.me
rst: in @mention parser, escape spaces so they don't go to HTML

This eliminates extra spaces around @mentions. Every time mention was followed
by a comma, for example:

@username, have you seen it?

it turned into:

@username , have you seen it?

So an extra space was inserted. It was inserted because otherwise rst parser
might not recognise the markup (i.e. @user1,@user2 is replaced by
**user1**,**user2** — that would be interpreted as <b>user1**,**user2</b>).

See http://docutils.sf.net/docs/ref/rst/restructuredtext.html#character-level-inline-markup
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/markup_renderer.py
Show inline comments
 
@@ -148,51 +148,51 @@ class MarkupRenderer(object):
 
        except ImportError:
 
            log.warning('Install markdown to use this function')
 
            return cls.plain(source)
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            if safe:
 
                log.debug('Falling back to render in plain mode')
 
                return cls.plain(source)
 
            else:
 
                raise
 

	
 
    @classmethod
 
    def rst(cls, source, safe=True):
 
        source = safe_unicode(source)
 
        try:
 
            from docutils.core import publish_parts
 
            from docutils.parsers.rst import directives
 
            docutils_settings = dict([(alias, None) for alias in
 
                                cls.RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES])
 

	
 
            docutils_settings.update({'input_encoding': 'unicode',
 
                                      'report_level': 4})
 

	
 
            for k, v in docutils_settings.iteritems():
 
                directives.register_directive(k, v)
 

	
 
            parts = publish_parts(source=source,
 
                                  writer_name="html4css1",
 
                                  settings_overrides=docutils_settings)
 

	
 
            return parts['html_title'] + parts["fragment"]
 
        except ImportError:
 
            log.warning('Install docutils to use this function')
 
            return cls.plain(source)
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            if safe:
 
                log.debug('Falling back to render in plain mode')
 
                return cls.plain(source)
 
            else:
 
                raise
 

	
 
    @classmethod
 
    def rst_with_mentions(cls, source):
 
        mention_pat = re.compile(MENTIONS_REGEX)
 

	
 
        def wrapp(match_obj):
 
            uname = match_obj.groups()[0]
 
            return ' **@%(uname)s** ' % {'uname': uname}
 
            return '\ **@%(uname)s**\ ' % {'uname': uname}
 
        mention_hl = mention_pat.sub(wrapp, source).strip()
 
        return cls.rst(mention_hl)
0 comments (0 inline, 0 general)