After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 384446 - Markdown syntax
Markdown syntax
Status: RESOLVED FIXED
Product: gtksourceview
Classification: Platform
Component: Syntax files
unspecified
Other All
: Normal enhancement
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on:
Blocks: 650253
 
 
Reported: 2006-12-10 18:15 UTC by ulrik sverdrup
Modified: 2011-07-03 19:28 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
markdown.lang syntax file (1.75 KB, application/xml)
2006-12-10 18:17 UTC, ulrik sverdrup
Details
markdown.lang now LGPL (1.78 KB, application/xml)
2007-06-19 15:29 UTC, ulrik sverdrup
Details
Markdown language definition based on the 2.0 spec (13.25 KB, application/xml)
2011-05-15 19:32 UTC, Jean-Philippe Fleury
Details
Sample Markdown file for testing syntax highlighting (3.38 KB, text/plain)
2011-05-15 19:39 UTC, Jean-Philippe Fleury
Details
Markdown language definition based on the 2.0 spec (13.17 KB, application/xml)
2011-05-23 15:50 UTC, Jean-Philippe Fleury
Details
Markdown language definition based on the 2.0 spec (13.17 KB, application/xml)
2011-05-24 20:21 UTC, Jean-Philippe Fleury
Details
Markdown language definition based on the 2.0 spec (14.96 KB, application/xml)
2011-06-23 02:42 UTC, Jean-Philippe Fleury
Details
Markdown language definition based on the 2.0 spec (15.00 KB, text/plain)
2011-06-26 13:55 UTC, Jean-Philippe Fleury
Details
Markdown language definition based on the 2.0 spec (14.88 KB, text/plain)
2011-06-26 22:09 UTC, Jean-Philippe Fleury
Details

Description ulrik sverdrup 2006-12-10 18:15:46 UTC
This is a request for Markdown syntax coloring to be included in the gtksourceview main distribution.

I have written the only syntax file I can find on the web for gtksourceview, and it has a (small) webpage here:
http://www.student.lu.se/~cif04usv/wiki/gedit.html

There are some major caveats for this syntax file:
* There is no agreed mimetype, file extension or anything for markdown. `file` cannot distinguish it from plain text
* I'm not a great regex artist
* I can in no way check that the parsing by this syntax file is equivalent to the proper markdown parser.
* The default syntax styles are all code-oriented so to get anything like a default coloring, **bold** is style="Data Type", _emph_ is style="Preprocessor" et cetera. This is naturally wrong but it's better than a blank style

Apart from that, I know that this file has been used and it is appreciated by at least a very small community. I have recently updated it to v2 to fix a known bug and add some things. Still, I guess it's pretty wrong in some places.

Also, the syntax file wrongly includes a [[Wiki link]] style (non-visible by default), as this is a common addition (ikiwiki)
Comment 1 ulrik sverdrup 2006-12-10 18:17:03 UTC
Created attachment 78090 [details]
markdown.lang syntax file

markdown.lang v2
Comment 2 ulrik sverdrup 2007-06-19 15:29:09 UTC
Created attachment 90275 [details]
markdown.lang now LGPL

now LGPL licensed for compatibility with gtksourceview 2.0
Comment 3 Dimitris Glezos 2008-09-24 14:33:13 UTC
Confirming that this file works.
Comment 4 Ignacio Casal Quinteiro (nacho) 2009-12-02 20:18:46 UTC
Sorry for the late response, but I just had a look right now at the file. Just say that we are no longer including lang files based on the 1.0 spec, you should update the file to use the 2.0 one.
Comment 5 Jean-Philippe Fleury 2011-05-15 19:32:36 UTC
Created attachment 187862 [details]
Markdown language definition based on the 2.0 spec

Here's Markdown language definition based on the 2.0 spec.
Comment 6 Jean-Philippe Fleury 2011-05-15 19:37:40 UTC
For Markdown file extension, I chose "*.markdown;*.md;*.mdtxt". Here's why:

# Markdown file extension #

There's no official Markdown file extension, so I did some research on actual usage by text editors, implementations' documentation or other stuff.

## Actual usage review ##

### Text editors ###

- BBEdit: `.mark`, `.markdown`, `.text`
- Eclipse (Markdown Editor plugin): `.md`; suggests to also add `.txt`
- Elements (iOS text editor): `.markdown`, `.md`, `.mdown`, `.mdwn`
- Emacs: (markdown-mode): no extension by default, but gives an example to associate `.text` with markdown-mode, with the following precision: *"There is no consensus on an official file extension so change `.text` to `.mdwn`, `.md`, `.mdt`, or whatever you call your markdown files."*
- Geany: `.mdml`
- Gedit (gedit-markdown): `.mdtxt`
- Jedit (Jedit mode for Markdown/Pandoc): `.markdown`, `.md`, `.pandoc`, `.pdc`
- Kate (Markdown Color Syntax Highlighting): `.md`, `.mmd`, `.text`
- Notepad++ (markdown_npp): `.md`
- SubEthaEdit: `.markdown`, `.md`
- Textmate: `.markdn`, `.markdown`, `.md`, `.mdown`
- vi and vim (pdc.vim): for filetype detection, suggests `.pdc`

### Implementations ###

Extensions used for documentation/README files written in Markdown.

- BlueCloth (Ruby fork): `.markdown`
- lua-discount (Lua): `.mkd`
- lunamark (Lua): `.markdown`
- Maraku (Ruby): `.md`
- Markdown (Perl): `.text`
- MarkdownJ (Java): `.markdown`
- Markout (Java): `.text`
- MultiMarkdown (C): `.markdown`
- Pandoku (Ruby): `.markdown`
- pegdown (Java): `.markdown`
- peg-markdown (C): `.markdown`
- PHP Markdown (PHP): `.text`
- python-markdown (Python): `.txt`
- python-markdown2 (Python): `.md`
- RDiscount (Ruby): `.markdown`
- rpeg-markdown (Ruby): `.markdown`
- text-markdown (Perl): `.text`

### Other ###

- ayans (news system): `.mdtxt`
- GAE django blog: `.md`, `.mdtxt` (for HELP and README files)
- github.com: `.markdown`, `.md`, `.mdown`, `.mkd`, `.mkdn` (for README files written in Markdown)
- Markdown-Discuss list: in 2 discussions on Markdown-Discuss list, extensions reported to be used by participants are: `.markdown`, `.md`, `.mdown`, `.mkd`, `.text`, `.txt`
- Squeletml: `.mdtxt`

## Unscientific statistics ##

**Unscientific** statistics (number of times extensions are used or suggested):

- `.markdown`: 16
- `.md`: 13
- `.text`: 8
- `.mdown`: 4
- `.mdtxt`: 4
- `.mkd`: 3
- `.txt`: 3
- `.mdwn`: 2
- `.pdc`: 2
- `.mark`: 1
- `.markdn`: 1
- `.mdml`: 1
- `.mdt`: 1
- `.mkd`n: 1
- `.mmd`: 1
- `.pandoc`: 1

## My choice ##

It seems to me that `.text` and `.txt` extensions are really too generic to be automatically associated with Markdown syntax highlighting.

I think it's reasonable to choose `.markdown` and `.md` (almost all text editors support one or other), and `.mdtxt` to ensure compatibility/transition with gedit-markdown.

## Sources ##

- <http://code.google.com/p/ayans/wiki/Readme>
- <http://daringfireball.net/projects/markdown/>
- <http://gae-django-blog.git.sourceforge.net/git/gitweb.cgi?p=gae-django-blog/gae-django-blog;a=tree;h=refs/heads/master;hb=refs/heads/master>
- <http://jblevins.org/projects/markdown-mode/>
- <http://michelf.com/projets/php-markdown/>
- <https://fedorahosted.org/deploymentguide/wiki/EditingInMarkdown>
- <https://github.com/asb/lua-discount/>
- <https://github.com/bobtfish/text-markdown>
- <https://github.com/fletcher/peg-multimarkdown>
- <https://github.com/github/markup/blob/master/lib/github/markups.rb>
- <https://github.com/jgm/lunamark>
- <https://github.com/jgm/peg-markdown>
- <https://github.com/lunant/pandoku>
- <https://github.com/mislav/bluecloth/>
- <https://github.com/myabc/markdownj>
- <https://github.com/nex3/maruku>
- <https://github.com/rtomayko/rdiscount/>
- <https://github.com/rtomayko/rpeg-markdown/>
- <https://github.com/sirthias/pegdown>
- <https://github.com/thomsmits/markdown_npp>
- <https://github.com/trentm/python-markdown2>
- <http://six.pairlist.net/pipermail/markdown-discuss/2006-October/thread.html>
- <http://six.pairlist.net/pipermail/markdown-discuss/2010-November/thread.html>
- <https://sourceforge.net/projects/markout/>
- <http://www.dyeager.org/post/2008/06/markdown-color-syntax-highlighting-kate>
- <http://www.freewisdom.org/projects/python-markdown/>
- <http://www.jpfleury.net/logiciels/gedit-markdown.php>
- <http://www.red-sweater.com/forums/discussion/comment/1034/#Comment_1034>
- <http://www.vim.org/scripts/script.php?script_id=2389>
- <http://www.winterwell.com/software/markdown-editor.php>
- <http://xbeta.org/wiki/show/Markdown>
Comment 7 Jean-Philippe Fleury 2011-05-15 19:39:50 UTC
Created attachment 187864 [details]
Sample Markdown file for testing syntax highlighting
Comment 8 Jean-Philippe Fleury 2011-05-23 15:50:07 UTC
Created attachment 188392 [details]
Markdown language definition based on the 2.0 spec

License updating.
Comment 9 Jean-Philippe Fleury 2011-05-24 20:21:29 UTC
Created attachment 188519 [details]
Markdown language definition based on the 2.0 spec

Fixes line break highlighting.
Comment 10 Jean-Philippe Fleury 2011-06-23 02:42:19 UTC
Created attachment 190487 [details]
Markdown language definition based on the 2.0 spec

Fixes little bugs and updates some highlighting contexts.
Comment 11 Carnë Draug 2011-06-23 14:34:05 UTC
I noticed you use a regex for e-mail address. Why not using the one on def.lang? If there's a problem with that one, maybe it should be fixed there instead. I can see they are already different.

def.lang:
 - allows an optional mailto:
 - allows [_.+-] on the domain

markdown.lang
 - allows an % on the name
 - only allows [-a-z0-9] on the first part of the domain and only [a-z] on the last one
Comment 12 Jean-Philippe Fleury 2011-06-26 13:55:47 UTC
Created attachment 190696 [details]
Markdown language definition based on the 2.0 spec

(In reply to comment #11)
> I noticed you use a regex for e-mail address. Why not using the one on
> def.lang?

The main reason is that I wanted to ensure it's not highlighted if it's not recognized as a link during convertion in HTML. For example, the address <an@example> is highlighted by the regex in def.lang, but is not recognized as a link by Markdown.pl (you can test online: <http://daringfireball.net/projects/markdown/dingus>).

About the optional "mailto:", it's an oversight. Also, I've just found that my regex used in markdown.lang is OK with PHP Markdown and Python Markdown, but not with the original Markdown implementation in Perl. I fixed that.
Comment 13 Jean-Philippe Fleury 2011-06-26 14:01:16 UTC
(In reply to comment #6)
> For Markdown file extension, I chose "*.markdown;*.md;*.mdtxt". Here's why:

About Markdown file extensions, the discussion continued on the FreeDesktop bug tracker:

https://bugs.freedesktop.org/show_bug.cgi?id=27441

Support for Markdown was committed on `shared-mime-info` for extensions `.md`, `.mkd` and `.markdown`, so I adjusted my Markdown language definition to be compliant with the specification.
Comment 14 Ignacio Casal Quinteiro (nacho) 2011-06-26 18:00:31 UTC
You sure about not using the spell-check class in the main context?
Comment 15 Jean-Philippe Fleury 2011-06-26 18:05:50 UTC
(In reply to comment #14)
> You sure about not using the spell-check class in the main context?

What do you mean by "main" context?
Comment 16 Carnë Draug 2011-06-26 18:09:33 UTC
(In reply to comment #15)
> (In reply to comment #14)
> > You sure about not using the spell-check class in the main context?
> 
> What do you mean by "main" context?

He means the context with the id "markdown". The one at the end, with same id as the language name where all other contexts are in. This one

    <context id="markdown">
      <include>
        <context ref="markdown-syntax"/>
        <!-- Note: even if it's highlighted, Markdown syntax within HTML blocks
             (e.g., `<div>`) is not processed. -->
        <context ref="html:html"/>
      </include>
    </context>
Comment 17 Jean-Philippe Fleury 2011-06-26 18:26:28 UTC
(In reply to comment #16)
> He means the context with the id "markdown".

OK, thanks.

I put `class="no-spell-check"` in contexts that don't need spell check. Should I do the opposite and put `class="no-spell-check"` for the main context and then put `class-disabled="no-spell-check"` for contexts needing spell check?

I don't know what's the best practice between both, but since Markdown is, IMHO, primarily text, not code, I think it's no so irrelevant to only disable spell check when it's needed. HTML language file does it this way.
Comment 18 Ignacio Casal Quinteiro (nacho) 2011-06-26 21:49:55 UTC
Ah! ok, if it is mainly text it makes sense to me then. Let's remove the mimetype comment about the freedesktop bug, if it is committed everything is fine and no need to add that comment.
Comment 19 Jean-Philippe Fleury 2011-06-26 22:09:44 UTC
Created attachment 190717 [details]
Markdown language definition based on the 2.0 spec

(In reply to comment #18)
> Let's remove the mimetype comment about the freedesktop bug, if it is
> committed everything is fine and no need to add that comment.

Done.
Comment 20 Ignacio Casal Quinteiro (nacho) 2011-07-03 19:28:38 UTC
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.