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))
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))
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'm happy to use Catsup!<br />中文测试<br />")
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
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) )
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'm happy to use Catsup!<br />中文测试<br />")
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'm happy to use Catsup! 中文测试</p> <hr/> <div class="highlight"><pre><span class="k">print</span><span class="p">(</span><span class="s">"Hello, World!"</span><span class="p">)</span> </pre></div>""").strip()