Skip to content

Commit

Permalink
Issue #64 + slight improvement.
Browse files Browse the repository at this point in the history
  • Loading branch information
xenatisch committed May 4, 2017
1 parent e74785c commit c6689c9
Show file tree
Hide file tree
Showing 46 changed files with 380 additions and 348 deletions.
78 changes: 77 additions & 1 deletion docs-src/customization.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,80 @@
Customization
=============

----

General (ex. settings)
**********************

Templates
---------

The default widget is as seen `here
<https://github.com/neutronX/django-markdownx/blob/master/markdownx/templates/markdownx/widget.html>`_.

If you would like to customise this; for instance, using `Bootstrap <https://getbootstrap.com>`_ to implement
side-by-side panes (as seen in :doc:`preview animation<index>`), you should override the default template by creating
your own template and saving it under ``markdownx/widget2.html`` (Django 1.11+) or ``markdownx/widget.html`` (Django
1.10 and below) in your project's :guilabel:`TEMPLATE_DIRS`.

Here is an example of the contents:

.. code-block:: html

<div class="markdownx row">
<div class="col-md-6">
{{ markdownx_editor }}
</div>
<div class="col-md-6">
<div class="markdownx-preview"></div>
</div>
</div>


Fields
------

We have ensured that **MarkdownX** is fully extensible and provides a high degree of flexibility in development.

There are times that you may wish to Markdownify a different type of field, or utilize your own customized widget. To
accommodate this, we have provided the tools to apply **MarkdownX** infrastructure to other fields through *Widgets*.

For instance, to apply **MarkdownX** to ``TextField`` instances in your Django Admins, you can override the default
widget in the Admins module in :guilabel:`admin.py` of your Django App as follows:

.. code-block:: python
:linenos:
from django.db import models
from django.contrib import admin
from markdownx.widgets import AdminMarkdownxWidget
from .models import MyModel
class MyModelAdmin(admin.ModelAdmin):
formfield_overrides = {
models.TextField: {'widget': AdminMarkdownxWidget},
}
admin.site.register(MyModel, MyModelAdmin)
Image tags
----------

Markdown uses ``![]()`` tag by default to insert uploaded image file. This generates a simple (X)HTML ``<image>`` tag.
If you wish to have more control and use your own HTML tags, you may create a custom ``form_valid()`` function in
``ImageUploadView`` class, as highlighted `here
<https://github.com/neutronX/django-markdownx/blob/master/markdownx/views.py#L55-L82>`_.

----

Settings
********

You may place any of the variables outlined in this page in your :guilabel:`settings.py`, alter their values and
override default behaviours.

Expand All @@ -9,6 +83,7 @@ override default behaviours.
customisations, or to be rather more accurate, **event controls** are enabled in the frontend through JavaScript
events. To learn more about these events, see our :doc:`JavaScript documentations on events<js/events>`.


Quick Reference
---------------

Expand Down Expand Up @@ -55,6 +130,7 @@ Looking for a specific feature? see the sidebar for the table of contents.

Markdownify
...........

Default function that compiles markdown using defined extensions. Using custom function can allow you to
pre-process or post-process markdown text. See below for more info.

Expand Down Expand Up @@ -244,7 +320,7 @@ by setting the value to ``False`` if so is desired.
.. Important::
MarkdownX does *not* disable CSRF protection by default, and requires the token for all AJAX request.
**MarkdownX** does *not* disable CSRF protection by default, and requires the token for all AJAX request.


Editor
Expand Down
65 changes: 0 additions & 65 deletions docs-src/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,71 +75,6 @@ your :guilabel:`app/admin.py` as follows:
admin.site.register(MyModel, MarkdownxModelAdmin)
Advanced
--------

Template customization
......................

The default widget is as seen `here
<https://github.com/neutronX/django-markdownx/blob/master/markdownx/templates/markdownx/widget.html>`_.

If you would like to customise this; for instance, using `Bootstrap <https://getbootstrap.com>`_ to implement
side-by-side panes (as seen in :doc:`preview animation<index>`), you should override the default template by creating
your own template and saving it under ``markdownx/widget.html`` (Django 1.11+) or ``markdownx/widget2.html`` (Django
1.10 and below) in your project's :guilabel:`TEMPLATE_DIRS`.

Here is an example of the contents:

.. code-block:: html

<div class="markdownx row">
<div class="col-md-6">
{{ markdownx_editor }}
</div>
<div class="col-md-6">
<div class="markdownx-preview"></div>
</div>
</div>


Field customization
...................

We have ensured that **MarkdownX** is fully extensible and provides a high degree of flexibility in development.

There are times that you may wish to Markdownify a different type of field, or utilize your own customized widget. To
accommodate this, we have provided the tools to apply **MarkdownX** infrastructure to other fields through *Widgets*.

For instance, to apply **MarkdownX** to ``TextField`` instances in your Django Admins, you can override the default
widget in the Admins module in :guilabel:`admin.py` of your Django App as follows:

.. code-block:: python
:linenos:
from django.db import models
from django.contrib import admin
from markdownx.widgets import AdminMarkdownxWidget
from .models import MyModel
class MyModelAdmin(admin.ModelAdmin):
formfield_overrides = {
models.TextField: {'widget': AdminMarkdownxWidget},
}
admin.site.register(MyModel, MyModelAdmin)
Custom image tags
.................
Markdown uses ``![]()`` tag by default to insert uploaded image file. This generates a simple (X)HTML ``<image>`` tag.
If you wish to have more control and use your own HTML tags, you may create a custom ``form_valid()`` function in
``ImageUploadView`` class, as highlighted `here
<https://github.com/neutronX/django-markdownx/blob/master/markdownx/views.py#L55-L82>`_.
.. _TextField: https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.TextField
12 changes: 11 additions & 1 deletion docs-src/markdownx/docs/urls.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@

URLs
----

.. automodule:: markdownx.urls
:members:



.. tip::
All **MarkdownX** URLs patterns have unique names that start with ``markdownx_`` and are followed by a specific
name; for instance, the `upload` link has the name :guilabel:`markdownx_upload`. It is still possible to use
the ``namespace`` attribute (see `Django docs`_ to find out more) when including the patterns in your project.


.. _Django docs: https://docs.djangoproject.com/en/dev/topics/http/urls/#url-namespaces
6 changes: 3 additions & 3 deletions docs/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Overview: module code &mdash; Django Markdownx 2.0.16 documentation</title>
<title>Overview: module code &mdash; Django Markdownx 2.0.19 documentation</title>



Expand All @@ -35,7 +35,7 @@
<link rel="index" title="Index"
href="../genindex.html"/>
<link rel="search" title="Search" href="../search.html"/>
<link rel="top" title="Django Markdownx 2.0.16 documentation" href="../index.html"/>
<link rel="top" title="Django Markdownx 2.0.19 documentation" href="../index.html"/>


<script src="../_static/js/modernizr.min.js"></script>
Expand Down Expand Up @@ -202,7 +202,7 @@ <h1>All modules for which code is available</h1>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../',
VERSION:'2.0.16',
VERSION:'2.0.19',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
Expand Down
6 changes: 3 additions & 3 deletions docs/_modules/markdownx/exceptions.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>markdownx.exceptions &mdash; Django Markdownx 2.0.16 documentation</title>
<title>markdownx.exceptions &mdash; Django Markdownx 2.0.19 documentation</title>



Expand All @@ -35,7 +35,7 @@
<link rel="index" title="Index"
href="../../genindex.html"/>
<link rel="search" title="Search" href="../../search.html"/>
<link rel="top" title="Django Markdownx 2.0.16 documentation" href="../../index.html"/>
<link rel="top" title="Django Markdownx 2.0.19 documentation" href="../../index.html"/>
<link rel="up" title="Module code" href="../index.html"/>


Expand Down Expand Up @@ -257,7 +257,7 @@ <h1>Source code for markdownx.exceptions</h1><div class="highlight"><pre>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../../',
VERSION:'2.0.16',
VERSION:'2.0.19',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
Expand Down
22 changes: 11 additions & 11 deletions docs/_modules/markdownx/forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>markdownx.forms &mdash; Django Markdownx 2.0.16 documentation</title>
<title>markdownx.forms &mdash; Django Markdownx 2.0.19 documentation</title>



Expand All @@ -35,7 +35,7 @@
<link rel="index" title="Index"
href="../../genindex.html"/>
<link rel="search" title="Search" href="../../search.html"/>
<link rel="top" title="Django Markdownx 2.0.16 documentation" href="../../index.html"/>
<link rel="top" title="Django Markdownx 2.0.19 documentation" href="../../index.html"/>
<link rel="up" title="Module code" href="../index.html"/>


Expand Down Expand Up @@ -239,6 +239,14 @@ <h1>Source code for markdownx.forms</h1><div class="highlight"><pre>
<span class="n">charset</span><span class="o">=</span><span class="kc">None</span>
<span class="p">)</span>

<span class="k">if</span> <span class="p">(</span><span class="n">content_type</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_SVG_TYPE</span>
<span class="ow">and</span> <span class="n">MARKDOWNX_SVG_JAVASCRIPT_PROTECTION</span>
<span class="ow">and</span> <span class="n">xml_has_javascript</span><span class="p">(</span><span class="n">uploaded_image</span><span class="o">.</span><span class="n">read</span><span class="p">())):</span>

<span class="k">raise</span> <span class="n">MarkdownxImageUploadError</span><span class="p">(</span>
<span class="s1">&#39;Failed security monitoring: SVG file contains JavaScript.&#39;</span>
<span class="p">)</span>

<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_save</span><span class="p">(</span><span class="n">uploaded_image</span><span class="p">,</span> <span class="n">file_name</span><span class="p">,</span> <span class="n">commit</span><span class="p">)</span></div>

<span class="k">def</span> <span class="nf">_save</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">image</span><span class="p">,</span> <span class="n">file_name</span><span class="p">,</span> <span class="n">commit</span><span class="p">):</span>
Expand Down Expand Up @@ -344,14 +352,6 @@ <h1>Source code for markdownx.forms</h1><div class="highlight"><pre>
<span class="n">expected</span><span class="o">=</span><span class="n">MARKDOWNX_UPLOAD_MAX_SIZE</span>
<span class="p">)</span>

<span class="k">elif</span> <span class="p">(</span><span class="n">content_type</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_SVG_TYPE</span>
<span class="ow">and</span> <span class="n">MARKDOWNX_SVG_JAVASCRIPT_PROTECTION</span>
<span class="ow">and</span> <span class="n">xml_has_javascript</span><span class="p">(</span><span class="n">upload</span><span class="o">.</span><span class="n">read</span><span class="p">())):</span>

<span class="k">raise</span> <span class="n">MarkdownxImageUploadError</span><span class="p">(</span>
<span class="s1">&#39;Failed security monitoring: SVG file contains JavaScript.&#39;</span>
<span class="p">)</span>

<span class="k">return</span> <span class="n">upload</span></div></div>
</pre></div>

Expand Down Expand Up @@ -389,7 +389,7 @@ <h1>Source code for markdownx.forms</h1><div class="highlight"><pre>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../../',
VERSION:'2.0.16',
VERSION:'2.0.19',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
Expand Down
Loading

1 comment on commit c6689c9

@xenatisch
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #63 (mistakenly noted as #64 in the commit message).

Please sign in to comment.