Render Markdown in Emacs Buffer

Can I imagine Markdown in an Emacs clipboard using the text formatting capabilities of the Emacs clipboard? Emacs in graphical environments has rich text presentation capabilities (font styles, colors, links, and even images), so this should be entirely possible. Are there any existing implementations?

Note that the idea is that the displayed Markdown is Emacs native formatted text that can be moved and worked like any other text in Emacs. Therefore, solutions that display an image embedded in the Emacs buffer are not needed here.

Also note that this is not about the Markdown editing mode, but about the presentation of the Markdown rendering in the Emacs buffer. It should preferably be a clean Emacs Lisp portability solution.

+46
emacs markdown elisp
Aug 04 2018-10-10T00:
source share
8 answers

Personally, I use the following workflow:

  • run Cc Cc m to run Markdown for the current buffer and view the output in another buffer.
  • go to html-mode in this other buffer ( Mx html-mode )
  • hide HTML tags to display something close to output ( Mx sgml-tags-invisible )

Then, every time you want to update the rendering, just run Cc Cc m again in the markdown buffer.

However, I still admit to editing / previewing Markdown, for me nothing compares with Textmate and its preview panel. In fact, from a personal point of view, the only case when I prefer to run Textmate rather than Emacs is when I want to edit markdown files. Still, the path to the same quality of previewing on emacs is not that complicated, and probably I should investigate it. In my opinion, this is simple:

  • get the internal CSS used by Textmate to render the preview
  • use w3 or w3m to preview markdown output using this CSS
+21
Jul 24 2018-12-12T00:
source share

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

Alternatively, you can convert the mark to html in the background and view the html.

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

+6
Aug 05 '10 at 12:24
source share

I have this in the .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 extends all the headers. Markdown mode itself highlights the highlighted text and bold text in bold, so this will bring you there. However, this will not make invisible control characters.

If you want this, you should probably study pretty-lambda for examples (as Bozidar Batov suggested )

+6
Sep 17 '12 at 21:52
source share

Depending on the context in which you want to see the text, you can get closer to what you need by simply changing the default font restriction rules.

+5
Mar 28 2018-12-12T00:
source share

Besides pretty-lambda (which has already been suggested several times), you can look at org-mode and its highliting syntax rules. In particular, the variable org-hide-emphasis-markers does more or less what you want (see, for example, how org-do-emphasis-faces hide markup characters).

+4
Sep 18
source share

Since I don't know any emacs-based Markdown parsers, I have to say that you need to encode it from scratch. Perhaps this SO Question may throw you a few pointers.

If you decide to go through Emacs-only, then Semantic is an excellent API for this work (it offers you a lexer, a parser and a parser, it has existed for more than ten years and has documentation!). After using the language parser, you will need to do some rendering functions for each type of token. And so you can customize everything.

Although it would be an interesting trip, for sure, I would prefer to use the existing Markdown-> html converter in a separate background process, and then use w3 (m) to preview emacs (as Bozidar suggested). He does his job, and it is much easier to do. There are no serious performance issues, not one of them - you should run this tool quite rarely, so you can save a few milliseconds).

The mixed solution should be to force the Markdown parser to generate HTML directly and view it in the w3 (m) buffer (it takes the rendering weight off your shoulders, you only need to translite the markdown in html and it seems pretty straightforward with semantics).

+3
Aug 10 2018-10-10T00:
source share

If it’s just about rendering, go with Bozidar’s suggestion and do the Markdown to HTML conversion, and then display the HTML in the W3 buffer. markdown-mode has code for invoking the external Markdown command with a few goodies.

But if you really want to do everything in Emacs Lisp, you first need to write a Markdown analyzer.

+1
Aug 05 '10 at 13:31
source share

Me too, I have been looking for something like this for a very long time. The best I could find was not an Emacs solution, it was an independent large software called ReText .

0
Mar 28 2018-12-12T00:
source share



All Articles