Render Markdown in Emacs buffer

前端 未结 8 622
一个人的身影
一个人的身影 2021-01-30 06:27

Is it possible to present Markdown rendered in an Emacs buffer using Emacs\' own buffer text formatting capabilities? Emacs in graphical environments has rich text presentation

相关标签:
8条回答
  • 2021-01-30 07:06

    Me too, I've been looking for something like this for a very long time. The best I could find, though, is not am Emacs solution, it is an independent great piece of software called ReText.

    0 讨论(0)
  • 2021-01-30 07:07

    If it is only about the rendering, go with Bozhidar's suggestion and do a Markdown to HTML conversion, then display the HTML in a W3 buffer. markdown-mode has code to call the external Markdown command with a few goodies.

    But if you really want to do everything within Emacs Lisp, you'll have to write a Markdown parser first.

    0 讨论(0)
  • 2021-01-30 07:16

    I guess you can use the source code of latex-preview for inspiration or pretty-lambda(a much simpler piece of software).

    Alternatively you can convert the markdown to html in a background process and preview the html.

    Everything is possible in Emacs, but not everything is easily achieved :-)

    0 讨论(0)
  • 2021-01-30 07:18

    I have this in my .emacs file:

    (custom-set-faces
     ;; custom-set-faces was added by Custom.
     ;; If you edit it by hand, you could mess it up, so be careful.
     ;; Your init file should contain only one such instance.
     ;; If there is more than one, they won't work right.
     '(markdown-header-delimiter-face ((t (:inherit font-lock-function-name-face :underline t :weight bold))) t)
     '(markdown-header-face-1 ((t (:inherit markdown-header-face :height 1.5))) t)
     '(markdown-header-face-2 ((t (:inherit markdown-header-face :height 1.3))) t)
     '(markdown-header-face-3 ((t (:inherit markdown-header-face :underline t :height 1.2))) t)
     '(markdown-header-face-4 ((t (:inherit markdown-header-face :underline t :height 1.1))) t)
     '(markdown-header-face-5 ((t (:inherit markdown-header-face :underline t))) t)
     '(markdown-header-face-6 ((t (:inherit markdown-header-face :underline t))) t))
    (put 'set-goal-column 'disabled nil)
    

    which enlarges all the headlines. Markdown-mode itself will italicize starred text and boldface double-starred text, so this will get you there. However, it will not make the control characters invisible.

    If you want that, you should probably look into pretty-lambda for examples (as Bozhidar Batsov suggested)

    0 讨论(0)
  • 2021-01-30 07:20

    Depending on the context where you'd like to see the rendered text, you might be able to get pretty close to what you need by just tweaking markdown-mode's font-lock rules.

    0 讨论(0)
  • 2021-01-30 07:24

    Personally, I use the following workflow:

    • run on a C-c C-c m to run Mark­down on the cur­rent buffer and pre­view the out­put in an­other buffer.
    • move to html-mode on this other buffer (M-x html-mode)
    • hide the html tags to display something close to the output (M-x sgml-tags-invisible)

    Then every time you want to refresh the rendering, simply run again C-c C-c m on the markdown buffer.

    Yet I confess until now for Markdown editing/previewing, nothing beats for me Textmate and its markdown preview panel. Actually, from a personal perspective, the only case where I prefer to run Textmate rather than Emacs is when I want to edit markdown files. Yet the path to have the same quality of preview on emacs is not so difficult and probably I should investigate it. As I see it, it's simply:

    • get the internal css used by Textmate for rendering the preview
    • use w3 or w3m to preview the markdown output using this css
    0 讨论(0)
提交回复
热议问题