Skip to content

Commit

Permalink
fixed #3 use of secure URLs when request is secure
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Feb 13, 2014
1 parent 8ea870c commit 50ba142
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Finally, the template needs the support Javascript code added, by calling `paged
</body>
</html>

The Javascript classes are imported from a CDN, there are no static files that need to be served by the application.
The Javascript classes are imported from a CDN, there are no static files that need to be served by the application. If the request is secure then the Javascript files are imported from an https:// URL to match.

To help adding specific CSS styling the `<textarea>` element has class `flask-pagedown-input` and the preview `<div>` has class `flask-pagedown-preview`.

Expand Down
12 changes: 8 additions & 4 deletions flask_pagedown/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from jinja2 import Markup
from flask import current_app
from flask import current_app, request

class _pagedown(object):
def include_pagedown(self):
if request.is_secure:
protocol = 'https'
else:
protocol = 'http'
return Markup('''
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Converter.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Sanitizer.min.js"></script>
''')
<script type="text/javascript" src="{0}://cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Converter.min.js"></script>
<script type="text/javascript" src="{0}://cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Sanitizer.min.js"></script>
'''.format(protocol))

def html_head(self):
return self.include_pagedown()
Expand Down

0 comments on commit 50ba142

Please sign in to comment.