Repository: saleor/saleor

Issue:
Integrate rich text editor
I'd like to start the discussion about choosing a rich text editor that we'll use in the dashboard. From what I recall the one that we've liked the most so far was the [Medium-editor](https://github.com/yabwe/medium-editor). @patrys @dominik-zeglen Do you know any other libraries worth considering?


Discussion:
https://github.com/froala/wysiwyg-editor
https://github.com/GetmeUK/ContentTools

These two look very promising.
@dominik-zeglen We're looking for an editor for the dashboard, we're not currently trying to replace the dashboard with inline tools.
Froala does not have a compatible license.
I suggest giving a try to medium-editor then. @dominik-zeglen We could start with trying to add the editor in the product description TextArea in the dashboard. From the backend point of view, it would be great if we could have a Django widget e.g. `RichTextArea` that could be used as a drop-in replacement for a standard TextArea.
Next step: flat pages? 😄 
Well, that might happen :)

Resolving patch:
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.py
--- a/saleor/dashboard/product/forms.py
+++ b/saleor/dashboard/product/forms.py
@@ -11,6 +11,7 @@
     ProductImage, ProductVariant, Stock, StockLocation, VariantImage)
 from .widgets import ImagePreviewWidget
 from . import ProductBulkAction
+from ..widgets import RichTextEditorWidget
 
 
 class ProductClassSelectorForm(forms.Form):
@@ -137,6 +138,7 @@ def __init__(self, *args, **kwargs):
         self.product_attributes = self.product_attributes.prefetch_related(
             'values')
         self.prepare_fields_for_attributes()
+        self.fields['description'].widget = RichTextEditorWidget()
 
     def prepare_fields_for_attributes(self):
         for attribute in self.product_attributes:
diff --git a/saleor/dashboard/widgets.py b/saleor/dashboard/widgets.py
--- a/saleor/dashboard/widgets.py
+++ b/saleor/dashboard/widgets.py
@@ -1,5 +1,6 @@
 from django import forms
 from django.conf import settings
+from django.forms import Textarea
 from django_filters.widgets import RangeWidget
 from django_prices.widgets import PriceInput
 
@@ -22,3 +23,14 @@ def __init__(self, attrs=None):
 
 class PhonePrefixWidget(StorefrontPhonePrefixWidget):
     template_name = 'dashboard/order/widget/phone_prefix_widget.html'
+
+
+class RichTextEditorWidget(Textarea):
+    """
+    This widget is used to initialize medium-editor out-of-the-box
+    """
+    def __init__(self, attrs=None):
+        default_attrs = {'class': 'rich-text-editor'}
+        if attrs:
+            default_attrs.update(attrs)
+        super().__init__(default_attrs)
diff --git a/saleor/product/migrations/0045_md_to_html.py b/saleor/product/migrations/0045_md_to_html.py
new file mode 100644
--- /dev/null
+++ b/saleor/product/migrations/0045_md_to_html.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.9 on 2018-01-15 11:16
+from __future__ import unicode_literals
+
+from django.db import migrations
+from markdown import markdown
+
+
+def md_to_html(apps, schema_editor):
+    Product = apps.get_model('product', 'Product')
+    for product in Product.objects.all():
+        product.description = markdown(product.description)
+        product.save()
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ('product', '0044_auto_20180108_0814'),
+    ]
+
+    operations = [
+        migrations.RunPython(md_to_html, migrations.RunPython.noop),
+    ]


Test patch: