Skip to content

Commit d3b3e58

Browse files
committed
Initial commit
0 parents  commit d3b3e58

16 files changed

+486
-0
lines changed

Commands/Preview.tmCommand

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>beforeRunningCommand</key>
6+
<string>saveActiveFile</string>
7+
<key>command</key>
8+
<string>#!/usr/bin/env bash
9+
[[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] &amp;&amp; . "${TM_SUPPORT_PATH}/lib/bash_init.sh"
10+
11+
. "$TM_SUPPORT_PATH/lib/webpreview.sh"
12+
html_header "Markdown (GitHub) Preview" "${TM_FILENAME:-}"
13+
14+
if [[ -f "$TM_FILEPATH" ]]; then
15+
echo "&lt;base href='file://${TM_FILEPATH// /%20}'&gt;"
16+
fi
17+
18+
# Convert to html then make one of the html tags above caret
19+
# into a link that we scroll down to
20+
"${TM_MARKDOWN:-redcarpet.rb}"|ruby -wU -e '
21+
lines = STDIN.read.split("\n")
22+
n = [ENV["TM_LINE_NUMBER"].to_i, lines.length].min - 7
23+
24+
while n &gt; 0 &amp;&amp; !lines[n].match(/&lt;(h\d|p|ul|li|blockquote|pre|div|img|code|table|tr)&gt;/i)
25+
n -= 1
26+
end
27+
28+
if n &gt; 0 &amp;&amp; m = lines[n].match(/&lt;(h\d|p|ul|li|blockquote|pre|div|img|code|table|tr)&gt;(.*)$/i)
29+
lines[n] = "&lt;#{m[1]} id=\"scroll_to_here\" &gt;#{m[2]}"
30+
end
31+
32+
puts lines.join("\n")
33+
puts "\n&lt;script&gt;window.location.hash = \"scroll_to_here\";&lt;/script&gt;"
34+
'
35+
html_footer</string>
36+
<key>input</key>
37+
<string>document</string>
38+
<key>inputFormat</key>
39+
<string>text</string>
40+
<key>keyEquivalent</key>
41+
<string>^~@m</string>
42+
<key>name</key>
43+
<string>Preview</string>
44+
<key>outputCaret</key>
45+
<string>afterOutput</string>
46+
<key>outputFormat</key>
47+
<string>html</string>
48+
<key>outputLocation</key>
49+
<string>newWindow</string>
50+
<key>scope</key>
51+
<string>text.html.markdown</string>
52+
<key>uuid</key>
53+
<string>E7A435B2-F6D1-487E-B5F0-AE90F0592A68</string>
54+
<key>version</key>
55+
<integer>2</integer>
56+
</dict>
57+
</plist>

LICENSE.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (C) 2015 by Mike McQuaid
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Font Name and Size</string>
7+
<key>scope</key>
8+
<string>text.html.markdown</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>fontName</key>
12+
<string>Helvetica</string>
13+
<key>fontSize</key>
14+
<string>1.1em</string>
15+
</dict>
16+
<key>uuid</key>
17+
<string>FB5AC213-8C29-425A-8134-FD731C66A16E</string>
18+
</dict>
19+
</plist>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Heading 1 Font Size</string>
7+
<key>scope</key>
8+
<string>markup.heading.1.markdown</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>fontSize</key>
12+
<string>2em</string>
13+
</dict>
14+
<key>uuid</key>
15+
<string>C2E34B3B-7672-4080-837B-39C639840707</string>
16+
</dict>
17+
</plist>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Heading 2 Font Size</string>
7+
<key>scope</key>
8+
<string>markup.heading.2.markdown</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>fontSize</key>
12+
<string>1.5em</string>
13+
</dict>
14+
<key>uuid</key>
15+
<string>6B09CADC-EC58-453D-B9B3-ED30CE26CCF8</string>
16+
</dict>
17+
</plist>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Heading 3 Font Size</string>
7+
<key>scope</key>
8+
<string>markup.heading.3.markdown</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>fontSize</key>
12+
<string>1.17em</string>
13+
</dict>
14+
<key>uuid</key>
15+
<string>974C7F72-3026-4FCE-B101-AEA9678F48B9</string>
16+
</dict>
17+
</plist>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Heading 4 Font Size</string>
7+
<key>scope</key>
8+
<string>markup.heading.4.markdown</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>fontSize</key>
12+
<string>1em</string>
13+
</dict>
14+
<key>uuid</key>
15+
<string>519EA1C8-558F-4B3D-97C0-71988FA779FD</string>
16+
</dict>
17+
</plist>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Heading 5 Font Size</string>
7+
<key>scope</key>
8+
<string>markup.heading.5.markdown</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>fontSize</key>
12+
<string>0.83em</string>
13+
</dict>
14+
<key>uuid</key>
15+
<string>B24F3166-6D7E-464A-9E19-A63B2BB5B4EA</string>
16+
</dict>
17+
</plist>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Heading 6 Font Size</string>
7+
<key>scope</key>
8+
<string>markup.heading.6.markdown</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>fontSize</key>
12+
<string>0.67em</string>
13+
</dict>
14+
<key>uuid</key>
15+
<string>B0F3AEF3-78DD-46E1-8736-23C9668D5690</string>
16+
</dict>
17+
</plist>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Headings Font Name Inherited</string>
7+
<key>scope</key>
8+
<string>entity.name.section.markdown</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>fontName</key>
12+
<string>inherit</string>
13+
</dict>
14+
<key>uuid</key>
15+
<string>25ACF9C8-C803-4B2A-A236-08563C3C0AEA</string>
16+
</dict>
17+
</plist>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Headings Hash Font Size</string>
7+
<key>scope</key>
8+
<string>punctuation.definition.heading.markdown</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>fontSize</key>
12+
<string>1em</string>
13+
</dict>
14+
<key>uuid</key>
15+
<string>3C768C7F-41E8-4E64-A067-61F227828371</string>
16+
</dict>
17+
</plist>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Raw Background Colour and Font Size</string>
7+
<key>scope</key>
8+
<string>markup.raw.block, markup.raw, meta.raw.block, markup.raw.inline</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>background</key>
12+
<string>#f0f0f0</string>
13+
<key>fontName</key>
14+
<string>inherit</string>
15+
<key>fontSize</key>
16+
<string>95%</string>
17+
</dict>
18+
<key>uuid</key>
19+
<string>0A70B5FF-6962-41BF-945E-D0FFFD819F59</string>
20+
</dict>
21+
</plist>

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# GitHub-Markdown.tmbundle
2+
Provides some [GitHub Flavoured Markdown](https://help.github.com/articles/github-flavored-markdown/) extensions for TextMate to make working with GitHub Flavoured Markdown nicer.
3+
4+
## Features
5+
- Add a new "Preview" command using [Redcarpet](https://github.com/vmg/redcarpet) to render GitHub Flavoured Markdown
6+
- Use Helvetica for the Markdown editor font and make it match the preview size
7+
- Render all Markdown editor headings the same relative size as in the preview
8+
- Use the default font (i.e. Helvetica) for the Markdown editor settings
9+
- Use the default font size for the Markdown editor hash/pound prefix
10+
- Set a grey background colour and reduce the size of the monospaced text in the Markdown editor
11+
- Support triple-backtick raw blocks and support syntax highlighting for Ruby and Shell (others can be added trivially)
12+
13+
## Installation
14+
### TextMate 2
15+
```bash
16+
mkdir -p ~/Library/Application\ Support/Avian/Bundles
17+
cd ~/Library/Application\ Support/Avian/Bundles
18+
git clone https://github.com/mikemcquaid/GitHub-Markdown.tmbundle
19+
```
20+
21+
### TextMate 1
22+
```bash
23+
mkdir -p ~/Library/Application\ Support/TextMate/Bundles
24+
cd ~/Library/Application\ Support/TextMate/Bundles
25+
git clone https://github.com/mikemcquaid/GitHub-Markdown.tmbundle
26+
osascript -e 'tell app "TextMate" to reload bundles'
27+
```
28+
29+
## Status
30+
The above features are tested and working for my day-to-day.
31+
32+
Tested using TextMate 2. May work in TextMate 1 or Sublime Text; I've no idea.
33+
34+
[Patches welcome](https://github.com/mikemcquaid/GitHub-Markdown.tmbundle/pulls).
35+
36+
## Contact
37+
[Mike McQuaid](mailto:[email protected])
38+
39+
## License
40+
GitHub-Markdown.tmbundle is licensed under the [MIT License](http://en.wikipedia.org/wiki/MIT_License). The full license text is
41+
available in
42+
[LICENSE.txt](https://github.com/mikemcquaid/GitHub-Markdown.tmbundle/blob/master/LICENSE.txt).

Support/bin/redcarpet.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby
2+
# Usage: markdown-github.rb [<file>...]
3+
# Convert one or more GitHub Flavored Markdown files to HTML and print to
4+
# standard output. With no <file> or when <file> is "-", read GitHub Flavored
5+
# Markdown source text from standard input.
6+
7+
if ARGV.include?("--help")
8+
File.read(__FILE__).split("\n").grep(/^# /).each do |line|
9+
puts line[2..-1]
10+
end
11+
exit 0
12+
end
13+
14+
require "rubygems"
15+
16+
begin
17+
require "redcarpet"
18+
require "pygments"
19+
rescue LoadError
20+
puts <<-EOS
21+
<p>Please install the Redcarpet and Pygments.rb RubyGems by running the following:</p>
22+
23+
<pre><code>/usr/bin/gem install --user redcarpet pygments.rb</code></pre>
24+
EOS
25+
exit 0
26+
end
27+
28+
class PygmentsSmartyHTML < Redcarpet::Render::HTML
29+
include Redcarpet::Render::SmartyPants
30+
31+
def block_code(code, language)
32+
language ||= "text"
33+
Pygments.highlight(code, :lexer => language)
34+
rescue
35+
Pygments.highlight(code, :lexer => "text")
36+
end
37+
end
38+
39+
def markdown(text)
40+
options = {
41+
:filter_html => true,
42+
:safe_links_only => true,
43+
:with_toc_data => true,
44+
:hard_wrap => true,
45+
}
46+
renderer = PygmentsSmartyHTML.new(options)
47+
extensions = {
48+
:no_intra_emphasis => true,
49+
:tables => true,
50+
:fenced_code_blocks => true,
51+
:autolink => true,
52+
:strikethrough => true,
53+
:space_after_headers => true,
54+
}
55+
Redcarpet::Markdown.new(renderer, extensions).render(text)
56+
end
57+
58+
puts "<style>#{Pygments.css(:style => "colorful")}</style>"
59+
puts markdown(ARGF.read)

0 commit comments

Comments
 (0)