-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4de672b
Showing
10 changed files
with
2,554 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>beforeRunningCommand</key> | ||
<string>saveActiveFile</string> | ||
<key>command</key> | ||
<string>#!/usr/bin/env ruby -s | ||
require 'erb' | ||
def markdown_text (text) | ||
text.gsub(/`(.*?)`/, '<code>\1</code>') | ||
end | ||
def make_id (text) | ||
text = text.gsub(/`(.*?)`/, '\1') | ||
text.gsub!(/[- \/_]+/, '_') | ||
text.gsub!(/[^a-zA-Z0-9_]+/, '') | ||
text.downcase | ||
end | ||
Dir.chdir(ENV['TM_PROJECT_DIRECTORY']) | ||
$toc = [ "<h1>Table of Contents</h1>" ] | ||
$chapters = [ ] | ||
$toc_template = "templates/toc.rhtml" if $toc_template.nil? | ||
$chapter_template = "templates/chapter.rhtml" if $chapter_template.nil? | ||
$all_template = "templates/all.rhtml" if $all_template.nil? | ||
$output_dir = "html" if $output_dir.nil? | ||
files = Dir.entries("pages").sort.grep(/.*\.markdown/) | ||
files.each_with_index do |file, i| | ||
def html_link (markdown_file) | ||
markdown_file.sub(/^(?:\d+ )?(.*?)\.markdown$/, '\1.html') | ||
end | ||
puts "• Convert #{file}…" | ||
$page_toc = [ ] | ||
IO.popen('"' + ENV['TM_BUNDLE_SUPPORT'] + '/bin/MultiMarkdown.pl"| "' + ENV['TM_SUPPORT_PATH'] + '/bin/SmartyPants.pl"| "' + ENV['TM_BUNDLE_SUPPORT'] + '"/add_image_size.rb', "r+") do |f| | ||
Thread.fork do | ||
heading_stack = [ i ] | ||
lastlevel = 0; | ||
File.open("pages/#{file}").each_line do |line| | ||
if(m = line.match(/^(#+)\s+(.*)$/)) | ||
level = m[1].length | ||
title = m[2] | ||
if heading_stack.length < level | ||
heading_stack.push(0) | ||
# $toc.push("<ol>") | ||
else | ||
while heading_stack.length > level | ||
heading_stack.pop | ||
# $toc.push("</ol>") | ||
end | ||
end | ||
heading_stack.push(heading_stack.pop + 1) | ||
prefix = heading_stack.join(".") | ||
puts(" #{prefix} #{title}") | ||
toc_entry = "#{"<ul><li>" if(level > lastlevel)}#{"</li><li>" if(level == lastlevel)}#{"</li></ul>" * (lastlevel - level) if(level < lastlevel)}<span class='toc_number'>#{prefix}</span><a href='#{html_link file}##{make_id title}'>#{markdown_text title}</a>"; | ||
$toc.push(toc_entry) | ||
$page_toc.push(toc_entry) | ||
f.write("#{m[1]} <span id='#{make_id title}'>#{prefix}</span> #{title}") | ||
lastlevel = level; | ||
else | ||
f.write(line) | ||
end | ||
end | ||
lastlevel.times {$page_toc.push("</li></ul>")} | ||
begin | ||
f.write("\n"+File.open("markdown.references").read) | ||
rescue | ||
end | ||
f.close_write | ||
lastlevel.times {$toc.push("</li></ul>")} | ||
# heading_stack.length.times { $toc.push("</ol>") } | ||
end | ||
$page = { :title => %x{ grep '^#' 'pages/#{file}'|head -n1 }.sub(/^#+\s+(.*)\n/, '\1'), :content => f.read, :name => "chapter", :page_toc => $page_toc.join("\n") } | ||
$prev = i > 0 ? { :link => "#{html_link files[i-1]}", :title => markdown_text(%x{ grep '^#' 'pages/#{files[i-1]}'|head -n1 }.sub(/^#+\s+(.*)\n/, '\1')) } : nil | ||
$next = i + 1 < files.length ? { :link => "#{html_link files[i+1]}", :title => markdown_text(%x{ grep '^#' 'pages/#{files[i+1]}'|head -n1 }.sub(/^#+\s+(.*)\n/, '\1')) } : nil | ||
File.open("#{$output_dir}/#{html_link file}", "w") do |f| | ||
f.write(ERB.new(File.open($chapter_template), 0, '<>').result) | ||
end | ||
$chapters.push($page) | ||
end | ||
end | ||
$alltoc = { :toc => $toc.join("\n") } | ||
File.open("#{$output_dir}/all_pages.html", "w") do |f| | ||
f.write(ERB.new(File.open($all_template), 0, '<>').result) | ||
end | ||
File.open("#{$output_dir}/index.html", "w") do |f| | ||
$page = { :content => $toc.join("\n"), :name => "toc", :title => "Table of Contents" } | ||
f.write(ERB.new(File.open($toc_template), 0, '<>').result) | ||
end | ||
</string> | ||
<key>input</key> | ||
<string>none</string> | ||
<key>keyEquivalent</key> | ||
<string>^G</string> | ||
<key>name</key> | ||
<string>Generate</string> | ||
<key>output</key> | ||
<string>showAsTooltip</string> | ||
<key>scope</key> | ||
<string>text.html.markdown</string> | ||
<key>uuid</key> | ||
<string>C445442D-06BF-4CEE-A642-6209B84632A6</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>beforeRunningCommand</key> | ||
<string>nop</string> | ||
<key>command</key> | ||
<string>open "$TM_PROJECT_DIRECTORY/html/index.html"</string> | ||
<key>input</key> | ||
<string>none</string> | ||
<key>keyEquivalent</key> | ||
<string>^O</string> | ||
<key>name</key> | ||
<string>Open Generated Files</string> | ||
<key>output</key> | ||
<string>discard</string> | ||
<key>scope</key> | ||
<string>text.html.markdown</string> | ||
<key>uuid</key> | ||
<string>B3AF90C8-A1B0-4583-A5E4-74374B68B015</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>beforeRunningCommand</key> | ||
<string>nop</string> | ||
<key>command</key> | ||
<string>. "$TM_SUPPORT_PATH/lib/webpreview.sh" | ||
html_header "Markdown2Book Help file" "Markdown2Book" | ||
Markdown.pl "$TM_BUNDLE_SUPPORT/help.markdown"|SmartyPants.pl | ||
html_footer</string> | ||
<key>input</key> | ||
<string>none</string> | ||
<key>name</key> | ||
<string>Readme</string> | ||
<key>output</key> | ||
<string>showAsHTML</string> | ||
<key>uuid</key> | ||
<string>B9B57AA0-0024-41F6-B6AE-C60FCDC1E8B1</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>beforeRunningCommand</key> | ||
<string>nop</string> | ||
<key>command</key> | ||
<string>res=$(CocoaDialog dropdown --text "References" --items `cat "$TM_PROJECT_DIRECTORY/markdown.references"|sed 's/ /_/'` --button1 "Insert") | ||
[[ $(head -n1 <<<"$res") == "2" ]] && exit_discard | ||
res=$(tail -n1 <<<"$res") | ||
let "res += 2" | ||
res=$(head -n "$res" "$TM_PROJECT_DIRECTORY/markdown.references" |tail -n 1) | ||
res=$(sed 's/\[\(.*\)\].*/[${1:Reference text}][\1]/'<<<"$res") | ||
echo -n "$res"</string> | ||
<key>input</key> | ||
<string>none</string> | ||
<key>keyEquivalent</key> | ||
<string>^l</string> | ||
<key>name</key> | ||
<string>Show References</string> | ||
<key>output</key> | ||
<string>insertAsSnippet</string> | ||
<key>scope</key> | ||
<string>text.html.markdown</string> | ||
<key>uuid</key> | ||
<string>3E0EDBF3-2018-46EA-95EE-C4EB20118789</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>beforeRunningCommand</key> | ||
<string>nop</string> | ||
<key>command</key> | ||
<string>#!/bin/bash | ||
cd "$TM_PROJECT_DIRECTORY" | ||
if [ ! -f "markdown.references" ]; then touch "markdown.references"; fi | ||
all_refs=$(grep -ho '\[[^]]*\]\[[^]]*\]' pages/*.markdown|perl -pe 's/.*\[(.*)\]$/$1/'|sort|uniq) | ||
known_refs=$(grep '^\[.*\]' markdown.references|perl -pe 's/^\[(.*?)\].*/$1/') | ||
all_ptrn=$(tr <<<"$all_refs" '\n' '|') | ||
known_ptrn=$(tr <<<"$known_refs" '\n' '|') | ||
all_ptrn="${all_ptrn:0:${#all_ptrn}-1}" | ||
known_ptrn="${known_ptrn:0:${#known_ptrn}-1}" | ||
echo -e "Missing:\n" | ||
grep -Ev <<<"$all_refs" "^($known_ptrn)$"|perl -pe 's/.*/[$&]: MISSING/'|tee -a markdown.references | ||
echo -e "\nRedundant:\n" | ||
grep -Ev <<<"$known_refs" "^($all_ptrn)$" | ||
</string> | ||
<key>input</key> | ||
<string>none</string> | ||
<key>keyEquivalent</key> | ||
<string>^U</string> | ||
<key>name</key> | ||
<string>Update References</string> | ||
<key>output</key> | ||
<string>showAsTooltip</string> | ||
<key>scope</key> | ||
<string>text</string> | ||
<key>uuid</key> | ||
<string>749EA16A-700B-43B3-9457-FA12D8301CAE</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This TextMate bundle is for compiling a Documentation project made of several Markdown files to HTML. It generates a TOC, a print version with all chapters on one page and HTML files for each chapter. You can use references to easily link between your pages. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env ruby | ||
|
||
STDIN.each_line do |line| | ||
line.gsub!(/<img(?![^>]*?(?:width|height)=)[^>*]src="(.*?)"/) do |tag| | ||
size = %x(sips -g pixelWidth -g pixelHeight "#{$1}") | ||
size.gsub(/pixel(Width|Height): (\d+)/) { |str| tag += " #{$1.downcase}=\"#{$2}\"" } | ||
# use the next line to change the image path | ||
# tag.gsub(/src="([^"]+)"/, 'src="http://yoursite.com/path/to/images/\1"') | ||
tag.gsub(/src="([^"]+)"/, 'src="\1"') | ||
end | ||
print line | ||
end |
Oops, something went wrong.