instant-markdown/vim-instant-markdown

Python mini server as an alternative to the nodejs instant-markdown-d

Closed this issue ยท 12 comments

Pros: Straightforward installation. Easier to cache (lru_cache) rendered markdown

Cons: speculating here: Less powerful markdown rendering? Mathjax?

See for inspiration:

This looks great, and it is pandoc based which would make rendering very feature rich: https://pypi.org/project/smdv/
It only needs an ability to recieve text from stdin, which is super easy with python's fileinput standard library.

cc: @flaport if you are interested

Hi!

Interesting that you found your way tot he smdv library... It's only been on PyPI for a few days ;)

Since you found it there anyway, I made the github repository public. I also added an --stdin flag to smdv.

cheers

I got lucky as I was looking for pandoc+flask server. Even some of the args are the same! (--port and --browser)

I tried to see how it goes. See #160. Some quick feedback.

If I manually edit the url and remove the @stdin it works

  • Can you also make the server accept:
  • a PUT request to receive updated markdown lines

https://github.com/suan/vim-instant-markdown/blob/5820f53eb8ec75f13a84aa616ecd7eb5335ce14c/after/ftplugin/markdown/instant-markdown.vim#L70-L74

  • and a DELETE request to stop the server

https://github.com/suan/vim-instant-markdown/blob/5820f53eb8ec75f13a84aa616ecd7eb5335ce14c/after/ftplugin/markdown/instant-markdown.vim#L117-L124

Hope I am not asking too much.

I see that you have a GET endpoint to stop the server. That could work too. But do consider adding a PUT request capability.

Ok, I'll see what I can do. I'm a bit busy at the moment, but I'll try to implement this asap.

Do it when you are free ๐Ÿ‘.

Ok, so I have been looking into this.

First of all, I removed the GET request to stop the server in favor of a DELETE request. The server can now be stopped as follows (the default port of smdv is 9876, but obviously this can be changed):

curl -s -X DELETE http://localhost:9876

Also, I removed the /@stdin route in favor of a route at /. Starting the smdv server with the --stdin flag will make sure that the contents of stdin will be displayed at /:

echo "hello" | smdv --stdin

Also, when the server has been started with the --stdin flag, it accepts PUT requests at http://localhost:9876:

echo "new content" | curl -s -X PUT -T - http://localhost:9876

the above command will replace all the content displayed at http://localhost:9876... and this is where I'm a bit stuck. I do not really know how the exact curl command from vim-instant-markdown will look like (mostly due to my utter lack of vim script knowledge) to insert/replace only a certain number of lines, hence this is not yet implemented, although this should be a very easy fix...

Could you give me an exact example of how the curl command will look like which vim-instant-markdown will use to request an update?

The vim command, in essence, would be something equivalent to (see lines 40-50) in the plugin:

call system("curl -s -X PUT -T - http://localhost:9876", "All the content... including new content")

and according to the vim docs:

system({cmd} [, {input}])				*system()* *E677*
		Get the output of {cmd} as a |string| (use |systemlist()| to
		get a |List|). {cmd} is treated exactly as in |jobstart()|.
		Not to be used for interactive commands.

		If {input} is a string it is written to a pipe and passed as
		stdin to the command.  The string is written as-is, line
		separators are not changed.

So your implementation seems good enough. As for replacing certain number of lines, my vim knowledge is not good enough to implement that either. We can leave that for later.

EDIT: clarified that all the content are transmitted.

I think with python on smdv side, there is a possibility to split paragraphs of markdown, render to html and stitch together. Like that, one could exploit functools.lru_cache and the rendering could be super fast.

Closing as we now have something basic.

indeed.. should be easy enough to implement. The only thing we should agree then on is the format of how the updated lines/content are sent to the server. Maybe a diff can be sent to the server or something like that. However, I'll leave it the way it is now. We can have a look at that another time if necessary.

cf.: #160