Rudimentary article_to_html function with markdown module.

This commit is contained in:
maste9 2015-02-15 01:07:20 +01:00 committed by Homer S
parent b2c1a34a98
commit c72d83cf39
1 changed files with 20 additions and 3 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os,re,time,getpass,subprocess import os,re,time,getpass,subprocess,markdown
from string import Template from string import Template
from argparse import ArgumentParser from argparse import ArgumentParser
@ -25,7 +25,7 @@ blog_parser_update.add_argument('subsection', choices=['all','recent','archive',
blog_parser_add = subparsers_blog.add_parser("add", help='add an non-existing blog at --blog-dir') blog_parser_add = subparsers_blog.add_parser("add", help='add an non-existing blog at --blog-dir')
# 'draft' command # 'draft' command
parser_draft = subparsers.add_parser('draft', help='create, list, edit or remove drafts') parser_draft = subparsers.add_parser('draft', help='create, list, edit, publish or remove drafts')
## 'draft' subroutines ## 'draft' subroutines
subparsers_draft = parser_draft.add_subparsers(help="draft subcommands", dest='action') subparsers_draft = parser_draft.add_subparsers(help="draft subcommands", dest='action')
draft_parser_add = subparsers_draft.add_parser('add', help='add a new draft') draft_parser_add = subparsers_draft.add_parser('add', help='add a new draft')
@ -35,6 +35,8 @@ draft_parser_edit = subparsers_draft.add_parser('edit', help='edit certain draft
draft_parser_edit.add_argument('id', help='id like specified by [list]') draft_parser_edit.add_argument('id', help='id like specified by [list]')
draft_parser_remove = subparsers_draft.add_parser('remove', help='remove certain draft') draft_parser_remove = subparsers_draft.add_parser('remove', help='remove certain draft')
draft_parser_remove.add_argument('id', help='id like specified by [list]') draft_parser_remove.add_argument('id', help='id like specified by [list]')
draft_parser_publish = subparsers_draft.add_parser('publish', help='publish draft as article')
draft_parser_publish.add_argument('name', help='name of draft to publish')
# 'article' command # 'article' command
parser_article = subparsers.add_parser('article', help='import, list, edit or delete article') parser_article = subparsers.add_parser('article', help='import, list, edit or delete article')
@ -165,6 +167,12 @@ def update_blog(subsection):
with open(blogIndex,"w", encoding=l10nconf['BLOG_CHARSET']) as f: with open(blogIndex,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
print(tmpIndex, file=f) print(tmpIndex, file=f)
def article_to_html(name):
article = os.path.join(blog_dir,"articles",name + ".txt")
txt = open(article).read()
html = markdown.markdown(txt)
return html
################## ##################
# Main Functions # # Main Functions #
@ -190,6 +198,7 @@ if vars(args)['target'] == 'blog':
# Joining all templates # Joining all templates
update_blog(vars(args)['subsection']) update_blog(vars(args)['subsection'])
print(article_to_html("test"))
print("Updated your blog.") print("Updated your blog.")
@ -231,7 +240,10 @@ if vars(args)['target'] == 'draft':
## edit draft ## edit draft
if vars(args)['action'] == 'edit': if vars(args)['action'] == 'edit':
pass draft = os.path.join(blog_dir,"drafts",vars(args)['id'] + ".txt")
subprocess.call(["emacs", " -nw", draft])
## remove draft ## remove draft
@ -239,6 +251,11 @@ if vars(args)['target'] == 'draft':
if vars(args)['action'] == 'remove': if vars(args)['action'] == 'remove':
pass pass
## publish draft as article
if vars(args)['action'] == 'publish':
pass
# article functions # article functions