benweet / stackedit

In-browser Markdown editor
https://stackedit.io/
Apache License 2.0
21.48k stars 2.7k forks source link

Improve the preview function in VimRepressPy3 #1820

Open vanabel opened 1 year ago

vanabel commented 1 year ago

StackEdit is awesome and I like it very much. But I would like to write markdown in VIM since there are a lot of math symbols I need to type. So I use the plugin VimRepressPy3, it has the preview function proceed by Python, see https://github.com/BourgeoisBear/VimRepressPy3/blob/399dbd9cdd675607c1651fb18befa4083114bf4a/plugin/vimrepress.py#L542:

    def html_preview(self):
        """
        Opens a browser with a local preview of the content.
        @params text_html - the html content
                meta      - a dictionary of the meta data
        """
        if g_data.vimpress_temp_dir == '':
            g_data.vimpress_temp_dir = tempfile.mkdtemp(suffix="vimpress")

        html = \
                """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Vimpress Local Preview: %(title)s</title> <style type="text/css"> ul, li { margin: 1em; } :link,:visited { text-decoration:none } h1,h2,h3,h4,h5,h6,pre,code { font-size:1.1em; } h1 {font-size: 1.8em;} h2 {font-size: 1.5em;} h3{font-size: 1.3em;} h4{font-size: 1.2em;} h5 {font-size: 1.1em;} a img,:link img,:visited img { border:none } body { margin:0 auto; width:770px; font-family: Helvetica, Arial, Sans-serif; font-size:12px; color:#444; } </style> </meta> </head> <body> %(content)s </body> </html>
""" % dict(content=self.html_text, title=self.buffer_meta["title"])
        with open(os.path.join(
                g_data.vimpress_temp_dir, "vimpress_temp.html"), 'w') as f:
            f.write(html)
        webbrowser.open("file://%s" % f.name)

    def remote_preview(self, pub="draft"):
        self.post_status = pub
        self.save_post()
        webbrowser.open("%s?p=%s&preview=true" %
                (g_data.blog_url, self.post_id))

Can we just improve it to preview the content in StackEdit? Thank you in advance!