当前位置: 首页 > news >正文

markdown support in emacs

Several excellent packages enhance emacs’s support for Markdown. Depending on the specific needs—such as syntax highlighting, live preview, export options, or integration with other tools—you can choose from one or a combination of these popular Markdown packages:

1. Markdown Mode (markdown-mode)

Overview:
markdown-mode is the most widely used Markdown editing mode in Emacs. It provides comprehensive support for editing Markdown files with features like syntax highlighting, indentation, and keybindings for common tasks.

Key Features:

  • Syntax Highlighting: Clear differentiation of Markdown elements (headers, lists, code blocks, etc.).
  • Live Preview: Integration with built-in or external preview tools.
  • Export Options: Export Markdown to HTML, PDF (via other tools like Pandoc), and more.
  • Customizable: Extensive customization options to tailor the editing experience.

Installation:
You can install markdown-mode via MELPA:

M-x package-install RET markdown-mode RET

Basic Configuration:

(require 'markdown-mode)
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))

2. Pandoc Mode (pandoc-mode)

Overview:
If you frequently convert Markdown to various formats (PDF, DOCX, HTML, etc.), pandoc-mode integrates the powerful Pandoc converter directly into Emacs.

Key Features:

  • Easy Conversion: Convert documents using Pandoc commands within Emacs.
  • Syntax Highlighting & Editing: Leverage markdown-mode or other editing modes alongside Pandoc features.
  • Template Support: Use and customize Pandoc templates for export.

Installation:
Install via MELPA:

M-x package-install RET pandoc-mode RET

Basic Configuration:

(require 'pandoc-mode)
(add-hook 'markdown-mode-hook 'pandoc-mode)

Usage:
Use M-x pandoc-convert to convert your Markdown files to the desired format.

3. Grip Mode (grip-mode)

Overview:
For those who want to preview GitHub-Flavored Markdown (GFM) as it appears on GitHub, grip-mode uses the Grip tool to render Markdown in a browser.

Key Features:

  • Accurate GFM Rendering: Matches GitHub’s rendering closely.
  • Live Preview: Automatically updates the browser preview as you edit.
  • Integration with GitHub: Useful for writing README files and GitHub documentation.

Installation:
First, install Grip (a Python package):

pip install grip

Then, install grip-mode via MELPA:

M-x package-install RET grip-mode RET

Basic Configuration:

(require 'grip-mode)
(add-hook 'markdown-mode-hook 'grip-mode)

Usage:
Start the Grip server with M-x grip-mode and view the preview in your default web browser.

4. Poly-Markdown (poly-markdown)

Overview:
If you work with Markdown files containing multiple languages or embedded code snippets, poly-markdown uses polymode to support multiple major modes simultaneously.

Key Features:

  • Multi-Language Support: Edit code blocks in their respective language modes (e.g., Python, JavaScript) within Markdown.
  • Enhanced Editing: Syntax highlighting and indentation for embedded languages.
  • Flexible Configuration: Customize which languages are supported and how they are handled.

Installation:
Install via MELPA:

M-x package-install RET poly-markdown RET

Basic Configuration:

(require 'poly-markdown)
(poly-markdown-mode)

5. Markdown-TOC (markdown-toc)

Overview:
Automatically generate and update a table of contents (TOC) in your Markdown files based on the headers present.

Key Features:

  • Automatic TOC Generation: Insert a TOC that updates with your document’s structure.
  • Customizable Levels: Choose which header levels to include in the TOC.
  • Easy Updating: Refresh the TOC with a simple command.

Installation:
Install via MELPA:

M-x package-install RET markdown-toc RET

Basic Configuration:

(require 'markdown-toc)

Usage:
Use M-x markdown-toc-generate-toc to insert a TOC and M-x markdown-toc-refresh-toc to update it.

6. Additional Enhancements

  • Company Mode for Autocompletion: Enhance your Markdown editing with autocompletion features.

    Installation:

    M-x package-install RET company RET
    

    Configuration:

    (add-hook 'markdown-mode-hook 'company-mode)
    
  • Flycheck for Syntax Checking: Ensure your Markdown syntax is correct as you type.

    Installation:

    M-x package-install RET flycheck RET
    

    Configuration:

    (add-hook 'markdown-mode-hook 'flycheck-mode)
    
  • Preview Enhancements: Use helm or ivy for enhanced navigation and previewing features within your Markdown documents.

7. Choosing the Right Setup

Your optimal setup depends on your workflow:

  • Basic Editing: markdown-mode is sufficient for most users.
  • Conversion Needs: Pair markdown-mode with pandoc-mode for versatile export options.
  • GitHub Integration: Use grip-mode for accurate GitHub previews.
  • Multi-Language Documents: Implement poly-markdown for documents with embedded code.
  • Enhanced Navigation & TOC: Incorporate markdown-toc and tools like helm or ivy.

8. Sample Configuration

Here’s a sample Emacs configuration snippet that combines several of the above tools for a robust Markdown editing environment:

;; Package Initialization
(require 'package)
(setq package-archives '(("melpa" . "https://melpa.org/packages/")("gnu" . "https://elpa.gnu.org/packages/")))
(package-initialize)
(unless package-archive-contents(package-refresh-contents));; Install Required Packages
(dolist (pkg '(markdown-mode pandoc-mode grip-mode poly-markdown markdown-toc company flycheck))(unless (package-installed-p pkg)(package-install pkg)));; Markdown Mode Setup
(require 'markdown-mode)
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(add-hook 'markdown-mode-hook 'flycheck-mode)
(add-hook 'markdown-mode-hook 'company-mode)
(add-hook 'markdown-mode-hook 'grip-mode)
(add-hook 'markdown-mode-hook 'markdown-toc-mode);; Pandoc Mode Setup
(require 'pandoc-mode)
(add-hook 'markdown-mode-hook 'pandoc-mode);; Poly-Markdown Setup
(require 'poly-markdown)
(add-hook 'markdown-mode-hook 'poly-markdown-mode);; Markdown TOC Setup
(require 'markdown-toc);; Optional: Custom Keybindings
(define-key markdown-mode-map (kbd "C-c C-t g") 'markdown-toc-generate-toc)
(define-key markdown-mode-map (kbd "C-c C-t r") 'markdown-toc-refresh-toc)

9. Resources and Further Reading

  • Markdown Mode GitHub: markdown-mode on GitHub
  • Pandoc Mode GitHub: pandoc-mode on GitHub
  • Grip Mode GitHub: grip-mode on GitHub
  • Poly-Markdown GitHub: poly-markdown on GitHub
  • Emacs Wiki - Markdown: Emacs Wiki - Markdown

10. Conclusion

Emacs offers a rich ecosystem for Markdown support, allowing you to tailor your editing environment to your precise needs. Starting with markdown-mode, you can progressively integrate additional packages like pandoc-mode, grip-mode, and others to enhance functionality, streamline your workflow, and improve your Markdown editing and previewing experience.


http://www.mrgr.cn/news/35004.html

相关文章:

  • 蓝桥杯每日真题 - 第7天
  • Collections.synchronizedList()你真的会用吗?
  • gitlab角色、权限
  • 半导体制造技术导论(第二版)萧宏 第二章集成电路工艺介绍答案
  • Chromium 中chrome.system.display扩展接口定义c++
  • 基于vue框架的的商品销售平台p2l5b(程序+源码+数据库+调试部署+开发环境)系统界面在最后面。
  • 【C++】容器适配器,stack,queue,priority_queue详解,模拟实现
  • 召回04 离散特征的处理
  • HyperWorks的实体几何创建与六面体网格剖分
  • 初识前端监控
  • 探秘链表:十大经典题目全解析
  • 使用 UWA Gears 测试小游戏性能
  • 828华为云征文 | 在华为云上通过Docker容器部署Elasticsearch并进行性能评测
  • vue2 实现简易版的模糊查询功能
  • 1.1 HuggingFists简介(二)
  • 华为云长江鲲鹏深度赋能,大势智慧稳居“实景三维+AI”领域排头兵
  • 解决银河麒麟桌面操作系统V10SP1 SSH连接“connection reset by ip地址 port 22”问题
  • Qt 每日面试题 -3
  • Linux:文件描述符详解
  • RocketMQ简介与应用场景
  • x-cmd pkg | hurl - 强力的 HTTP 请求测试工具,让 API 测试更加简洁和高效
  • PCIe configuration 包分析
  • 【深度学习|地学应用】glacier——让我们一起看看深度学习在冰川研究中的应用是怎么样的呢?
  • np.pad实现零填充
  • Python知识点:如何使用Python与Java进行互操作(Jython)
  • js中正则表达式中【exec】用法深度解读