├── .github └── workflows │ └── tests.yml ├── .gitignore ├── CHANGES.md ├── LICENSE ├── MANIFEST.in ├── README.md ├── example ├── app.py ├── requirements.txt └── templates │ └── index.html ├── pyproject.toml ├── src └── flask_pagedown │ ├── __init__.py │ ├── fields.py │ └── widgets.py └── tox.ini /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | branches: 8 | - main 9 | jobs: 10 | lint: 11 | name: lint 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v3 15 | - uses: actions/setup-python@v3 16 | - run: python -m pip install --upgrade pip wheel 17 | - run: pip install tox tox-gh-actions 18 | - run: tox -eflake8 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | bin 14 | var 15 | sdist 16 | develop-eggs 17 | .installed.cfg 18 | lib 19 | lib64 20 | __pycache__ 21 | 22 | # Installer logs 23 | pip-log.txt 24 | 25 | # Unit test / coverage reports 26 | .coverage 27 | .tox 28 | nosetests.xml 29 | 30 | # Translations 31 | *.mo 32 | 33 | # Mr Developer 34 | .mr.developer.cfg 35 | .project 36 | .pydevproject 37 | 38 | venv 39 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | # Flask-PageDown Change Log 2 | 3 | **Release 0.4.0** - 2021-09-08 4 | 5 | - Fix deprecation warnings by using markupsafe.Markup [#27](https://github.com/miguelgrinberg/flask-pagedown/issues/27) ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/b0bf84f7757f975bef075faab24a6bf11ba02829)) (thanks **Nick Bautista**!) 6 | - Document how to use your own PageDown JavaScript source files [#24](https://github.com/miguelgrinberg/flask-pagedown/issues/24) ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/f13f81a72d2dfd0f881306ddc18d5d6642c5744d)) (thanks **olumidesan**!) 7 | - Improved project structure ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/ea12a8551b4e17fc7a8adffb26845abbead82b72)) 8 | - Add a change log ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/a00e7195b1b98008c33cf9c4fafcd5b66026ceb5)) 9 | - Added github actions build ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/4fec2e7f04c4013193a542218d852072b20bf528)) 10 | 11 | **Release 0.3.0** - 2020-05-02 12 | 13 | - Converted strings to markup [#21](https://github.com/miguelgrinberg/flask-pagedown/issues/21) ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/90139d9b45aa1a74adbf4ce221faabf8f9b2ca4f)) (thanks **Petr Deriabin**!) 14 | 15 | **Release 0.2.2** - 2016-09-30 16 | 17 | - Updated Form to FlaskForm ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/fc69896717eea1ebd055c70511a144aee71525f7)) 18 | - Updated requirements for example app ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/5b0f452200cd382aa64c7c5fdadcb7bfcfa29d73)) 19 | 20 | **Release 0.2.1** - 2015-05-11 21 | 22 | - Support custom CSS classes in field render call ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/3ee04376a20a7e430190d016a41695c464970201)) 23 | 24 | **Release 0.2.0** - 2015-05-11 25 | 26 | - Change Flask plugins to new recommended import syntax ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/c70899a0cc3c23d69cb280177e8dc98cd88fc5b7)) 27 | - Render preview separately from input area ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/69a243900a49baca336040cf0ed73094f7d9f66d)) 28 | - pep8 fixes ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/5b04c2de0e6ad697c0399cd40a59f3709fd33944)) 29 | 30 | **Release 0.1.5** - 2014-05-26 31 | 32 | - Fix support for SSL for proxied sites, or otherwise uncertain situations My particular situation is deployed through ElasticBeanstalk, proxying HTTPS to HTTP on the actual endpoints. This makes flask think that it is only running with http, not https ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/04df5c189d6d1760c692d1985faf558058e56eb2)) (thanks **Frank Tackitt**!) 33 | 34 | **Release 0.1.4** - 2014-02-13 35 | 36 | - Use of secure URLs when request is secure [#3](https://github.com/miguelgrinberg/flask-pagedown/issues/3) ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/50ba142994e47d584f5bdf083e0c47f4a9209aa4)) 37 | 38 | **Release 0.1.3** - 2014-01-07 39 | 40 | - Add check if the document is already ready, and if so skip the onload handlers. Fixes live loading of markdown forms ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/868a4c51028e580fd265d428a9d8f2afe3f4aa7c)) (thanks **Frank Tackitt**!) 41 | 42 | **Release 0.1.2** - 2013-11-11 43 | 44 | - Minor updates ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/be1a3e4f25f552178e36d7f383783ff192685832)) 45 | 46 | **Release 0.1.1** - 2013-11-05 47 | 48 | - Fixed setup.py and minor corrections to example app ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/b50acac4b14f1a882f7de0d47702a175dabde9dc)) 49 | 50 | **Release 0.1** - 2013-11-04 51 | 52 | - Initial version ([commit](https://github.com/miguelgrinberg/flask-pagedown/commit/d8a30b86354b264c4427424d444140bc9f568116)) 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Miguel Grinberg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md LICENSE tox.ini 2 | recursive-include docs * 3 | recursive-exclude docs/_build * 4 | recursive-include tests * 5 | exclude **/*.pyc 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Flask-PageDown 2 | ============== 3 | 4 | [![Build status](https://github.com/miguelgrinberg/Flask-PageDown/workflows/build/badge.svg)](https://github.com/miguelgrinberg/Flask-PageDown/actions) 5 | 6 | Implementation of StackOverflow's "PageDown" markdown editor for Flask and Flask-WTF. 7 | 8 | What is PageDown? 9 | ----------------- 10 | 11 | [PageDown](https://code.google.com/p/pagedown/wiki/PageDown) is the JavaScript [Markdown](http://daringfireball.net/projects/markdown/) previewer used on [Stack Overflow](http://stackoverflow.com/) and all the other question and answer sites in the [Stack Exchange network](http://stackexchange.com/). 12 | 13 | Flask-PageDown provides a `PageDownField` class that extends [Flask-WTF](https://flask-wtf.readthedocs.org/en/latest/) with a specialized text area field that renders an HTML preview of the Markdown text on the fly as you type. 14 | 15 | Installation 16 | ------------ 17 | 18 | $ pip install flask-pagedown 19 | 20 | Example 21 | ------- 22 | 23 | An example is worth a thousand words. Below is how to define a simple Flask-WTF form that includes a PageDown field: 24 | 25 | from flask_wtf import Form 26 | from flask_pagedown.fields import PageDownField 27 | from wtforms.fields import SubmitField 28 | 29 | class PageDownFormExample(Form): 30 | pagedown = PageDownField('Enter your markdown') 31 | submit = SubmitField('Submit') 32 | 33 | The `PageDownField` works exactly like a `TextAreaField` (in fact it is a subclass of it). The handling in view functions is identical. For example: 34 | 35 | @app.route('/', methods = ['GET', 'POST']) 36 | def index(): 37 | form = PageDownFormExample() 38 | if form.validate_on_submit(): 39 | text = form.pagedown.data 40 | # do something interesting with the Markdown text 41 | return render_template('index.html', form = form) 42 | 43 | The extension needs to be initialized in the usual way before it can be used: 44 | 45 | from flask_pagedown import PageDown 46 | 47 | app = Flask(__name__) 48 | pagedown = PageDown(app) 49 | 50 | Finally, the template needs the support Javascript code added, by calling `pagedown.include_pagedown()` somewhere in the page: 51 | 52 | 53 | 54 | {{ pagedown.include_pagedown() }} 55 | 56 | 57 |
58 | {{ form.hidden_tag() }} 59 | {{ form.pagedown(rows=10) }} 60 | {{ form.submit }} 61 |
62 | 63 | 64 | 65 | 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. 66 | 67 | If you prefer to use your own JavaScript source files, you can simply include your Converter and Sanitizer files directly in the HTML page instead of calling `pagedown.include_pagedown()`: 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
76 | {{ form.hidden_tag() }} 77 | {{ form.pagedown(rows=10) }} 78 | {{ form.submit }} 79 |
80 | 81 | 82 | 83 | To help adding specific CSS styling the `