Ejemplo n.º 1
0
def publish_html(filename):
    """Publish a HTML-format post
    """
    html_file = codecs.open(filename, 'r', encoding='utf-8')
    content = html_file.read()

    title, description = post.parse_html(content)
    post.new(title, description)
Ejemplo n.º 2
0
def publish_markdown(title, filename):
    """Publish a markdown post"""

    markdown_file = codecs.open(filename, 'r', encoding='utf-8')
    text = markdown_file.read()

    description = markdown.markdown(text, extensions=['extra', 'toc'])
    description = '<div id="markdown">\n\n%s\n\n</div>' % description

    post.new(title, description)
Ejemplo n.º 3
0
def publish_markdown(filename):
    """Publish a Markdown-format post
    """
    # suppose post `title` is just `filename` without prefix-dirpath and suffix-extension
    title = os.path.splitext(os.path.basename(filename))[0]
    # suppose markdown-file and images are in the same folder
    img_base_path = os.path.dirname(filename)

    markdown_file = codecs.open(filename, 'r', encoding='utf-8')
    text = markdown_file.read()
    description = markdown.markdown(text, extensions=['extra', 'toc'])

    # wrapping `description` in div#markdown is just my favor, it's not necessary
    description = '<div id="markdown">\n\n%s\n\n</div>' % description

    post.new(title, description, img_base_path)
Ejemplo n.º 4
0
 def post(self):
     r = json.loads(self.request.body)
     p = Post.new(r['title'], r['description'])
     self.SendJson(p.json())