Ejemplo n.º 1
0
 def _create_pdf(self, obj, output_path):
     if obj.filename.endswith(".rst"):
         filename = obj.slug + ".pdf"
         output_pdf=os.path.join(output_path, filename)
         # print "Generating pdf for", obj.filename, " in ", output_pdf
         self.pdfcreator.createPdf(text=open(obj.filename), output=output_pdf)
         info(u' [ok] writing %s' % output_pdf)
Ejemplo n.º 2
0
 def _create_pdf(self, obj, output_path):
     if obj.filename.endswith(".rst"):
         filename = obj.slug + ".pdf"
         output_pdf = os.path.join(output_path, filename)
         # print "Generating pdf for", obj.filename, " in ", output_pdf
         self.pdfcreator.createPdf(text=open(obj.filename),
                                   output=output_pdf)
         print u' [ok] writing %s' % output_pdf
Ejemplo n.º 3
0
Archivo: readers.py Proyecto: zeke/.com
    def read(self, filename):
        """Parse content and metadata of (x)HTML files"""
        content = open(filename)
        metadatas = {'title': 'unnamed'}
        for i in self._re.findall(content):
            key = i.split(':')[0][5:].strip()
            value = i.split(':')[-1][:-3].strip()
            metadatas[key.lower()] = value

        return content, metadatas
Ejemplo n.º 4
0
    def read(self, filename):
        """Parses restructured text"""
        pub = self._get_publisher(filename)
        parts = pub.writer.parts
        content = parts.get('body')

        metadata = self._parse_metadata(pub.document)
        metadata.setdefault('title', parts.get('title'))

        return content, metadata, open(filename)
Ejemplo n.º 5
0
    def read(self, filename):
        """Parse content and metadata of (x)HTML files"""
        content = open(filename)
        metadatas = {'title':'unnamed'}
        for i in self._re.findall(content):
            key = i.split(':')[0][5:].strip()
            value = i.split(':')[-1][:-3].strip()
            metadatas[key.lower()] = value

        return content, metadatas
Ejemplo n.º 6
0
    def read(self, filename):
        """Parse content and metadata of (x)HTML files"""
        with open(filename) as content:
            metadata = {'title': 'unnamed'}
            for i in self._re.findall(content):
                key = i.split(':')[0][5:].strip()
                value = i.split(':')[-1][:-3].strip()
                name = key.lower()
                metadata[name] = self.process_metadata(name, value)

            return content, metadata
Ejemplo n.º 7
0
    def read(self, filename):
        """Parse content and metadata of markdown files"""
        text = open(filename)
        md = Markdown(extensions=set(self.extensions + ['meta']))
        content = md.convert(text)

        metadata = {}
        for name, value in md.Meta.items():
            name = name.lower()
            metadata[name] = self.process_metadata(name, value[0])
        return content, metadata
Ejemplo n.º 8
0
    def read(self, filename):
        """Parse content and metadata of markdown files"""
        text = open(filename)
        md = Markdown(extensions=set(self.extensions + ['meta']))
        content = md.convert(text)

        metadata = {}
        for name, value in md.Meta.items():
            name = name.lower()
            metadata[name] = _process_metadata(name, value[0])
        return content, metadata
Ejemplo n.º 9
0
    def read(self, filename):
        """Parse content and metadata of markdown files"""
        text = open(filename)
        md = Markdown(extensions=["meta", "codehilite"])
        content = md.convert(text)

        metadatas = {}
        for name, value in md.Meta.items():
            name = name.lower()
            metadatas[name] = _METADATAS_PROCESSORS.get(name, lambda x: x)(value[0])
        return content, metadatas
Ejemplo n.º 10
0
 def read(self, filename):
     """Parse restructured text"""
     text = open(filename)
     metadatas = self._parse_metadata(text)
     extra_params = {"input_encoding": "unicode", "initial_header_level": "2"}
     rendered_content = core.publish_parts(text, writer_name="html", settings_overrides=extra_params)
     title = rendered_content.get("title")
     content = rendered_content.get("body")
     if not metadatas.has_key("title"):
         metadatas["title"] = title
     return content, metadatas
Ejemplo n.º 11
0
    def read(self, filename):
        """Parse content and metadata of (x)HTML files"""
        with open(filename) as content:
            metadata = {'title': 'unnamed'}
            for i in self._re.findall(content):
                key = i.split(':')[0][5:].strip()
                value = i.split(':')[-1][:-3].strip()
                name = key.lower()
                metadata[name] = self.process_metadata(name, value)

            return content, metadata
Ejemplo n.º 12
0
Archivo: readers.py Proyecto: zeke/.com
    def read(self, filename):
        """Parse content and metadata of markdown files"""
        text = open(filename)
        md = Markdown(extensions=['meta', 'codehilite'])
        content = md.convert(text)

        metadatas = {}
        for name, value in md.Meta.items():
            name = name.lower()
            metadatas[name] = _METADATAS_PROCESSORS.get(name,
                                                        lambda x: x)(value[0])
        return content, metadatas
Ejemplo n.º 13
0
 def read(self, filename):
     """Parse restructured text"""
     text = open(filename)
     metadatas = self._parse_metadata(text)
     extra_params = {'input_encoding': 'unicode',
                     'initial_header_level': '2'}
     rendered_content = core.publish_parts(text, writer_name='html',
                                           settings_overrides=extra_params)
     title = rendered_content.get('title')
     content = rendered_content.get('body')
     if not metadatas.has_key('title'):
         metadatas['title'] = title
     return content, metadatas
Ejemplo n.º 14
0
Archivo: readers.py Proyecto: zeke/.com
 def read(self, filename):
     """Parse restructured text"""
     text = open(filename)
     metadatas = self._parse_metadata(text)
     extra_params = {
         'input_encoding': 'unicode',
         'initial_header_level': '2'
     }
     rendered_content = core.publish_parts(text,
                                           writer_name='html',
                                           settings_overrides=extra_params)
     title = rendered_content.get('title')
     content = rendered_content.get('body')
     if not metadatas.has_key('title'):
         metadatas['title'] = title
     return content, metadatas
Ejemplo n.º 15
0
 def read(self, filename):
     """Parse restructured text"""
     text = open(filename)
     metadatas = self._parse_metadata(text)
     extra_params = {'input_encoding': 'unicode',
                     'initial_header_level': '2'}
     rendered_content = core.publish_parts(text, writer_name='html',
                                           settings_overrides=extra_params)
     title = rendered_content.get('title')
     content = rendered_content.get('body')
     
     # construct link between internal pages or article
     for slug, title in re.compile(u':link:(.*):(.*):').findall(content):
         content = content.replace(u':link:' + slug + ':' + title + ':',
                                   u'<a href="../' + slug + '.html" alt="' + title + '" title="' + title + '">'+ title +u'</a>')
     
     if not metadatas.has_key('title'):
         metadatas['title'] = title
     return content, metadatas
Ejemplo n.º 16
0
    def read(self, filename):
        """Parse content and metadata of markdown files"""
        text = open(filename)
        # Remove BOM character, usually at beginning of text 
        # string. Usually `Title` is the first string, but with 
        # a BOM it never matches, and the file is not processed 
        # because Title is compulsary metadata.
        text = text.replace(u'\ufeff', '') 
        md = Markdown(extensions=set(self.extensions + ['meta']), 
                      extension_configs={
                        'codehilite': dict(guess_lang=False) 
                      },
                      output_format='html5')
        content = md.convert(text)

        metadata = {}
        for name, value in md.Meta.items():
            name = name.lower()
            metadata[name] = _process_metadata(name, value[0])
        return content, metadata, text