Comments (8)
Thanks for the suggestions. It seems most of them could be done by just implementing your own [url] renderer that calls the same linker function you provide, and does whatever domain matching and http/https replacement you want. Not that adding customization hooks into the default renderer is a bad idea.
I think passing the context to a linker function is a good idea, but will need to think about backwards compatibility at this point. Trying to call self.linker(url, context) will break existing linkers that just take the url (and no args/*kwargs).
As for performance, I haven't done any serious benchmarking. Are you experiencing performance problems, or do you have any numbers that indicate your suggestions would be an improvement? For my own usage patterns, shaving a few microseconds off a regular expression match won't matter, but I'd be happy to accept patches that are demonstrably faster and pass the tests.
from bbcode.
Yeah, most of those suggestions are just convenience things, no big deal not to add them :)
As far as context goes, I understand where backwards compatibility would be a concern. I was hoping that since it was relatively undocumented (at least, it's not explicitly described on readthedocs, even though it's commented in the source code) that the interface wasn't stable yet. I just really can't think of any other (thread-safe) way to actually pass in context :( Creating a v2 linker or doing some sort of introspection just seems ugly. Maybe make it a module-level option whether context gets passed in or not, a la the thread safe extensions to yacc?
I'll try benchmarking and see what I come up with. Based on the limited tests I've run your module is already pretty optimized, so it may not make much of a difference.
from bbcode.
I'm wondering if some simple introspection would be that bad. Something like:
if linker.func_code.co_argcount == 2 or linker.func_code.co_flags & 4 != 0: linker(url, context)
elif linker.func_code.co_flags & 8 != 0: linker(url, **context)
else: linker(url)
from bbcode.
Also, is there a reason you can't get around this by doing something like:
def linker(url, context=None):
...
parser = bbcode.Parser(linker=functools.partial(linker, context=whatever))
from bbcode.
I'll answer your second question first: I can't do that, because the context is different each time I parse (I'm using information from the request header in Django).
First question, your call. I'm generally not a fan of reflection, but it's your project :)
from bbcode.
This is merged. I'm working on a release, should have something soon-ish. Thanks for the feedback and pull request!
from bbcode.
FYI, I just pushed out version 1.0.16 to PyPI (and added some docs on this and other things at http://bbcode.readthedocs.org/en/latest/). Sorry for the delay, and thanks for the contribution!
from bbcode.
Awesome, thanks!
On May 5, 2014 7:10 PM, "Dan Watson" [email protected] wrote:
FYI, I just pushed out version 1.0.16 to PyPI (and added some docs on this
and other things at http://bbcode.readthedocs.org/en/latest/). Sorry for
the delay, and thanks for the contribution!—
Reply to this email directly or view it on GitHubhttps://github.com//issues/11#issuecomment-42261032
.
from bbcode.
Related Issues (20)
- Problem with :[ HOT 1
- Quoted option values are cut on square bracket HOT 3
- Parsing links not working correctly HOT 1
- Obscure XSS using url tag HOT 5
- Option to use custom tag opener/closer on formatter level HOT 1
- url should allow specifying target and rel attributes HOT 5
- Problem: lines too looong HOT 4
- Quotation marks in brackes confuses parser HOT 3
- Formatters should only transform their contents and not the contents of their children HOT 8
- Unvalid BBCode Generates HTML HOT 3
- url bbcode replaces \n with <br> tag HOT 1
- "Dash" symbols inside code block HOT 2
- Output is html escaped even if `escape_html=False` HOT 3
- URLs with ampersand seem to break HOT 2
- make tag options dict case-insensitive
- replace_links=False doesn't work on video tag/mp4
- Unclosed "tag" treated as tag HOT 2
- Question about simple_formatter
- Cosmetic replacement within list tag even when replace_cosmetic=False 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 bbcode.