jamesturk / django-markupfield

📑 a MarkupField for Django

Home Page:http://pypi.python.org/pypi/django-markupfield

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need help with set up

hnykda opened this issue · comments

Hello,

I'd like to use MarkupField with ReST in admin app when I want to add new blog post. Unfortunately I'm not able to run it properly. My current config looks like this:

settings.py

from docutils.core import publish_parts

def render_rest(markup):
    parts = publish_parts(source=markup, writer_name="html4css1")
    return parts["fragment"]

MARKUP_FIELD_TYPES = (
    ('ReST', render_rest),
)

models.py

class Blog(models.Model):
    ...
    mdf = MarkupField(null=True, blank=True)
    ...

I successfuly migrated (using South) and I can see this field in django admin when I want to add Blog object.

But when I try to type e.g.:

====================
Heading 1
====================

Heading 2
-----------------

Ok what now **bold text** and here *italic* and try ``code``.

`THis link is unfortunately relative <www.google.com>`_

In final page I end up with no headings (they are not just hidden - when I run developer tools, they are just not rendered), I can't manage to make link absolute (now I end up mydomain.com/blog/www.google.com and code is represented as <tt class="docutils literal">code</tt> - but that is rendered as normal text - do I need to edit manually these classes in style.css?

Thank you for you help.

yes, you'd need to ensure that those classes are styled however you wish. you're probably using a css reset if that isn't being rendered as fixed width

I'm confused because of this:

>>> p = Blog.objects.all()[6] 
>>> p.mdf
<markupfield.fields.Markup object at 0x7f9a16370b70>
>>> p.mdf.markup_type
'ReST'
>>> p.mdf.raw
'some text'
>>> p.mdf.rendered
'<p>some text</p>\n'
>>> p.mdf.raw = """
... aaa
... ===
... 
... """
>>> p.save()
>>> p.mdf.raw
'\naaa\n===\n\n'
>>> p.mdf.rendered
''
>>> 

\naaa\n===\n\n this should be treated as a headline, but it is not even rendered (just as empty string). Thank you for your help

Do you think you can contribute a test demonstrating this, I can't replicate it locally so I imagine it is a configuration thing, but a test would help us figure out where the problem is.

Sorry for that. I had to mess something up. I try that with new project and it works fine.

By the way - are there any "sample" css styles for docutils etc.? I've founded these but it's kind a heavy. E.g now default list is created with <ul class="simple"> and I'd like to change it to <ul class="style1">. Where I could do that?

Thank you very much

I'm not aware of other docutils CSS, if you want something simple you could write your own though.

Going to go ahead and close this issue.