Exemple #1
0
def html_reader(path):
    meta, content = split_content(path)
    if not meta:
        meta = ObjectDict()
    else:
        meta = parse_yaml_meta(meta, path)
    return Post(path=path, meta=meta, content=to_unicode(content))
Exemple #2
0
def split_content(path):
    file = open_file(path)

    lines = [file.readline().strip()]
    no_meta = False

    for l in file:
        l = l.strip()
        if l.startswith("---"):
            break
        elif l:
            lines.append(l)
    else:
        no_meta = True
    if no_meta:
        return [], to_unicode("\n".join(lines))
    else:
        return lines, to_unicode("".join(file))
Exemple #3
0
def test_txt_reader():
    import datetime
    from catsup.reader import txt_reader
    post_path = os.path.join(BASE_DIR, "post.txt")
    post = txt_reader(post_path)
    assert post.path == post_path
    assert post.date == post.datetime.strftime("%Y-%m-%d") == "2014-01-04"
    assert post.datetime == datetime.datetime(2014, 1, 4, 20, 56)
    assert post.title == "Hello, World!"
    assert post.content == to_unicode("<br />Hi!<br />I&#39;m happy to use Catsup!<br />中文测试<br />")
Exemple #4
0
def txt_reader(path):
    post = html_reader(path)
    content = post.content.encode("utf-8")
    content = escape_html(content)
    content = content.replace(
        "\n",
        "<br />"
    )
    post.content = to_unicode(content)
    return post
Exemple #5
0
def html_reader(path):
    meta, content = split_content(path)
    if not meta:
        meta = ObjectDict()
    else:
        meta = parse_yaml_meta(meta, path)
    return Post(
        path=path,
        meta=meta,
        content=to_unicode(content)
    )
Exemple #6
0
def test_txt_reader():
    import datetime
    from catsup.reader import txt_reader
    post_path = os.path.join(BASE_DIR, "post.txt")
    post = txt_reader(post_path)
    assert post.path == post_path
    assert post.date == "2014-01-04"
    assert post.datetime == datetime.datetime(2014, 1, 4, 20, 56)
    assert post.title == "Hello, World!"
    assert post.content == to_unicode(
        "<br />Hi!<br />I&#39;m happy to use Catsup!<br />中文测试<br />")
Exemple #7
0
def test_md_reader():
    from catsup.reader import markdown_reader
    post_path = os.path.join(BASE_DIR, "2013-02-11-test.md")
    post = markdown_reader(post_path)
    assert post.path == post_path
    assert post.content.strip() == to_unicode("""<p>Hi!
I&#39;m happy to use Catsup!
中文测试</p>

<hr/>
<div class="highlight"><pre><span class="k">print</span><span class="p">(</span><span class="s">&quot;Hello, World!&quot;</span><span class="p">)</span>
</pre></div>""").strip()