Skip to content

Commit

Permalink
add vim command
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Tang committed Nov 1, 2015
1 parent b137145 commit 57fad0d
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 2 deletions.
Empty file added Display
Empty file.
Empty file added FileType
Empty file.
Empty file added Initial
Empty file.
Empty file added Others
Empty file.
2 changes: 1 addition & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# git add .
# git commit -am 'just in case'
# git push origin master
mv ~/.vim/bundle/markdown-preview.vim ~/.vim/bundle/markdown-preview.vim.back
mv ~/.vim/bundle/markdown-preview.vim ~/markdown-preview.vim.back
cp -r ../markdown-preview.vim ~/.vim/bundle/markdown-preview.vim
9 changes: 8 additions & 1 deletion plugin/markdown-preview.vim
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ if empty(glob('~/.vim/MarkDownCSS/default.css'))
call MarkdownPreviewInit()
endif

function! MarkdownPreview(args1, args2)
python << EOF
import markdown_preview
markdown_preview.markdownPreviewWithCustomCodeStyle()
EOF
endfunction

function! MarkdownPreview(args1)
python << EOF
import markdown_preview
markdown_preview.markdownPreview()
markdown_preview.markdownPreviewWithDefaultCodeStyle()
EOF
endfunction

Expand Down
38 changes: 38 additions & 0 deletions pythonx/markdown_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,41 @@ def markdownPreview():

url = 'file:///' + currentpath + '/tmp.html'
webbrowser.open(url)

def markdownPreviewWithCustomCodeStyle():
cssName = vim.eval("a:args1")
codeName = vim.eval("a:args2")
currentpath = commands.getstatusoutput("pwd")[1]

if vim.eval("exists('g:MarkDownResDir')") == '1':
cssDir = vim.eval('g:MarkDownResDir')
else:
if platform.system() == 'Windows':
cssDir = os.path.join(vim.eval('$HOME'), 'vimfiles', 'MarkDownRes')
elif vim.eval("has('nvim')") == '1':
cssDir = os.path.join(vim.eval('$HOME'),'.nvim', 'MarkDownRes')
else:
cssDir = os.path.join(vim.eval('$HOME'), '.vim', 'MarkDownRes')

content = "<html>\n"
content += '<meta charset="UTF-8" />\n'
content += '<head>'
content += '<link rel="stylesheet" href="' + cssDir + '/code-styles/' + codeName + '.css">\n'
content += '<link href="' + cssDir + '/' + cssName + '.css" media="all" rel="stylesheet"/>\n'
content += '<script src="' + cssDir + '/js/highlight.min.js"></script>\n'
content += '<script src="' + cssDir + '/js/highlight.pack.js"></script>\n'
content += '<script>hljs.initHighlightingOnLoad();</script>\n'
content += '</head>\n<body>'
buff = ''
for line in vim.current.buffer:
buff += line + '\n'
content += markdown_parser.markdown(buff)
content += "</body></html>"

print currentpath
file = open(os.path.join(currentpath, 'tmp.html'), 'w')
file.write(content)
file.close()

url = 'file:///' + currentpath + '/tmp.html'
webbrowser.open(url)

0 comments on commit 57fad0d

Please sign in to comment.