def parse_article(articlename, articlefile): with open(articlefile, "r") as f: article = f.read() in_meta = False lines = article.splitlines() title, date, location, description = None, None, None, None for i, line in enumerate(lines): if line == "---": if in_meta: break in_meta = True elif in_meta: if line.startswith("description:"): description = line.replace("description:", "").strip() elif line.startswith("title:"): title = line.replace("title:", "").strip() elif line.startswith("location:"): location = line.replace("location:", "").strip() elif line.startswith("date:"): date = line.replace("date:", "").strip() date = dateutil.parser.parse(date) else: raise AssertionError("Unknown meta field '%s'" % line) if not title: raise ValueError("title is missing in article %s" % articlefile) if not date: raise ValueError("date is missing in article %s" % articlefile) i += 1 while not lines[i].strip(): i += 1 body = "\n".join(lines[i:]) html = hoep.render(body, 0, 0) articlename = articlename.split("__", 1) try: articlename = articlename[1] except IndexError: articlename = articlename[0] articlename.replace("_", "-") return { "name": articlename, "title": title, "date": date, "body": html, "location": location, "description": description, }
def md(self, md, extension): return h.render(md, self.extensions[extension])
def md(self, md, flag): return h.render(md, render_flags=self.render_flags[flag])
def md(self, md, flag): return h.render(md, render_flags = self.render_flags[flag])
def remove_markdown(text): html = h.render(text) return BS(html, features='lxml').get_text()
def render(self): if self.mdtext is None: self.read_mdtext() return hoep.render(self.mdtext)