Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reST filter doesn't render header levels 1 & 2 #14

Closed
benoistlaurent opened this issue Dec 16, 2015 · 2 comments
Closed

reST filter doesn't render header levels 1 & 2 #14

benoistlaurent opened this issue Dec 16, 2015 · 2 comments

Comments

@benoistlaurent
Copy link

Problem

This classical restructured text formatting for section headers is not rendered as expected by django_markup.

********
Header 1
********

Header 2
========

Header 3
--------

Header 1 & 2 are pure and simply forgotten.

Diagnotic

After some investigations, django_markup uses docutils.core.publish_parts to render rst. django_markup uses this code to render rst:

def render(self, text, **kwargs):
    from docutils import core
    publish_args = {'source': text, 'writer_name': 'html4css1'}
    publish_args.update(**kwargs)
    parts = core.publish_parts(**publish_args)
    return parts['fragment']

parts['fragment'] returns body content only from header 3, which is in agreement with the docutils documentation:

parts['fragment'] contains the document body (not the HTML ). In other words, it contains the entire document, less the document title, subtitle, docinfo, header, and footer.

Proposed solution.

Use parts['html_body'] instead of parts['fragment']:

def render(self, text, **kwargs):
    from docutils import core
    publish_args = {'source': text, 'writer_name': 'html4css1'}
    publish_args.update(**kwargs)
    parts = core.publish_parts(**publish_args)
    return parts['html_body']
@bartTC
Copy link
Owner

bartTC commented Feb 2, 2016

Thanks for pointing this out, I wasn't aware! I'm going to setup some tests before merging it.

bartTC added a commit that referenced this issue Feb 2, 2016
#14.

This changes how the document is fetched from the rST renderer. Before it was fetching the actual document fragment while now it fetches the entire document body including the main and subtitle.

If you prefer the previous behavior, this is easily changed by subclassing the Filter class and adjust the part name:

```
class OldStyleRstMarkupFilter(RstMarkupFilter):
    rst_part_name = 'fragment'
```
@bartTC
Copy link
Owner

bartTC commented Feb 2, 2016

This introduced backwards incompatible behavior. See the related commit 69b3e7c for more info.

@bartTC bartTC closed this as completed Feb 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants