Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Nov 11, 2013
1 parent b50acac commit be1a3e4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ The extension needs to be initialized in the usual way before it can be used:
app = Flask(__name__)
pagedown = PageDown(app)

Finally, the template needs the support Javascript code added, by calling `pagedown.html_head()` from inside the `<head>` element of the page:
Finally, the template needs the support Javascript code added, by calling `pagedown.include_pagedown()` somewhere in the page:

<html>
<head>
{{ pagedown.html_head() }}
{{ pagedown.include_pagedown() }}
</head>
<body>
<form method="POST">
Expand Down
2 changes: 1 addition & 1 deletion example/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
{{ pagedown.html_head() }}
{{ pagedown.include_pagedown() }}
<style>
.flask-pagedown-input {
}
Expand Down
5 changes: 4 additions & 1 deletion flask_pagedown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
from flask import current_app

class _pagedown(object):
def html_head(self):
def include_pagedown(self):
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>
''')

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

class PageDown(object):
def __init__(self, app = None):
if app is not None:
Expand Down
10 changes: 8 additions & 2 deletions flask_pagedown/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
pagedown_post_html = '''
</div>
<script type="text/javascript">
(function() {
f = function() {
if (typeof flask_pagedown_converter === "undefined")
flask_pagedown_converter = Markdown.getSanitizingConverter().makeHtml;
var textarea = document.getElementById("flask-pagedown-%s");
Expand All @@ -16,7 +16,13 @@
textarea.parentNode.insertBefore(preview, textarea.nextSibling);
textarea.onkeyup = function() { preview.innerHTML = flask_pagedown_converter(textarea.value); }
textarea.onkeyup.call(textarea);
})();
}
if (window.addEventListener)
window.addEventListener("load", f, false);
else if (window.attachEvent)
window.attachEvent("onload", f);
else
f();
</script>
'''

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='Flask-PageDown',
version='0.1.1',
version='0.1.2',
url='http://github.com/miguelgrinberg/flask-pagedown/',
license='MIT',
author='Miguel Grinberg',
Expand Down

0 comments on commit be1a3e4

Please sign in to comment.