├── CHANGELOG.md
├── README.md
└── after
└── ftplugin
└── markdown
└── instant-markdown.vim
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ### 0.0.2 (03-27-2012)
2 |
3 | All changes for this release were made in the backend. Do `[sudo] npm -g update instant-markdown-d` to get them.
4 |
5 | - Updated to the latest github styles!
6 | - Performance should be slightly better as CSS is no longer generated at every update.
7 |
8 | ### 0.0.3 (04-26-2012)
9 |
10 | Some changes for this release were made in the backend. Do `[sudo] npm -g update instant-markdown-d` to get them.
11 |
12 | - Delay starting the `instant-markdown-d` server. This fixed the plugin for a few people who were getting empty browser windows.
13 | - Display a message with configuration instructions when the preview window can't be closed due to Firefox restrictions.
14 |
15 | ### 0.0.4 (12-05-2012)
16 |
17 | All these changes courtesy of @chreekat, THANKS!
18 |
19 | - Is now an `after/ftplugin` plugin. Markdown filetype detection is left to Vim itself, or other plugins.
20 | - Behavior when multiple markdown files are open has been improved
21 | - No more weird characters taking over the status/command bar while editing
22 | - Internals have been completely rewritten and are much more cleaner and adhere to vim script best practices
23 |
24 | ### 0.0.5 (12-05-2012)
25 |
26 | These changes are _also_ courtesy of @chreekat!
27 |
28 | - Plugin no longer breaks vim mouse scrolling
29 | - No longer errors upon opening an empty markdown file
30 | - `instant_markdown_slow` option to update preview less frequently
31 |
32 | ### 0.0.6 (03-02-2013)
33 |
34 | All changes for this release were made in the backend. Do `[sudo] npm -g update instant-markdown-d` to get them.
35 |
36 | - Fix for systems (such as Ubuntu, Debian) which use the `nodejs` executable instead of `node`.
37 |
38 | ### 0.0.7 (10-31-2013)
39 |
40 | thanks to @terryma!
41 |
42 | - Added option to only start previewing markdown on demand
43 |
44 | ### 0.0.8 (01-17-2015)
45 |
46 | All changes for this release were made in the backend. Do `[sudo] npm -g update instant-markdown-d` to get them. All thanks to the awesome work of @euclio!
47 |
48 | - Ruby dependencies (pygments.rb and redcarpet) are no longer required! `instant-markdown-d` is now the only dependency
49 | - Plugin should be _much_ more performant and stable. Should be able to edit at brisk typing speed without slowdowns or crashes.
50 | - Updated to the latest github styles!
51 | - Due to github not fully open-sourcing their current syntax highlighting pipeline, syntax highlighting colors are _slightly_ different.
52 |
53 | ### 0.1.0 (04-15-2016)
54 |
55 | Change `instant-markdown-d` to `instant-markdown-x`.
56 |
57 | - Support local image.
58 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # extra-instant-markdown
2 |
3 | **extra-instant-markdown is a fork of [vim-instant-markdown](https://github.com/suan/vim-instant-markdown).**
4 |
5 | > Want to instantly preview finnicky markdown files, but don't want to leave your favorite editor, or have to do it in some crappy browser textarea? **vim-instant-markdown** is your friend! When you open a markdown file in vim, a browser window will open which shows the compiled markdown in real-time, and closes once you close the file in vim.
6 |
7 | As a bonus, [github-flavored-markdown][gfm] is supported, and styles used while previewing are the same as those github uses!
8 |
9 | [![Screenshot][ss]][ssbig]
10 |
11 | ## Installation
12 |
13 | You first need to have node.js with npm installed.
14 |
15 | - `[sudo] npm -g install instant-markdown-x`
16 | - If you're on Linux, the `xdg-utils` package needs to be installed (is installed by default on Ubuntu).
17 | - Using [Vundle](https://github.com/VundleVim/Vundle.vim) and add `NBUT-Developers/extra-instant-markdown`.
18 | - Open a markdown file in vim and enjoy!
19 |
20 | ## Configuration
21 |
22 | ### g:instant_markdown_slow
23 |
24 | By default, extra-instant-markdown will update the display in realtime. If that taxes your system too much, you can specify
25 |
26 | ```
27 | let g:instant_markdown_slow = 1
28 | ```
29 |
30 | before loading the plugin (for example place that in your `~/.vimrc`). This will cause extra-instant-markdown to only refresh on the following events:
31 |
32 | - No keys have been pressed for a while
33 | - A while after you leave insert mode
34 | - You save the file being edited
35 |
36 | ### g:instant_markdown_autostart
37 |
38 | By default, extra-instant-markdown will automatically launch the preview window when you open a markdown file. If you want to manually control this behavior, you can specify
39 |
40 | ```
41 | let g:instant_markdown_autostart = 0
42 | ```
43 |
44 | in your .vimrc. You can then manually trigger preview via the command ```:InstantMarkdownPreview```. This command is only available inside markdown buffers and when the autostart option is turned off.
45 |
46 | ## Supported Platforms
47 |
48 | OSX and Unix/Linuxes*.
49 |
50 | *: One annoyance in Linux is that there's no way to reliably open a browser page in the background, so you'll likely have to manually refocus your vim session everytime you open a Markdown file. If you have ideas on how to address this I'd love to know!
51 |
52 | ## FAQ
53 |
54 | > Why don't my `.md` files trigger this plugin?
55 |
56 | By default, vim (7.3 and above) only recognizes files ending with `.markdown`, `.mdown`, and `README.md` as markdown files. If you want `.md` to be recognized, I recommend installing one of many markdown plugins available, such as [this one][tpope-markdown].
57 |
58 | > It's not working!
59 |
60 | - Make sure `instant-markdown-x` was installed as a global module (e.g. using `npm -g install`)
61 | - If you're on OSX and are using zsh, try to add `set shell=bash\ -i` in your `.vimrc` to set interactive bash as the default vim shell. (See [this issue](http://github.com/suan/vim-instant-markdown/issues/41))
62 |
63 | ## etc.
64 |
65 | If you're curious, the code for the mini-server component for this plugin can be found at http://github.com/suan/instant-markdown-d. A plugin can easily be written for any editor to interface with the server to get the same functionality found here.
66 |
67 | [ss]: http://dl.dropbox.com/u/28956267/instant-markdown-demo_thumb.gif "Click for bigger preview"
68 | [ssbig]: http://dl.dropbox.com/u/28956267/instant-markdown-demo.gif
69 | [gfm]: http://github.github.com/github-flavored-markdown/
70 | [tpope-markdown]: https://github.com/tpope/vim-markdown
71 |
--------------------------------------------------------------------------------
/after/ftplugin/markdown/instant-markdown.vim:
--------------------------------------------------------------------------------
1 | " # Configuration
2 | if !exists('g:instant_markdown_slow')
3 | let g:instant_markdown_slow = 0
4 | endif
5 |
6 | if !exists('g:instant_markdown_autostart')
7 | let g:instant_markdown_autostart = 1
8 | endif
9 |
10 | " # Utility Functions
11 | " Simple system wrapper that ignores empty second args
12 | function! s:system(cmd, stdin)
13 | if strlen(a:stdin) == 0
14 | call system(a:cmd)
15 | else
16 | call system(a:cmd, a:stdin)
17 | endif
18 | endfu
19 |
20 | function! s:refreshView()
21 | let bufnr = expand('')
22 | call s:system("curl -X PUT -T - http://localhost:18474/ &>/dev/null &",
23 | \ s:bufGetContents(bufnr))
24 | endfu
25 |
26 | function! s:startDaemon(initialMD)
27 | call s:system("instant-markdown-x " . shellescape(expand("%:p:h")) . " &>/dev/null &", a:initialMD)
28 | endfu
29 |
30 | function! s:initDict()
31 | if !exists('s:buffers')
32 | let s:buffers = {}
33 | endif
34 | endfu
35 |
36 | function! s:pushBuffer(bufnr)
37 | call s:initDict()
38 | let s:buffers[a:bufnr] = 1
39 | endfu
40 |
41 | function! s:popBuffer(bufnr)
42 | call s:initDict()
43 | call remove(s:buffers, a:bufnr)
44 | endfu
45 |
46 | function! s:killDaemon()
47 | call system("curl -s -X DELETE http://localhost:18474/ &>/dev/null &")
48 | endfu
49 |
50 | function! s:bufGetContents(bufnr)
51 | return join(getbufline(a:bufnr, 1, "$"), "\n")
52 | endfu
53 |
54 | " I really, really hope there's a better way to do this.
55 | fu! s:myBufNr()
56 | return str2nr(expand(''))
57 | endfu
58 |
59 | " # Functions called by autocmds
60 | "
61 | " ## push a new Markdown buffer into the system.
62 | "
63 | " 1. Track it so we know when to garbage collect the daemon
64 | " 2. Start daemon if we're on the first MD buffer.
65 | " 3. Initialize changedtickLast, possibly needlessly(?)
66 | fu! s:pushMarkdown()
67 | let bufnr = s:myBufNr()
68 | call s:initDict()
69 | if len(s:buffers) == 0
70 | call s:startDaemon(s:bufGetContents(bufnr))
71 | endif
72 | call s:pushBuffer(bufnr)
73 | let b:changedtickLast = b:changedtick
74 | endfu
75 |
76 | " ## pop a Markdown buffer
77 | "
78 | " 1. Pop the buffer reference
79 | " 2. Garbage collection
80 | " * daemon
81 | " * autocmds
82 | fu! s:popMarkdown()
83 | let bufnr = s:myBufNr()
84 | silent au! instant-markdown *
85 | call s:popBuffer(bufnr)
86 | if len(s:buffers) == 0
87 | call s:killDaemon()
88 | endif
89 | endfu
90 |
91 | " ## Refresh if there's something new worth showing
92 | "
93 | " 'All things in moderation'
94 | fu! s:temperedRefresh()
95 | if !exists('b:changedtickLast')
96 | let b:changedtickLast = b:changedtick
97 | elseif b:changedtickLast != b:changedtick
98 | let b:changedtickLast = b:changedtick
99 | call s:refreshView()
100 | endif
101 | endfu
102 |
103 | fu! s:previewMarkdown()
104 | call s:startDaemon(join(getline(1, '$'), "\n"))
105 | aug instant-markdown
106 | if g:instant_markdown_slow
107 | au CursorHold,BufWrite,InsertLeave call s:temperedRefresh()
108 | else
109 | au CursorHold,CursorHoldI,CursorMoved,CursorMovedI call s:temperedRefresh()
110 | endif
111 | au BufWinLeave call s:cleanUp()
112 | aug END
113 | endfu
114 |
115 | fu! s:cleanUp()
116 | call s:killDaemon()
117 | au! instant-markdown *
118 | endfu
119 |
120 | if g:instant_markdown_autostart
121 | " # Define the autocmds "
122 | aug instant-markdown
123 | au! *
124 | au BufEnter call s:refreshView()
125 | if g:instant_markdown_slow
126 | au CursorHold,BufWrite,InsertLeave call s:temperedRefresh()
127 | else
128 | au CursorHold,CursorHoldI,CursorMoved,CursorMovedI call s:temperedRefresh()
129 | endif
130 | au BufWinLeave call s:popMarkdown()
131 | au BufwinEnter call s:pushMarkdown()
132 | aug END
133 | else
134 | command! -buffer InstantMarkdownPreview call s:previewMarkdown()
135 | endif
136 |
--------------------------------------------------------------------------------