gedit-markdown: support du langage Markdown dans gedit

简介:

原文:http://www.jpfleury.net/en/software/gedit-markdown.php

Overview

gedit-markdown adds support for Markdown (or Markdown Extra) in gedit, the default Gnome text editor.

Specifically, it adds:

  • Markdown syntax highlighting and snippets;

  • plugin Markdown Preview for gedit, displayed in the side panel or the bottom panel and previewing in HTML the current document or selection (this plugin can also be used as a Web browser; see section Usage);

  • an external tool exporting to HTML the current document or selection;

  • a color scheme, optional, highlighting Markdown files in a manner more similar to HTML rendering.

Default Markdown syntax highlighting in gedit.

Requirements

  • gedit-markdown supports gedit 2 and gedit 3. It's shipped with an installer for GNU/Linux. On Windows XP, only a few files work, and must be installed by hand.

  • The plugin Markdown Preview depends on Python 2 (>= 2.6) or Python 3 (>= 3.1), although for now gedit only supports Python 2. The installer will copy the plugin only if the right version of Python is installed.

  • Deactivation of check spelling for irrelevant highlighted contexts (for example in URL) depends on GtkSourceView >= 2.10.

  • For users of Ubuntu 11.10 or later: the package gir1.2-webkit-3.0 must be installed to use the plugin Markdown Preview.

Installation (or update)

GNU/Linux

Markdown support will be added for the current user (so no need root privileges). The folder created by the extraction can be deleted after installation.

Windows XP

Here are steps for gedit 2:

  • Syntax highlighting: in the extracted folder, find the folder language-specs, copy the file corresponding to the Markdown version desired, for example:

    language-specs/markdown.lang
    

    and paste it in the following folder:

    C:\Program Files\gedit\share\gtksourceview-2.0\language-specs\
    
  • Optional color scheme: in the extracted folder, copy the file styles/classic-markdown.xmland paste it in the following folder:

    C:\Program Files\gedit\share\gtksourceview-2.0\styles\
    

Uninstallation

GNU/Linux

  • Open a terminal in the extracted folder.

  • Run the uninstaller in the terminal:

    ./gedit-markdown.sh uninstall
    

Tip: it's possible to specify in command line the version of gedit. Possible values ​​are 2 and 3. It can be useful when updating from gedit 2 to gedit 3. Thus, the script can be run to remove files from the old version of gedit. Example:

./gedit-markdown.sh uninstall 2

Windows XP

Simply remove by hand the files added during installation.

Usage

First of all, restart gedit if it's already running.

Syntax highlighting

Syntax highlighting should automatically be activated for files recognized as Markdown files (extensions .markdown.md or .mkd), otherwise choose it manually by going to View > Highlight Mode > Markup and selecting Markdown.

Plugin Markdown Preview

To enable this plugin, go to Edit > Preferences > Plugins and check Markdown Preview.

Two items are added in the gedit menu Tools:

  • Update Markdown Preview: displays in the side panel or in the bottom panel a preview in HTML of the current document or selection.

    Note: there are two other ways to update preview:

    • with the keyboard shortcut Ctrl+Alt+m (can be changed in the configuration file);

    • by right clicking on the preview area (side or bottom panel) and selecting the item Update Preview (gedit 3 only).

  • Toggle Markdown Preview visibility: allows to display or hide the Markdown Preview panel tab.

    Note: the keyboard shortcut Ctrl+Alt+v (can be changed in the configuration file) can be used to do the same.

If gedit 3 is used, when right clicking on the preview area, a context menu appears and lists several options. Besides the default ones (previous page, next page, copy, etc.), we have:

  • Copy the current URL: copy in the clipboard the URL of the document or the page being displayed in the preview tab. If it's a document that has not yet been saved to disk, this menu item is disabled.

  • Go to another URL: allows to manually enter a local or distant URL of a document or page to visit in the preview tab.

  • One of the following two options, depending on the value of the property externalBrowser in the configuration file:

    • Open in an external browser: allows to open the link in an external browser.

    • Open in the embedded browser: allows to open the link in the panel.

  • Update Preview: reloads in the side panel or in the bottom panel the preview in HTML of the current document or selection.

  • Clear Preview: clear content of the preview tab.

Here's a screenshot of the plugin when it's displayed in the bottom panel:

Markdown Preview in the bottom panel of gedit.

Now the same plugin displayed in the side panel (click to download the original image):

Markdown Preview in the side panel of gedit.

Note that when the cursor passes over a link in the preview area, a tooltip displays the URL:

Tooltip displaying URL when the cursor passes over a link.

Snippets

To use Markdown snippets, activate the plugin Snippets in Edit > Preferences > Plugins. Then, go toTools > Manage Snippets... to see the possibilities.

External tool Export to HTML

To use the external tool, activate the plugin External Tools in Edit > Preferences > Plugins. Then, go to Tools > External Tools > Export to HTML to access the tool. The keyboard shortcut Ctrl+Alt+hdoes the same. The code of the currently opened Markdown file or the selection will be converted in HTML, and the result will be put in a new document.

To edit the tool, go to Tools > Manage External Tools....

Optional color scheme

An optional color scheme is installed by gedit-markdown. To use it, go to Edit > Preferences > Font & Colors > Color Scheme in gedit and select Classic Markdown. This color scheme is more similar to an HTML rendering, for example strong emphases and headers are in bold and black font, links are blue and underlined, etc. Here's a screenshot of a Markdown document highlighted with this color scheme:

Optional color scheme for Markdown syntax highlighting in gedit.

Configuration file

The configuration file of gedit-markdown is the following:

$XDG_CONFIG_HOME/gedit/gedit-markdown.ini

Most of the time, it will correspond to:

$HOME/.config/gedit/gedit-markdown.ini

Only the section markdown-preview can be edited. It contains several properties:

  • externalBrowser: open links in an external browser by default. Possible values: 0 (don't open links in an external browser by default; default value) or 1 (open links in an external browser by default).

    If externalBrowser has a value of 0, the context menu displayed when right clicking on a link will contain an option to open the link in an external browser. If externalBrowser equals 1, the context menu will contain an option to open the link in the embedded browser.

  • panel: emplacement of the preview. Possibles values: side or bottom.

  • shortcut: shortcut to refresh the preview. The default value is <Control><Alt>m.

  • version: the Markdown version to use for the HTML preview and to export to HTML. Possible values: standard or extra.

  • visibility: visibility of the Markdown Preview panel tab when gedit starts. Possible values: 0(hidden) or 1 (displayed; default value).

  • visibilityShortcut: shortcut to toggle Markdown Preview visibility. The default value is<Control><Alt>v.

Details and limitations

  • Syntax highlighting and snippets for standard Markdown were officially added in GtkSourceView and gedit > 3.1.1. The installer of gedit-markdown will ensure that no already existing files are copied (no check is done for Markdown Extra because this is not the default version shipped with GtkSourceView and gedit > 3.1.1).

  • Older versions of gedit-markdown also added Markdown MIME type and recognition of an additional extension (.mdtxt). Since Markdown support was added directly into the shared MIME database shared-mime-info (see the bug report), gedit-markdown no longer adds its own Markdown MIME type file. Also, for purposes of compliance with the specification, the extension .mdtxt is no longer supported.

  • Since HTML code can be directly used in a text written in Markdown, HTML syntax highlighting was added to Markdown syntax highlighting. However, keep in mind that, even if they're highlighted, Markdown syntax within HTML blocks (e.g. <div>) and Markdown Extra syntax within HTML blocks without markdown attribute set to 1 (e.g., <div markdown="1">) are not processed.

  • Within a paragraph, text wrapped with backticks indicates a code span. Markdown allows to use one or more backticks to wrap text, provided that the number is identical on both sides, and the same number of consecutive backticks is not present within the text. Examples:

    `lorem lorem lorem lorem`
    
    `lorem lorem `` lorem lorem`
    
    `lorem lorem ````` lorem lorem`
    
    ``lorem lorem lorem lorem``
    
    ``lorem lorem ` lorem lorem``
    
    ``lorem lorem ````` lorem lorem``
    

    Syntax highlighting in gedit supports code span highlighting with up to 2 backticks surrounding text.

  • Blockquote can contain block-level and inline Markdown elements, but gedit-markdown only highlights inline ones (emphasis, link, etc.).

  • A full context analysis can't be done (because line break can't be used in regex). Here are some consequences:

    • According to the Markdown syntax, to write several paragraphs in a list item, we have to indent each paragraph. Example:

      - Item A (paragraph 1).
      
          Item A (paragraph 2).
      
          Item A (paragraph 3).
      
      - Item B.
      

      So there is a conflict in terms of syntax highlighting between an indented paragraph inside a list item (4 spaces or 1 tab) and an indented line of code outside a list (also 4 spaces or 1 tab). The choice was made ​​​​to highlight code block only from 2 levels of indentation.

    • Only the underline of a Setext-style header is matched and highlighted, so there's no guarantee that it's indeed a title underline.

    • With Markdown Extra, some elements are matched and highlighted with no guarantee that they're in the right context: Setext-style header id attribute, colon used as separator in a definition list and separator line of a table.

Localization

gedit-markdown installer is translatable. Anyone interested in the translation can copy the filegedit-markdown.pot in the folder locale, rename it to LANG.po, translate all strings and send me the result.

Similarly, the plugin Markdown Preview is also localizable. The file containing strings isplugins/markdown-preview/locale/markdown-preview.pot.

For now, gedit-markdown is available in French and English.

Development

Last version: 1.4.1 (2013-01-17)

Git is used for revision control. Repository can be browsed online or cloned.

gedit-markdown has an issue tracker, on which bug reports and feature requests can be submitted.

License

Author: Jean-Philippe Fleury contact@jpfleury.net
Copyright © 2009-2012 Jean-Philippe Fleury

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Third-party code


相关文章
|
5月前
|
Java Unix 程序员
【OS Ctags】Vim 代码阅读工具 Ctags
【OS Ctags】Vim 代码阅读工具 Ctags
41 0
【OS Ctags】Vim 代码阅读工具 Ctags
|
7月前
|
开发工具
vim和typora的makerdown语法
vim和typora的makerdown语法
|
3天前
|
Linux 程序员 开发工具
最强文本编辑器 VIM 获取与安装
最强文本编辑器 VIM 获取与安装
|
5天前
|
Linux C语言
man|文本编辑器-nano|文件拷贝-cp|cat|剪切/重命名-mv
man|文本编辑器-nano|文件拷贝-cp|cat|剪切/重命名-mv
|
开发工具
oeasy教您玩转vim - 2 - # 使用帮助
oeasy教您玩转vim - 2 - # 使用帮助
103 0
|
网络安全 开发工具 git
在Markdown中使用目录
在markdown中使用目录的正确形式
1718 0
|
程序员 Linux 开发工具
Linux系统里让vim支持markdown格式的语法高亮
Markdown是深受程序员喜爱的一个文件格式。 然而Linux里默认的vim设置,并不支持markdown格式的语法高亮显示。 下面就来介绍如何设置使得markdown格式的文件在vim里也能享有语法高亮的待遇。
2240 0
|
Web App开发 开发工具 Python