Skip to content

Instantly share code, notes, and snippets.

@edelooff
Created June 9, 2014 18:56
Show Gist options
  • Save edelooff/1d280ec2745248295dae to your computer and use it in GitHub Desktop.
Save edelooff/1d280ec2745248295dae to your computer and use it in GitHub Desktop.
reST article to demonstrate pelican issue #1369

Automatic post summary causes weird line numbers in code-block

Date: 2014/06/09
tags:Pelican, reStructuredText

This article is a demonstration for Pelican issue #1369. The SUMMARY_MAX_LENGTH is set to 100 words, which means that index pages will list the first 100 words of this article. This includes a portion of the below code snippet, which configured to have its line numbers in a table.

class RstReader(BaseReader):
    """Reader for reStructuredText files"""

    enabled = bool(docutils)
    file_extensions = ['rst']

    def __init__(self, *args, **kwargs):
        super(RstReader, self).__init__(*args, **kwargs)

    def _parse_metadata(self, document):
        """Return the dict containing document metadata"""
        output = {}
        for docinfo in document.traverse(docutils.nodes.docinfo):
            for element in docinfo.children:
                if element.tagname == 'field':  # custom fields (e.g. summary)
                    name_elem, body_elem = element.children
                    name = name_elem.astext()
                    if name == 'summary':
                        value = render_node_to_html(document, body_elem)
                    else:
                        value = body_elem.astext()
                else:  # standard fields (e.g. address)
                    name = element.tagname
                    value = element.astext()
                name = name.lower()

                output[name] = self.process_metadata(name, value)
        return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment