Commits

moberley committed 60c820f

Commit first version of django app source.

  • Participants
  • Parent commits b7622a7

Comments (0)

Files changed (7)

File pagedown/__init__.py

Empty file added.

File pagedown/fields.py

+from django.db import models
+from django.forms import fields
+
+from pagedown.widgets import PageDownEditorWidget
+
+
+class MarkdownTextField(models.TextField):
+    def formfield(self, **kwargs):
+        defaults = {'form_class': RichTextFormField}
+        defaults.update(kwargs)
+        return super(MarkdownTextField, self).formfield(**defaults)
+
+
+class MarkdownTextFormField(fields.Field):
+    def __init__(self, template=None, *args, **kwargs):
+        kwargs.update({'widget': PageDownEditorWidget(template)})
+        super(MarkdownTextFormField, self).__init__(*args, **kwargs)

File pagedown/models.py

Empty file added.

File pagedown/static/pagedown/editor.css

+.wmd-button-bar {
+        width: 100%;
+        background-color: silver;
+}
+
+.wmd-input {
+        height: 300px;
+        width: 100%;
+}
+
+.wmd-preview {
+        width: 65%;
+        border: 2px solid #c0e0ff;
+        border-radius: 4px;
+        background-color: white;
+        padding: 5px 8px;
+        margin: 15px 0;
+}
+
+.wmd-preview h1,
+.wmd-preview h2,
+.wmd-preview h3,
+.wmd-preview h4 {
+    border-width: 0;
+    border-radius: 0;
+    background: inherit;
+    padding-left: 0;
+    padding-right: 0;
+}
+
+.wmd-preview em {
+    font-style: italic;
+}
+
+.wmd-preview ul,
+.wmd-preview ol {
+    margin-top: 0.5em;
+    margin-left: 3em;
+}
+
+.wmd-preview ul>li {
+    list-style-type: disc;
+}
+.wmd-preview ol>li {
+    list-style-type: decimal;
+}
+
+.wmd-button-row {
+        position: relative;
+        margin-left: 5px;
+        margin-right: 5px;
+        margin-bottom: 5px;
+        margin-top: 10px;
+        padding: 0px;
+        height: 20px;
+}
+
+.wmd-spacer {
+        width: 1px;
+        height: 20px;
+        margin-left: 14px;
+        position: absolute;
+        background-color: silver;
+        display: inline-block;
+        list-style: none;
+}
+
+.wmd-button {
+    width: 20px;
+    height: 20px;
+    padding-left: 2px;
+    padding-right: 3px;
+    position: absolute;
+    display: inline-block;
+    list-style: none;
+    cursor: pointer;
+}
+
+.wmd-button > span {
+    background-image: url(wmd-buttons.png);
+    background-repeat: no-repeat;
+    background-position: 0px 0px;
+    width: 20px;
+    height: 20px;
+    display: inline-block;
+}
+
+.wmd-spacer1 {
+    left: 50px;
+}
+.wmd-spacer2 {
+    left: 175px;
+}
+.wmd-spacer3 {
+    left: 300px;
+}
+
+.wmd-prompt-background {
+        background-color: Black;
+}
+
+.wmd-prompt-dialog {
+        border: 1px solid #999999;
+        background-color: #F5F5F5;
+}
+
+.wmd-prompt-dialog > div {
+        font-size: 0.8em;
+        font-family: arial, helvetica, sans-serif;
+}
+
+.wmd-prompt-dialog > form > input[type="text"] {
+        border: 1px solid #999999;
+        color: black;
+}
+
+.wmd-prompt-dialog > form > input[type="button"]{
+        border: 1px solid #888888;
+        font-family: trebuchet MS, helvetica, sans-serif;
+        font-size: 0.8em;
+        font-weight: bold;
+}

File pagedown/templates/pagedown/editor.html

+<div class="wmd-panel"><!-- {{ final_attrs|safe }} -->
+  <div id="wmd-button-bar-{{ id }}"></div>
+  <textarea id="wmd-input-{{ id }}" class="wmd-input">{{ value }}</textarea>
+</div>
+<div id="wmd-preview-{{ id }}" class="wmd-panel wmd-preview"></div>
+<script type="text/javascript">
+(function () {
+    var converter_{{ id }} = Markdown.getSanitizingConverter();
+    var editor_{{ id }} = new Markdown.Editor(converter_{{ id }}, "-{{ id }}");
+    editor_{{ id }}.run();
+})();
+</script>

File pagedown/widgets.py

+from django import forms
+from django.utils.safestring import mark_safe
+from django.template.loader import render_to_string
+from django.utils.html import conditional_escape
+from django.utils.encoding import force_unicode
+from django.forms.util import flatatt
+
+
+class PageDownEditorWidget(forms.Textarea):
+    """
+    Widget providing Markdown preview using PageDown JavaScript
+    """
+    class Media:
+        css = {"all": ("pagedown/editor.css",)}
+        js = (
+            "pagedown/Markdown.Converter.js",
+            "pagedown/Markdown.Sanitizer.js",
+            "pagedown/Markdown.Editor.js",
+        )
+
+    def __init__(self, template=None, *args, **kwargs):
+        self.template = template or "pagedown/editor.html"
+
+        super(PageDownEditorWidget, self).__init__(*args, **kwargs)
+
+    def render(self, name, value, attrs={}):
+        if value is None: value = ""
+        final_attrs = self.build_attrs(attrs, name=name)
+        return mark_safe(render_to_string(self.template, {
+            "final_attrs": flatatt(final_attrs),
+            "value": conditional_escape(force_unicode(value)),
+            "id": final_attrs["id"],
+        }))
 
 setup(
     name = "django-pagedown",
-    version = "0.1dev1",
+    version = "0.1",
     description = "Django forms PageDown widget",
     long_description = open("README.rst").read(),
     author = "Bradley D. Peters",