From 842a7e50c954545ad536fea06266bd4b2384e92e Mon Sep 17 00:00:00 2001 From: Spencer Stecko Date: Mon, 4 Sep 2017 22:43:36 -0700 Subject: [PATCH 1/9] custom attrs for widget --- pagedown/widgets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pagedown/widgets.py b/pagedown/widgets.py index ad932f6..8afac6c 100644 --- a/pagedown/widgets.py +++ b/pagedown/widgets.py @@ -48,6 +48,7 @@ def render(self, name, value, attrs=None): final_attrs = self.build_attrs(attrs, name=name) else: final_attrs = self.build_attrs(attrs, {'name': name}) + final_attrs = self.build_attrs(final_attrs, self.attrs) if "class" not in final_attrs: final_attrs["class"] = "" From 65da84a71ea35aed62da7dc206827cbf1261a0d8 Mon Sep 17 00:00:00 2001 From: MonarchChakri Date: Mon, 2 Jul 2018 20:51:13 +0530 Subject: [PATCH 2/9] added space as required for good user experience. --- pagedown/templates/pagedown/widgets/default.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pagedown/templates/pagedown/widgets/default.html b/pagedown/templates/pagedown/widgets/default.html index 4c99ad1..6f1bf78 100644 --- a/pagedown/templates/pagedown/widgets/default.html +++ b/pagedown/templates/pagedown/widgets/default.html @@ -1,10 +1,12 @@
- {{ body }} +
{% if show_preview %} -

HTML Preview:

-
+

+ HTML Preview: +

+
{% endif %} -
\ No newline at end of file + From 07f002bf4fb33408a3de9fd591ce957d57d628f4 Mon Sep 17 00:00:00 2001 From: MonarchChakri Date: Mon, 2 Jul 2018 21:02:39 +0530 Subject: [PATCH 3/9] changed the doc string quotes and spacing with reference to pep-8 --- pagedown/forms.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pagedown/forms.py b/pagedown/forms.py index 9f50337..11752a5 100644 --- a/pagedown/forms.py +++ b/pagedown/forms.py @@ -4,14 +4,12 @@ class PagedownField(forms.CharField): - """ A simple CharField that allows us avoid having to write widget code """ widget = PagedownWidget class AdminPagedownField(forms.CharField): - """ A simple CharField that allows us avoid having to write widget code """ widget = AdminPagedownWidget @@ -19,6 +17,7 @@ class AdminPagedownField(forms.CharField): try: from south.modelsinspector import add_introspection_rules + add_introspection_rules([], ["^pagedown\.forms\.PagedownField"]) add_introspection_rules([], ["^pagedown\.forms\.AdminPagedownField"]) except ImportError: From 2d25868c64359c453872a99037d598803b97ef12 Mon Sep 17 00:00:00 2001 From: MonarchChakri Date: Mon, 2 Jul 2018 21:03:32 +0530 Subject: [PATCH 4/9] changed the spacing with reference to pep-8 --- pagedown/settings.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pagedown/settings.py b/pagedown/settings.py index 6fe47f1..7b706d6 100644 --- a/pagedown/settings.py +++ b/pagedown/settings.py @@ -1,9 +1,8 @@ from django.conf import settings - SHOW_PREVIEW = getattr(settings, "PAGEDOWN_SHOW_PREVIEW", True) WIDGET_TEMPLATE = getattr( - settings, "PAGEDOWN_WIDGET_TEMPLATE", "pagedown/widgets/default.html") + settings, "PAGEDOWN_WIDGET_TEMPLATE", "pagedown/widgets/default.html") WIDGET_CSS = getattr( - settings, "PAGEDOWN_WIDGET_CSS", ("pagedown/demo/browser/demo.css", )) + settings, "PAGEDOWN_WIDGET_CSS", ("pagedown/demo/browser/demo.css",)) EXTENSIONS = getattr(settings, "PAGEDOWN_EXTENSIONS", []) From 5b94633556ae0ef5e9af4a21c6606c2c73afe914 Mon Sep 17 00:00:00 2001 From: MonarchChakri Date: Mon, 2 Jul 2018 21:04:17 +0530 Subject: [PATCH 5/9] changed the spacing with reference to pep-8 --- pagedown/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pagedown/utils.py b/pagedown/utils.py index 357bf21..86d2877 100644 --- a/pagedown/utils.py +++ b/pagedown/utils.py @@ -3,7 +3,6 @@ def compatible_staticpath(path): - """ Try to return a path to static the static files compatible all the way back to Django 1.2. If anyone has a cleaner or better From 0582afec124542543885b739f2b1173cd0c2805f Mon Sep 17 00:00:00 2001 From: MonarchChakri Date: Mon, 2 Jul 2018 21:08:40 +0530 Subject: [PATCH 6/9] Render function added renderer, custom attrs. Added param renderer in render function to support django version 2, and also added support to give custom attributes to widget. --- pagedown/widgets.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pagedown/widgets.py b/pagedown/widgets.py index 26db1a8..996c7fa 100644 --- a/pagedown/widgets.py +++ b/pagedown/widgets.py @@ -12,7 +12,6 @@ from pagedown import settings as pagedown_settings from pagedown.utils import compatible_staticpath - # Python 3 compatibility # https://docs.djangoproject.com/en/1.5/topics/python3/#string-handling try: @@ -45,15 +44,18 @@ def _media(self): compatible_staticpath("pagedown-extra/Markdown.Extra.js"), compatible_staticpath("pagedown_init.js"), )) + media = property(_media) - def render(self, name, value, attrs=None): + def render(self, name, value, attrs=None, renderer=None): + # def render(self, name, value, attrs=None): if value is None: value = "" if VERSION < (1, 11): final_attrs = self.build_attrs(attrs, name=name) else: final_attrs = self.build_attrs(attrs, {'name': name}) + final_attrs = self.build_attrs(final_attrs, self.attrs) if "class" not in final_attrs: final_attrs["class"] = "" @@ -81,4 +83,5 @@ def _media(self): js=( compatible_staticpath("admin/js/pagedown.js"), )) + media = property(_media) From e191bff1554f14aca4c22bb6131ca756b9e5e9ea Mon Sep 17 00:00:00 2001 From: Timmy O'Mahony Date: Sat, 18 Aug 2018 00:21:56 +0100 Subject: [PATCH 7/9] Made widget code clearer --- pagedown/widgets.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pagedown/widgets.py b/pagedown/widgets.py index 996c7fa..5564de9 100644 --- a/pagedown/widgets.py +++ b/pagedown/widgets.py @@ -48,18 +48,24 @@ def _media(self): media = property(_media) def render(self, name, value, attrs=None, renderer=None): - # def render(self, name, value, attrs=None): if value is None: value = "" + + extra_attrs = { + 'name': name + }.update(self.attrs) + + # Signature for build_attrs changed in 1.11 + # https://code.djangoproject.com/ticket/28095 if VERSION < (1, 11): - final_attrs = self.build_attrs(attrs, name=name) + final_attrs = self.build_attrs(attrs, **extra_attrs) else: - final_attrs = self.build_attrs(attrs, {'name': name}) - final_attrs = self.build_attrs(final_attrs, self.attrs) - + final_attrs = self.build_attrs(attrs, extra_attrs=extra_attrs) + if "class" not in final_attrs: final_attrs["class"] = "" final_attrs["class"] += " wmd-input" + template = loader.get_template(self.template) # Compatibility fix: From 974ade7403ae10660660fc78993851d96da62edd Mon Sep 17 00:00:00 2001 From: Timmy O'Mahony Date: Sat, 18 Aug 2018 00:34:17 +0100 Subject: [PATCH 8/9] Moved dict update --- pagedown/widgets.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pagedown/widgets.py b/pagedown/widgets.py index 5564de9..21459bb 100644 --- a/pagedown/widgets.py +++ b/pagedown/widgets.py @@ -53,7 +53,9 @@ def render(self, name, value, attrs=None, renderer=None): extra_attrs = { 'name': name - }.update(self.attrs) + } + + extra_attrs.update(self.attrs) # Signature for build_attrs changed in 1.11 # https://code.djangoproject.com/ticket/28095 From 13280d5ac325ba2135b8fd94f75e04306b519a70 Mon Sep 17 00:00:00 2001 From: Timmy O'Mahony Date: Sat, 18 Aug 2018 00:45:44 +0100 Subject: [PATCH 9/9] Updated the CSS --- pagedown/static/admin/css/pagedown.css | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pagedown/static/admin/css/pagedown.css b/pagedown/static/admin/css/pagedown.css index deb3afb..588dabb 100644 --- a/pagedown/static/admin/css/pagedown.css +++ b/pagedown/static/admin/css/pagedown.css @@ -36,14 +36,15 @@ padding: 12px 14px; margin: 0; background: #f8f8f8; - border: 1px solid #eee; - border-radius: 4px; } .wmd-preview * { font-family: "Roboto","Lucida Grande","DejaVu Sans","Bitstream Vera Sans",Verdana,Arial,sans-serif !important; } +.wmd-preview *:last-child { + margin-bottom: 0; +} .wmd-preview a { color: #447e9b; @@ -95,7 +96,7 @@ .wmd-preview h6 { margin:0 0 12px 0; padding: 0; - color: #666; + color: #333; font-weight: bold; background: none; } @@ -175,12 +176,11 @@ word-wrap: break-word; margin: 15px 0; padding: 10px; + color: #333; margin: 0 0 15px 0; padding-left: 1em; - border-left: 0.5em #ddd solid; background-color: #eee; - border-radius: 0 4px 4px 0; } .wmd-preview pre code { background-color: transparent;