From 57fad0d48f74959ec0eb8086ac1082b040afd256 Mon Sep 17 00:00:00 2001 From: Mike Tang Date: Sun, 1 Nov 2015 18:43:20 +0800 Subject: [PATCH] add vim command --- Display | 0 FileType | 0 Initial | 0 Others | 0 deploy.sh | 2 +- plugin/markdown-preview.vim | 9 ++++++++- pythonx/markdown_preview.py | 38 +++++++++++++++++++++++++++++++++++++ 7 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 Display create mode 100644 FileType create mode 100644 Initial create mode 100644 Others diff --git a/Display b/Display new file mode 100644 index 0000000..e69de29 diff --git a/FileType b/FileType new file mode 100644 index 0000000..e69de29 diff --git a/Initial b/Initial new file mode 100644 index 0000000..e69de29 diff --git a/Others b/Others new file mode 100644 index 0000000..e69de29 diff --git a/deploy.sh b/deploy.sh index 3bb0ff4..d18ee02 100644 --- a/deploy.sh +++ b/deploy.sh @@ -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 diff --git a/plugin/markdown-preview.vim b/plugin/markdown-preview.vim index 6ea16a9..2587d37 100644 --- a/plugin/markdown-preview.vim +++ b/plugin/markdown-preview.vim @@ -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 diff --git a/pythonx/markdown_preview.py b/pythonx/markdown_preview.py index d0f8c50..600ee96 100644 --- a/pythonx/markdown_preview.py +++ b/pythonx/markdown_preview.py @@ -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 = "\n" + content += '\n' + content += '' + content += '\n' + content += '\n' + content += '\n' + content += '\n' + content += '\n' + content += '\n' + buff = '' + for line in vim.current.buffer: + buff += line + '\n' + content += markdown_parser.markdown(buff) + content += "" + + print currentpath + file = open(os.path.join(currentpath, 'tmp.html'), 'w') + file.write(content) + file.close() + + url = 'file:///' + currentpath + '/tmp.html' + webbrowser.open(url)