Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress base_url via attribute #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

viernullvier
Copy link
Contributor

Don't prepend base_url to URLs if the tag's attribute 'data-premailer' is set to 'ignore'. Helps with / fixes #140.

Don't prepend base_url to URLs if the tag's attribute 'data-premailer' is set to 'ignore'
@peterbe
Copy link
Owner

peterbe commented Oct 8, 2015

You have me convinced in the Issue that we need to tackle this with an option. However, the PR needs some work. I don't like that the data-premailer="ignore" attribute is still there after premailer has transformed. Also, if someone reads data-premailer="ignore" they might think that the whole tag should be ignored. E.g. if you have

<style>a { color: red }</style>
<a href="tel:+1234" data-premailer="ignore">Call</a>
<a href="/">Home page</a>

...and giving someone sets base_url='http://example.com' to the transform, you might expect this output:

<a href="tel:+1234">Call</a>
<a href="http://example.com/" style="color:red">Home page</a>

which is NOT want we want. We just want the href attribute to be ignored.

Do you have some other ideas about how to annotate and tell premailer to "not touch" an attribute value?

@peterbe
Copy link
Owner

peterbe commented Oct 8, 2015

How about this for a functional idea:

def my_replacer(value, base_url):
      if 'tel:' in value:
         # leave it as is 
         return value
     return urlparse.urljoin(base_url, value)
premailer.transform(html, base_url='http://example.com', base_url_replacer=my_replacer)

@peterbe
Copy link
Owner

peterbe commented Jan 13, 2016

So the problem is that it becomes <a href="http://mybaseurl/tel:+1234">Call</a>, right?
Can't we write a regex that checks the content of the href tag before it does the "insertion" of the base_url?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Phone number URLs are broken
2 participants