Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlighting Github README.md format in Sublime Text 2

I have got README file and I want Sublime to highlight only some pieces of code idented by some "tag", for example:

Here is an example of usage

# This should be highlighted
```ruby
  superhero = Superhero.new
  superhero.make_world_better
```

or with [code lang=ruby] or whatever

like image 517
fl00r Avatar asked Jul 18 '12 09:07

fl00r


People also ask

Does sublime support Markdown?

Freshly installed, Sublime Text doesn't offer any specific Markdown support—no syntax highlighting, no special italic or bold formatting, no keyboard shortcuts, and no HTML preview or output.


2 Answers

Lazy answer

(for independent fast learners)

  1. Install package control for sublime-text.
  2. Once you restarted sublime-text, see "Fast Answer".

Fast answer

(for intermediate to advanced sublime-text users)

  1. Ctrl+Shift+P and Package Control: Install Package, then install Knockdown.

    That's it, now you have a Set Syntax: Markdown (Github flavored) option right at the reach of your fingertips.


Elaborate answer

(powerless to powerfull)

- Installing Package Control

  1. Open sublime-text.
    [If you need this functionality available when you edit files on a directory owned by root or www-data ( i.e. /var/www/ ) you may want to open sublime with admin privileges using gksu sublime or similar and repeat every step]

  2. Activate sublime's console by pressing ctr+`
    [That is CONTROL key plus GRAVE ACCENT key (usually above the TAB key)]

enter image description here

  1. Copy-paste one of the following options to sublime console's prompt. (and press enter):

    If sublime-text 2:

    import urllib2,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler()) ); by = urllib2.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); open( os.path.join( ipp, pf), 'wb' ).write(by) if dh == h else None; print('Error validating download (got %s instead of %s), please try manual install' % (dh, h) if dh != h else 'Please restart Sublime Text to finish installation')
    

    If sublime-text 3:

    import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)
    

enter image description here

  1. Close sublime when the console prints back a message saying "Please restart Sublime Text to finish installation" (usually almost instantaneous). Open sublime-text again.

  2. Once you restarted sublime-text, the rest is easy, see "Fast Answer" (above), or read on.

About using Package Control

What you just installed adds a new bunch of commands to your Palette and opens the door to a wonderful world of community contributed plugins; a way to extend sublime's functionality by other people or by yourself! (share your code!).
Now lets use it to install knockdown.

  1. You can access Package Controll simply by pressing ctr+shift+P, and typing Package Control, pc, pack (or anything similar thanks to the fuzzy search feature of the command palette), in this case search the right command by writing Package Control: Install Package (or just pi).
    (If something goes wrong you can always Remove Package).

enter image description here

  1. To see all the available packages just enter or click on it. Sublime will search for all the registered packages and will even check and show for you only the ones that are compatible with your version of sublime-text, you'll have to wait a few seconds.
    (or less than a second, depending on your internet+computer latency+speed).

enter image description here

  1. Now search for and select knockdown.

enter image description here

  1. After you hit Enter or click on it it will take a brief moment to install.

enter image description here

That's it, it just works.


## - How to use it you ask?

To activate this highlighting in the current loaded buffer:

(lets say "the open file")

  1. Inside sublime-text and with a .md file opened, press ctr+shift+P again.
  2. Search for Set Syntax: Markdown (Github Flavored) and enter or click on it. enter image description here

IF you want to activate for all .md files (that's a big IF)

On current version (Latest Sublime Text 2 releases & any ver 3 release):
  • Navigate through the following menus: View -> Syntax -> Open all with current extension as... ->[your syntax choice].
On previous versions of sublime:
  • Go to a Packages/User, create (or edit) a .sublime-settings file named after the Syntax where you want to add the extensions, Markdown (Github Flavored).sublime-settings in your case, then write there something like this:
    {
        "extensions":
        [
            "md"
        ]
    }
 

And then restart Sublime Text

... pics, else it shant have come to pass:

(it totally works! here's the evidence)enter image description here

presto!
You just took one further step to be a sublime-text master, I hope my answer helped you

like image 72
JorgeArtware Avatar answered Oct 02 '22 14:10

JorgeArtware


Your example is describing Markdown structured text

Try

1) Save file with .md extension

2) View -> Syntax -> Open all with current extension -> Markdown

like image 43
Mikko Ohtamaa Avatar answered Oct 02 '22 13:10

Mikko Ohtamaa