Comments (6)
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.
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.
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.
Great, thanks for your time.
from markdown.
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.
@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)
- API docs are not being properly indexed for search HOT 18
- Strange and inconsistent parsing of lists with headers and multiple lines HOT 6
- The title from `toc_tokens` ignores the `smarty` extension HOT 3
- BlockProcessor output wrapped in p tag HOT 9
- Trying to migrate from `markdown2`, lists without blank lines not working HOT 3
- "Unterminated character set" exception when using extra extension HOT 6
- <table> improperly wrapped by <p> when inside a list HOT 1
- Add Support for Tab Customization in Code Blocks HOT 3
- List not rendering correctly when preceded by word HOT 1
- add a buildin Mermaid extention HOT 1
- No table support? HOT 8
- GFM alerts HOT 2
- TOC extension: ignore headers above [TOC] marker HOT 2
- Fenced code blocks with newlines not parsed into html <code> blocks HOT 2
- convert \u2028 to <br>? HOT 2
- `abbr` extension breaks title attribute added using `attr_list` HOT 1
- Separate extensions from core
- no anchors are created HOT 8
- A line ending that is preceded by a backslash is not parsed as a hard line break HOT 3
- Abbreviation processing order alternative HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markdown.