dagrevis / mdx_linkify Goto Github PK
View Code? Open in Web Editor NEWLink recognition for Python Markdown
License: MIT License
Link recognition for Python Markdown
License: MIT License
When using markdown
I sometimes specify the output_format
as "xhtml". But, if I use LinkifyExtension
then this is ignored and any tags that would be XHTML-style are HTML5 style.
For example, the \n\n----\n\n
in text
here should come out as <hr />
, but it doesn't in the second case:
from markdown import markdown
from mdx_linkify.mdx_linkify import LinkifyExtension
text = "Hello\n\n----\n\nBye"
markdown(text=text, extensions=[], output_format="xhtml")
markdown(text=text, extensions=[LinkifyExtension()], output_format="xhtml")
Output:
'<p>Hello</p>\n<hr />\n<p>Bye</p>'
'<p>Hello</p>\n<hr>\n<p>Bye</p>'
I guess this is to do with Bleach?
After update to 2.0 i encountered a strange bug, sometimes, very rarely, linkify fails with following traceback:
...
File "markdown/core.py", line 292, in convert
output = pp.run(output)
File "mdx_linkify/mdx_linkify.py", line 34, in run
return self._linker.linkify(text)
File "bleach/linkifier.py", line 170, in linkify
dom = self.parser.parseFragment(text)
File "bleach/_vendor/html5lib/html5parser.py", line 317, in parseFragment
self._parse(stream, True, *args, **kwargs)
File "bleach/html5lib_shim.py", line 399, in _parse
self.mainLoop()
File "bleach/_vendor/html5lib/html5parser.py", line 243, in mainLoop
new_token = phase.processEndTag(new_token)
File "bleach/_vendor/html5lib/html5parser.py", line 485, in processEndTag
return self.endTagHandler[token["name"]](token)
File "bleach/_vendor/html5lib/html5parser.py", line 1372, in endTagP
node = self.tree.openElements.pop()
And i cannot reproduce it in test case.
But i presume, that's becouse HTMLParser.parseFragment
function is not pure.
Before 2.0 bleach.linkify
created new Linker instance for each call, here we creating single instance and reusing it.
I moved Linker from __init__
to run
in my private project, i'll test it for few days, if it works, i'll create PR with fix.
First of all, many thanks for providing a maintained package!
I've come by an apparently less frequently experienced behaviour that may not be intentional, the partial linkification of Posix paths. (It may not be an issue.) A (real life :) ) example:
from markdown import markdown
markdown("tests/test_markdown.py", extensions=["mdx_linkify"])
gives
'<p>tests/<a href="http://test_markdown.py" rel="nofollow">test_markdown.py</a></p>'
Albeit .py is a valid TLD, I suspect this may not be as intended, at the very least due to the conversion being partial - I guess it should cover the "tests/" thing then as well ... is there a dedicated workaround and/or a setting that I missed?
I personally wouldn't like this linkified without a protocol part, or at least a "www." at the front - I'll look into accomplishing this via the "Ignoring TLDs" example. I am partial to imagining this to be a more common default preference (I can be biased of course! for now it is just a guess).
(I would also suggest/bring up the ability of configuring https versus the now-less-desirable http protocol, maybe even making it the default. Let's spread good security practice?)
I'll try to give it a look over the weekend, but if it's like something quite trivial (so far as priorities allow ... almost never the case :) even if I'm otherwise quite interested), please do feel free to let me know
Thanks in advance!
I get this error when using mdx_linkify 0.5 with Markdown 2.5.1.
Exception Type: TypeError
Exception Value:
'NoneType' object is not iterable
Exception Location: /home/nnyby/src/dmt/ve/local/lib/python2.7/site-packages/markdown/extensions/init.py in setConfigs, line 75
Python Executable: /home/nnyby/src/dmt/ve/bin/python
Python Version: 2.7.8
Server time: Fri, 7 Nov 2014 13:59:44 -0500
Here's how I'm calling mdx_linkify:
{{object.description|markdown:"linkify"}}
Hi, thanks for the work on this package!
Minor issue, but after upgrading the markdown package to version 3.0, I'm seeing deprecation warnings for the md_globals
parameter, as well as the add
call:
Using the add method to register a processor or pattern is deprecated.
'Use the `register` method instead.', DeprecationWarning
/home/circleci/repo/venv/lib/python3.6/site-packages/markdown/core.py:128:
DeprecationWarning: The 'md_globals' parameter of
'mdx_linkify.mdx_linkify.LinkifyExtension.extendMarkdown' is deprecated.
Are there plans to upgrade the markdown dependency any time soon? I think the fix should only need to touch the LinkifyExtension
class:
mdx_linkify/mdx_linkify/mdx_linkify.py
Line 22 in d4db257
Some of the new TLDs are not supported, and bleach doesn't plan to fix it.
Can you add ability to override tlds/url_re to this project? If it's considered good idea, i can make pull-request.
When mdx_linkify sees a URL in a string surrounded by backticks like this:
<img src="http://dontescapethis.com/img.png" />
It linkifies the URL when it should leave it alone.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.