예제 #1
0
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,
    }
예제 #2
0
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,
    }
예제 #3
0
파일: extensions.py 프로젝트: Third9/Hoep
 def md(self, md, extension):
     return h.render(md, self.extensions[extension])
예제 #4
0
 def md(self, md, flag):
     return h.render(md, render_flags=self.render_flags[flag])
예제 #5
0
파일: extensions.py 프로젝트: Anomareh/Hoep
 def md(self, md, extension):
     return h.render(md, self.extensions[extension])
예제 #6
0
 def md(self, md, flag):
     return h.render(md, render_flags = self.render_flags[flag])
예제 #7
0
def remove_markdown(text):
    html = h.render(text)
    return BS(html, features='lxml').get_text()
예제 #8
0
 def render(self):
     if self.mdtext is None:
         self.read_mdtext()
     return hoep.render(self.mdtext)