GithubHelp home page GithubHelp logo

Comments (6)

waylan avatar waylan commented on May 25, 2024

I can't seem to reproduce this. Are you sure you are using the latest code in the repo?

In [1]: import markdown

In [2]: markdown.markdown('[a b c](/a_b_c)')
Out[2]: u'<p><a href="/a_b_c">a b c</a></p>'

In [3]: markdown.version_info
Out[3]: (2, 1, 0, 'Dev')

I suppose it is possible that you are using some extension that is messing with the order of the inline patterns. The text you are getting is a placeholder, which makes me think the patterns are getting run in the wrong order or something. In any event, that would be a bug in your extension, not markdown.

from markdown.

Wilfred avatar Wilfred commented on May 25, 2024

Sorry, it seems we're using GitHub style markdown where we try to stop inter-word underscores becoming italics. Here's the actual issue we're seeing:

>>> import markdown
>>> markdown.version_info
(2, 0, 3, 'Final')
>>> markdown.markdown('[a b c](/a\_b\_c)')
u'<p><a href="/a\x02klzzwxh:0000\x03b\x02klzzwxh:0001\x03c">a b c</a></p>'

I think this example is legal markdown, but I'm not sure. Other markdown packages we've used produce <p><a href="/a_b_c">a b c</a></p>.

from markdown.

waylan avatar waylan commented on May 25, 2024

Ahh, see you're using markdown version 2.0.3. But the current code in the repo is not exhibiting this behavior (we already fix it) so there is nothing to fix. If you want the fixed code use the current source here on github or wait for the next release.

from markdown.

Wilfred avatar Wilfred commented on May 25, 2024

Great, thanks for your time.

from markdown.

agusmakmun avatar agusmakmun commented on May 25, 2024

Hello there, i found same problem here...

>>> import markdown
>>> markdown.version
'2.6.7'
>>>
>>> MARKDOWNX_MARKDOWN_EXTENSIONS = [
...     'markdown.extensions.extra',
...     'markdown.extensions.nl2br',
...     'markdown.extensions.smarty',
...     'markdown.extensions.fenced_code',
... 
...     # Custom markdown extensions.
...     'app_forum.utils.extensions.urlize',
...     'app_forum.utils.extensions.mention',
...     'app_forum.utils.extensions.emoji',
... ]
>>> md = markdown.Markdown(extensions=MARKDOWNX_MARKDOWN_EXTENSIONS)
>>> md.convert('![](/media/markdownx/affbbda4-054e-4fd3-b263-eb4982289d01.jpg)@[falcon] ')
'<p>\x02klzzwxh:0000\x03\x02klzzwxh:0001\x03 </p>'
>>>
>>> # but if has `space` between `)` and `@` it work well.
>>> md.convert('![](/media/markdownx/affbbda4-054e-4fd3-b263-eb4982289d01.jpg) @[falcon] ')
'<p><img alt="" src="/media/markdownx/affbbda4-054e-4fd3-b263-eb4982289d01.jpg" /> <a class="direct-mention-link" href="//mysite.com/profile/falcon/">@falcon</a> </p>'
>>> 

My Extention at app_forum.utils.extensions.mention

import markdown
from django.contrib.auth.models import User

BASE_LINK = '//mysite.com/profile/'
MENTION_RE = r'\@\[(?P<username>\S+)\]'
# MENTION_RE = r'(?<!\!)\@\[([^\]]+)\]' -> m.group(2)


class MentionPattern(markdown.inlinepatterns.Pattern):

    def __init__(self, pattern, markdown_instance):
        markdown.inlinepatterns.Pattern.__init__(self, pattern)
        self.markdown_instance = markdown_instance

    def handleMatch(self, m):
        username = m.group('username')

        """Makesure `username` is registered."""
        if username in [u.username for u in User.objects.all() if u.is_active]:
            url = '{0}{1}/'.format(BASE_LINK, username)
            el = markdown.util.etree.Element('a')
            el.set('href', url)
            el.set('class', 'direct-mention-link')
            el.text = markdown.util.AtomicString('@' + username)
            return el


class MentionExtension(markdown.Extension):

    def extendMarkdown(self, md, md_globals):
        """ Setup `mention_link` with MentionPattern """
        md.inlinePatterns['mention_link'] = MentionPattern(MENTION_RE, md)


def makeExtension(*args, **kwargs):
    return MentionExtension(*args, **kwargs)

from markdown.

waylan avatar waylan commented on May 25, 2024

@agusmakmun it appears that your issue is completely unrelated to this issue. When I run your input without your extension, the output is completely reasonable:

<p><img alt="" src="/media/markdownx/affbbda4-054e-4fd3-b263-eb4982289d01.jpg" />@[falcon] </p>

Which suggests you have a bug in your extension. For an explanation of why you are getting strings like klzzwxh:0002 in your output, see #354.

Note that this forum is for reporting bugs in Python-Markdown, not for asking support questions. If you need any assistance building an extension, please ask for assistance on the mailing list. If you find an actual bug in Python-Markdown (rather than your code), then please open a new issue.

from markdown.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.