mcbean 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.autotest +23 -0
- data/CHANGELOG.rdoc +6 -0
- data/History.txt +6 -0
- data/Manifest.txt +13 -0
- data/README.rdoc +69 -0
- data/Rakefile +49 -0
- data/bin/mcbean +3 -0
- data/lib/mcbean.rb +28 -0
- data/lib/mcbean/markdown.rb +90 -0
- data/markdown-syntax.html +1081 -0
- data/test/helper.rb +6 -0
- data/test/test_markdown.rb +111 -0
- data/test/test_mcbean.rb +17 -0
- metadata +178 -0
- metadata.gz.sig +1 -0
data.tar.gz.sig
ADDED
Binary file
|
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/CHANGELOG.rdoc
ADDED
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
= McBean
|
2
|
+
|
3
|
+
* http://github.com/flavorjones/mcbean
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
"You can't teach a Sneetch."
|
8
|
+
|
9
|
+
McBean transforms HTML into Markdown with the help of Loofah and Nokogiri.
|
10
|
+
|
11
|
+
Its goal is to eventually be able to transform (with the help of other
|
12
|
+
relevant gems) documents from HTML to Markdown to Textile, and
|
13
|
+
anything in between. It will be the Sylvester McMonkey McBean of
|
14
|
+
markup, placing stars onto the bellies of all kinds of document
|
15
|
+
formats.
|
16
|
+
|
17
|
+
== FEATURES/PROBLEMS:
|
18
|
+
|
19
|
+
* Transforms HTML into Markdown.
|
20
|
+
* Doesn't do anything else yet.
|
21
|
+
|
22
|
+
== SYNOPSIS:
|
23
|
+
|
24
|
+
If you have an HTML fragment:
|
25
|
+
|
26
|
+
McBean.fragment(your_html_string).to_markdown
|
27
|
+
|
28
|
+
Or if you have an HTML document:
|
29
|
+
|
30
|
+
McBean.document(your_html_string).to_markdown
|
31
|
+
|
32
|
+
=== Side Note: Fragments vs Documents
|
33
|
+
|
34
|
+
Generally speaking, if you expect to have a DOCTYPE and a single root
|
35
|
+
\<html\> node, you have a *document*. If you don't expect to
|
36
|
+
have a single root node, you have a *fragment*.
|
37
|
+
|
38
|
+
== REQUIREMENTS:
|
39
|
+
|
40
|
+
* Loofah 0.4.7 (and thusly Nokogiri)
|
41
|
+
|
42
|
+
== INSTALL:
|
43
|
+
|
44
|
+
* sudo gem install mcbean
|
45
|
+
|
46
|
+
== LICENSE:
|
47
|
+
|
48
|
+
(The MIT License)
|
49
|
+
|
50
|
+
Copyright (c) 2010 Mike Dalessio
|
51
|
+
|
52
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
53
|
+
a copy of this software and associated documentation files (the
|
54
|
+
'Software'), to deal in the Software without restriction, including
|
55
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
56
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
57
|
+
permit persons to whom the Software is furnished to do so, subject to
|
58
|
+
the following conditions:
|
59
|
+
|
60
|
+
The above copyright notice and this permission notice shall be
|
61
|
+
included in all copies or substantial portions of the Software.
|
62
|
+
|
63
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
64
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
65
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
66
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
67
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
68
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
69
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
gem 'hoe', '>= 2.5.0'
|
5
|
+
require 'hoe'
|
6
|
+
|
7
|
+
Hoe.plugin :git
|
8
|
+
|
9
|
+
Hoe.spec 'mcbean' do
|
10
|
+
developer "Mike Dalessio", "mike.dalessio@gmail.com"
|
11
|
+
|
12
|
+
self.extra_rdoc_files = FileList["*.rdoc"]
|
13
|
+
self.history_file = "CHANGELOG.rdoc"
|
14
|
+
self.readme_file = "README.rdoc"
|
15
|
+
|
16
|
+
extra_deps << ["loofah", ">= 0.4.7"]
|
17
|
+
extra_dev_deps << ["shoulda", ">= 2.10"]
|
18
|
+
end
|
19
|
+
|
20
|
+
task :redocs => :fix_css
|
21
|
+
task :docs => :fix_css
|
22
|
+
task :fix_css do
|
23
|
+
better_css = <<-EOT
|
24
|
+
.method-description pre {
|
25
|
+
margin : 1em 0 ;
|
26
|
+
}
|
27
|
+
|
28
|
+
.method-description ul {
|
29
|
+
padding : .5em 0 .5em 2em ;
|
30
|
+
}
|
31
|
+
|
32
|
+
.method-description p {
|
33
|
+
margin-top : .5em ;
|
34
|
+
}
|
35
|
+
|
36
|
+
#main ul, div#documentation ul {
|
37
|
+
list-style-type : disc ! IMPORTANT ;
|
38
|
+
list-style-position : inside ! IMPORTANT ;
|
39
|
+
}
|
40
|
+
|
41
|
+
h2 + ul {
|
42
|
+
margin-top : 1em;
|
43
|
+
}
|
44
|
+
EOT
|
45
|
+
puts "* fixing css"
|
46
|
+
File.open("doc/rdoc.css", "a") { |f| f.write better_css }
|
47
|
+
end
|
48
|
+
|
49
|
+
# vim: syntax=ruby
|
data/bin/mcbean
ADDED
data/lib/mcbean.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "loofah"
|
2
|
+
|
3
|
+
class McBean
|
4
|
+
VERSION = "0.1.0"
|
5
|
+
REQUIRED_LOOFAH_VERSION = "0.4.7"
|
6
|
+
|
7
|
+
attr_accessor :html
|
8
|
+
|
9
|
+
def McBean.fragment(string_or_io)
|
10
|
+
mcbean = allocate
|
11
|
+
mcbean.html = Loofah.fragment(string_or_io)
|
12
|
+
mcbean
|
13
|
+
end
|
14
|
+
|
15
|
+
def McBean.document(string_or_io)
|
16
|
+
mcbean = allocate
|
17
|
+
mcbean.html = Loofah.document(string_or_io)
|
18
|
+
mcbean
|
19
|
+
end
|
20
|
+
end
|
21
|
+
Mcbean = McBean
|
22
|
+
|
23
|
+
require "mcbean/markdown"
|
24
|
+
|
25
|
+
if Loofah::VERSION < McBean::REQUIRED_LOOFAH_VERSION
|
26
|
+
raise RuntimeError, "McBean requires Loofah #{McBean::REQUIRED_LOOFAH_VERSION} or later (currently #{Loofah::VERSION})"
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
class McBean
|
2
|
+
|
3
|
+
class Markdownify < Loofah::Scrubber
|
4
|
+
def initialize
|
5
|
+
@direction = :bottom_up
|
6
|
+
@link_references = nil
|
7
|
+
@link_reference_count = 0
|
8
|
+
end
|
9
|
+
|
10
|
+
def scrub(node)
|
11
|
+
return CONTINUE if node.text?
|
12
|
+
replacement_killer = \
|
13
|
+
case node.name
|
14
|
+
when "h1"
|
15
|
+
new_text node, "\n#{node.content}\n==========\n"
|
16
|
+
when "h2"
|
17
|
+
new_text node, "\n#{node.content}\n----------\n"
|
18
|
+
when "h3"
|
19
|
+
new_text node, "\n### #{node.content} ###\n"
|
20
|
+
when "h4"
|
21
|
+
new_text node, "\n#### #{node.content} ####\n"
|
22
|
+
when "blockquote"
|
23
|
+
fragment = node.inner_html
|
24
|
+
fragment.gsub!(/\n(.)/, "\n> \\1")
|
25
|
+
node.document.fragment(fragment)
|
26
|
+
when "li"
|
27
|
+
nil # handled by parent list tag
|
28
|
+
when "ul"
|
29
|
+
fragment = []
|
30
|
+
node.xpath("./li").each do |li|
|
31
|
+
fragment << "* #{li.text}" if li.text =~ /\S/
|
32
|
+
end
|
33
|
+
new_text node, "\n#{fragment.join("\n")}\n"
|
34
|
+
when "ol"
|
35
|
+
fragment = []
|
36
|
+
node.xpath("./li").each_with_index do |li, j|
|
37
|
+
fragment << "#{j+1}. #{li.text}" if li.text =~ /\S/
|
38
|
+
end
|
39
|
+
new_text node, "\n#{fragment.join("\n")}\n"
|
40
|
+
when "code"
|
41
|
+
if node.parent.name == "pre"
|
42
|
+
new_text node, node.content.gsub(/^/," ")
|
43
|
+
else
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
when "a"
|
47
|
+
if node['title']
|
48
|
+
unless @link_references
|
49
|
+
@link_references = node.document.fragment("<div>\n</div>").children.first
|
50
|
+
end_of_doc(node).add_next_sibling @link_references
|
51
|
+
end
|
52
|
+
@link_reference_count += 1
|
53
|
+
key = "#{@link_reference_count}"
|
54
|
+
link = new_text node, "[#{node.text}][#{key}]"
|
55
|
+
ref = new_text node, "[#{key}]: #{node['href']} \"#{node['title']}\"\n"
|
56
|
+
@link_references.add_child ref
|
57
|
+
link
|
58
|
+
else
|
59
|
+
new_text node, "[#{node.text}](#{node['href']})"
|
60
|
+
end
|
61
|
+
else
|
62
|
+
if Loofah::HashedElements::BLOCK_LEVEL[node.name]
|
63
|
+
new_text node, "\n#{node.content}\n"
|
64
|
+
else
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
if replacement_killer
|
69
|
+
node.add_next_sibling replacement_killer
|
70
|
+
node.remove
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def new_text(node, text)
|
77
|
+
Nokogiri::XML::Text.new(text, node.document)
|
78
|
+
end
|
79
|
+
|
80
|
+
def end_of_doc(node)
|
81
|
+
(node.document.serialize_root || node.ancestors.last).children.last
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def to_markdown
|
86
|
+
Loofah::Helpers.remove_extraneous_whitespace \
|
87
|
+
html.dup.scrub!(:prune).scrub!(Markdownify.new).text(:encode_special_chars => false)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
@@ -0,0 +1,1081 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
6
|
+
<title>Daring Fireball: Markdown Syntax Documentation</title>
|
7
|
+
<meta name="viewport" content="width=700, initial-scale=0.70, minimum-scale=0.45" />
|
8
|
+
<link rel="stylesheet" type="text/css" media="screen" href="/css/fireball_screen.css?v1.45" />
|
9
|
+
<link rel="stylesheet" type="text/css" media="screen" href="/css/ie_sucks.php" />
|
10
|
+
<link rel="stylesheet" type="text/css" media="print" href="/css/fireball_print.css?v01" />
|
11
|
+
<link rel="alternate" type="application/atom+xml" href="/index.xml" />
|
12
|
+
<script src="/js/js-global/FancyZoom.js" type="text/javascript"></script>
|
13
|
+
<script src="/js/js-global/FancyZoomHTML.js" type="text/javascript"></script>
|
14
|
+
<style type="text/css">
|
15
|
+
ul + p {
|
16
|
+
margin-top: 2em;
|
17
|
+
}
|
18
|
+
.article h2 {
|
19
|
+
font-family: Georgia;
|
20
|
+
font-size: 14px;
|
21
|
+
text-transform: uppercase;
|
22
|
+
letter-spacing: .25em;
|
23
|
+
margin-bottom: 2.5em;
|
24
|
+
}
|
25
|
+
.article h3 {
|
26
|
+
font-weight: normal;
|
27
|
+
text-transform: uppercase;
|
28
|
+
letter-spacing: .15em;
|
29
|
+
}
|
30
|
+
.article p + h3 {
|
31
|
+
margin-top: 5em;
|
32
|
+
}
|
33
|
+
.article pre + h3 {
|
34
|
+
margin-top: 6em;
|
35
|
+
}
|
36
|
+
</style>
|
37
|
+
<link rel="shortcut icon" href="/favicon.ico" />
|
38
|
+
<script src="/mint/?js" type="text/javascript"></script>
|
39
|
+
</head>
|
40
|
+
<body>
|
41
|
+
<div id="Box">
|
42
|
+
|
43
|
+
<div id="Banner">
|
44
|
+
<a href="/" title="Daring Fireball: Home"><img src="http://10.164.97.137/daringfireball.net/graphics/logos/" alt="Daring Fireball" height="56" /></a>
|
45
|
+
</div>
|
46
|
+
|
47
|
+
<div id="Sidebar">
|
48
|
+
<p>By <strong>John Gruber</strong></p>
|
49
|
+
|
50
|
+
<ul><!--★-->
|
51
|
+
<li><a href="/archive/" title="Previous articles.">Archive</a></li>
|
52
|
+
<!-- <li><a href="/members/shirts" title="Buy some swell t-shirts.">T-Shirts</a></li> -->
|
53
|
+
<li><script type="text/javascript">
|
54
|
+
// <![CDATA[
|
55
|
+
function ReadCookie(name) {
|
56
|
+
var nameEQ = name + "=";
|
57
|
+
var ca = document.cookie.split(';');
|
58
|
+
for(var i=0;i < ca.length;i++) {
|
59
|
+
var c = ca[i];
|
60
|
+
while (c.charAt(0)==' ') c = c.substring(1,c.length);
|
61
|
+
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
|
62
|
+
}
|
63
|
+
return null;
|
64
|
+
}
|
65
|
+
var display_linked_list = ReadCookie('displayLinkedList');
|
66
|
+
var li_linked = '<a href="/linked/" title="The Linked List.">Linked List<\/a>';
|
67
|
+
var li_members = '<a href="/members/" title="Support Daring Fireball with a contribution.">Membership<\/a>';
|
68
|
+
if (display_linked_list == "hide") {
|
69
|
+
// Linked List is off on home page, so show it in menu:
|
70
|
+
document.write(li_linked + "<\/li>\n<li>" + li_members);
|
71
|
+
}
|
72
|
+
else {
|
73
|
+
// Default to not putting separate LL item in sidebar:
|
74
|
+
document.write(li_members);
|
75
|
+
}
|
76
|
+
// ]]>
|
77
|
+
</script></li>
|
78
|
+
<li><a href="/projects/" title="Software projects, including SmartyPants and Markdown.">Projects</a></li>
|
79
|
+
<li><a href="/contact/" title="How to send email regarding Daring Fireball.">Contact</a></li>
|
80
|
+
<li><a href="/colophon/" title="About this site and the tools used to produce it.">Colophon</a></li>
|
81
|
+
<li><a href="/feeds/">RSS Feed</a></li>
|
82
|
+
<li><a href="/feeds/sponsors/">Sponsorship</a></li>
|
83
|
+
</ul>
|
84
|
+
|
85
|
+
<div id="SidebarTheDeck">
|
86
|
+
<script type="text/javascript">
|
87
|
+
//<![CDATA[
|
88
|
+
(function(id) {
|
89
|
+
document.write('<script type="text/javascript" src="' +
|
90
|
+
'http://connect.decknetwork.net/deck' + id + '_js.php?' +
|
91
|
+
(new Date().getTime()) + '"></' + 'script>');
|
92
|
+
})("DF");
|
93
|
+
//]]>
|
94
|
+
</script>
|
95
|
+
<a href="http://decknetwork.net/"><img src="http://10.164.97.135/daringfireball.net/graphics/madison/via_the_deck.png" alt="Ads via The Deck" class="the_deck_promo" /></a>
|
96
|
+
</div>
|
97
|
+
|
98
|
+
|
99
|
+
</div> <!-- Sidebar -->
|
100
|
+
|
101
|
+
|
102
|
+
<div id="Main">
|
103
|
+
|
104
|
+
<div class="article">
|
105
|
+
<h1>Markdown: Syntax</h1>
|
106
|
+
|
107
|
+
<ul id="ProjectSubmenu">
|
108
|
+
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
|
109
|
+
<li><a href="/projects/markdown/basics" title="Markdown Basics">Basics</a></li>
|
110
|
+
<li><a class="selected" title="Markdown Syntax Documentation">Syntax</a></li>
|
111
|
+
<li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
|
112
|
+
<li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
|
113
|
+
</ul>
|
114
|
+
|
115
|
+
<ul>
|
116
|
+
<li><a href="#overview">Overview</a>
|
117
|
+
<ul><li><a href="#philosophy">Philosophy</a></li>
|
118
|
+
<li><a href="#html">Inline HTML</a></li>
|
119
|
+
<li><a href="#autoescape">Automatic Escaping for Special Characters</a></li></ul></li>
|
120
|
+
<li><a href="#block">Block Elements</a>
|
121
|
+
<ul><li><a href="#p">Paragraphs and Line Breaks</a></li>
|
122
|
+
<li><a href="#header">Headers</a></li>
|
123
|
+
<li><a href="#blockquote">Blockquotes</a></li>
|
124
|
+
<li><a href="#list">Lists</a></li>
|
125
|
+
<li><a href="#precode">Code Blocks</a></li>
|
126
|
+
<li><a href="#hr">Horizontal Rules</a></li></ul></li>
|
127
|
+
<li><a href="#span">Span Elements</a>
|
128
|
+
<ul><li><a href="#link">Links</a></li>
|
129
|
+
<li><a href="#em">Emphasis</a></li>
|
130
|
+
<li><a href="#code">Code</a></li>
|
131
|
+
<li><a href="#img">Images</a></li></ul></li>
|
132
|
+
<li><a href="#misc">Miscellaneous</a>
|
133
|
+
<ul><li><a href="#backslash">Backslash Escapes</a></li>
|
134
|
+
<li><a href="#autolink">Automatic Links</a></li></ul></li>
|
135
|
+
</ul>
|
136
|
+
|
137
|
+
<p><strong>Note:</strong> This document is itself written using Markdown; you
|
138
|
+
can <a href="/projects/markdown/syntax.text">see the source for it by adding ‘.text’ to the URL</a>.</p>
|
139
|
+
|
140
|
+
<hr />
|
141
|
+
|
142
|
+
<h2 id="overview">Overview</h2>
|
143
|
+
|
144
|
+
<h3 id="philosophy">Philosophy</h3>
|
145
|
+
|
146
|
+
<p>Markdown is intended to be as easy-to-read and easy-to-write as is feasible.</p>
|
147
|
+
|
148
|
+
<p>Readability, however, is emphasized above all else. A Markdown-formatted
|
149
|
+
document should be publishable as-is, as plain text, without looking
|
150
|
+
like it’s been marked up with tags or formatting instructions. While
|
151
|
+
Markdown’s syntax has been influenced by several existing text-to-HTML
|
152
|
+
filters — including <a href="http://docutils.sourceforge.net/mirror/setext.html">Setext</a>, <a href="http://www.aaronsw.com/2002/atx/">atx</a>, <a href="http://textism.com/tools/textile/">Textile</a>, <a href="http://docutils.sourceforge.net/rst.html">reStructuredText</a>,
|
153
|
+
<a href="http://www.triptico.com/software/grutatxt.html">Grutatext</a>, and <a href="http://ettext.taint.org/doc/">EtText</a> — the single biggest source of
|
154
|
+
inspiration for Markdown’s syntax is the format of plain text email.</p>
|
155
|
+
|
156
|
+
<p>To this end, Markdown’s syntax is comprised entirely of punctuation
|
157
|
+
characters, which punctuation characters have been carefully chosen so
|
158
|
+
as to look like what they mean. E.g., asterisks around a word actually
|
159
|
+
look like *emphasis*. Markdown lists look like, well, lists. Even
|
160
|
+
blockquotes look like quoted passages of text, assuming you’ve ever
|
161
|
+
used email.</p>
|
162
|
+
|
163
|
+
<h3 id="html">Inline HTML</h3>
|
164
|
+
|
165
|
+
<p>Markdown’s syntax is intended for one purpose: to be used as a
|
166
|
+
format for <em>writing</em> for the web.</p>
|
167
|
+
|
168
|
+
<p>Markdown is not a replacement for HTML, or even close to it. Its
|
169
|
+
syntax is very small, corresponding only to a very small subset of
|
170
|
+
HTML tags. The idea is <em>not</em> to create a syntax that makes it easier
|
171
|
+
to insert HTML tags. In my opinion, HTML tags are already easy to
|
172
|
+
insert. The idea for Markdown is to make it easy to read, write, and
|
173
|
+
edit prose. HTML is a <em>publishing</em> format; Markdown is a <em>writing</em>
|
174
|
+
format. Thus, Markdown’s formatting syntax only addresses issues that
|
175
|
+
can be conveyed in plain text.</p>
|
176
|
+
|
177
|
+
<p>For any markup that is not covered by Markdown’s syntax, you simply
|
178
|
+
use HTML itself. There’s no need to preface it or delimit it to
|
179
|
+
indicate that you’re switching from Markdown to HTML; you just use
|
180
|
+
the tags.</p>
|
181
|
+
|
182
|
+
<p>The only restrictions are that block-level HTML elements — e.g. <code><div></code>,
|
183
|
+
<code><table></code>, <code><pre></code>, <code><p></code>, etc. — must be separated from surrounding
|
184
|
+
content by blank lines, and the start and end tags of the block should
|
185
|
+
not be indented with tabs or spaces. Markdown is smart enough not
|
186
|
+
to add extra (unwanted) <code><p></code> tags around HTML block-level tags.</p>
|
187
|
+
|
188
|
+
<p>For example, to add an HTML table to a Markdown article:</p>
|
189
|
+
|
190
|
+
<pre><code>This is a regular paragraph.
|
191
|
+
|
192
|
+
<table>
|
193
|
+
<tr>
|
194
|
+
<td>Foo</td>
|
195
|
+
</tr>
|
196
|
+
</table>
|
197
|
+
|
198
|
+
This is another regular paragraph.
|
199
|
+
</code></pre>
|
200
|
+
|
201
|
+
<p>Note that Markdown formatting syntax is not processed within block-level
|
202
|
+
HTML tags. E.g., you can’t use Markdown-style <code>*emphasis*</code> inside an
|
203
|
+
HTML block.</p>
|
204
|
+
|
205
|
+
<p>Span-level HTML tags — e.g. <code><span></code>, <code><cite></code>, or <code><del></code> — can be
|
206
|
+
used anywhere in a Markdown paragraph, list item, or header. If you
|
207
|
+
want, you can even use HTML tags instead of Markdown formatting; e.g. if
|
208
|
+
you’d prefer to use HTML <code><a></code> or <code><img></code> tags instead of Markdown’s
|
209
|
+
link or image syntax, go right ahead.</p>
|
210
|
+
|
211
|
+
<p>Unlike block-level HTML tags, Markdown syntax <em>is</em> processed within
|
212
|
+
span-level tags.</p>
|
213
|
+
|
214
|
+
<h3 id="autoescape">Automatic Escaping for Special Characters</h3>
|
215
|
+
|
216
|
+
<p>In HTML, there are two characters that demand special treatment: <code><</code>
|
217
|
+
and <code>&</code>. Left angle brackets are used to start tags; ampersands are
|
218
|
+
used to denote HTML entities. If you want to use them as literal
|
219
|
+
characters, you must escape them as entities, e.g. <code>&lt;</code>, and
|
220
|
+
<code>&amp;</code>.</p>
|
221
|
+
|
222
|
+
<p>Ampersands in particular are bedeviling for web writers. If you want to
|
223
|
+
write about ‘AT&T’, you need to write ‘<code>AT&amp;T</code>’. You even need to
|
224
|
+
escape ampersands within URLs. Thus, if you want to link to:</p>
|
225
|
+
|
226
|
+
<pre><code>http://images.google.com/images?num=30&q=larry+bird
|
227
|
+
</code></pre>
|
228
|
+
|
229
|
+
<p>you need to encode the URL as:</p>
|
230
|
+
|
231
|
+
<pre><code>http://images.google.com/images?num=30&amp;q=larry+bird
|
232
|
+
</code></pre>
|
233
|
+
|
234
|
+
<p>in your anchor tag <code>href</code> attribute. Needless to say, this is easy to
|
235
|
+
forget, and is probably the single most common source of HTML validation
|
236
|
+
errors in otherwise well-marked-up web sites.</p>
|
237
|
+
|
238
|
+
<p>Markdown allows you to use these characters naturally, taking care of
|
239
|
+
all the necessary escaping for you. If you use an ampersand as part of
|
240
|
+
an HTML entity, it remains unchanged; otherwise it will be translated
|
241
|
+
into <code>&amp;</code>.</p>
|
242
|
+
|
243
|
+
<p>So, if you want to include a copyright symbol in your article, you can write:</p>
|
244
|
+
|
245
|
+
<pre><code>&copy;
|
246
|
+
</code></pre>
|
247
|
+
|
248
|
+
<p>and Markdown will leave it alone. But if you write:</p>
|
249
|
+
|
250
|
+
<pre><code>AT&T
|
251
|
+
</code></pre>
|
252
|
+
|
253
|
+
<p>Markdown will translate it to:</p>
|
254
|
+
|
255
|
+
<pre><code>AT&amp;T
|
256
|
+
</code></pre>
|
257
|
+
|
258
|
+
<p>Similarly, because Markdown supports <a href="#html">inline HTML</a>, if you use
|
259
|
+
angle brackets as delimiters for HTML tags, Markdown will treat them as
|
260
|
+
such. But if you write:</p>
|
261
|
+
|
262
|
+
<pre><code>4 < 5
|
263
|
+
</code></pre>
|
264
|
+
|
265
|
+
<p>Markdown will translate it to:</p>
|
266
|
+
|
267
|
+
<pre><code>4 &lt; 5
|
268
|
+
</code></pre>
|
269
|
+
|
270
|
+
<p>However, inside Markdown code spans and blocks, angle brackets and
|
271
|
+
ampersands are <em>always</em> encoded automatically. This makes it easy to use
|
272
|
+
Markdown to write about HTML code. (As opposed to raw HTML, which is a
|
273
|
+
terrible format for writing about HTML syntax, because every single <code><</code>
|
274
|
+
and <code>&</code> in your example code needs to be escaped.)</p>
|
275
|
+
|
276
|
+
<hr />
|
277
|
+
|
278
|
+
<h2 id="block">Block Elements</h2>
|
279
|
+
|
280
|
+
<h3 id="p">Paragraphs and Line Breaks</h3>
|
281
|
+
|
282
|
+
<p>A paragraph is simply one or more consecutive lines of text, separated
|
283
|
+
by one or more blank lines. (A blank line is any line that looks like a
|
284
|
+
blank line — a line containing nothing but spaces or tabs is considered
|
285
|
+
blank.) Normal paragraphs should not be indented with spaces or tabs.</p>
|
286
|
+
|
287
|
+
<p>The implication of the “one or more consecutive lines of text” rule is
|
288
|
+
that Markdown supports “hard-wrapped” text paragraphs. This differs
|
289
|
+
significantly from most other text-to-HTML formatters (including Movable
|
290
|
+
Type’s “Convert Line Breaks” option) which translate every line break
|
291
|
+
character in a paragraph into a <code><br /></code> tag.</p>
|
292
|
+
|
293
|
+
<p>When you <em>do</em> want to insert a <code><br /></code> break tag using Markdown, you
|
294
|
+
end a line with two or more spaces, then type return.</p>
|
295
|
+
|
296
|
+
<p>Yes, this takes a tad more effort to create a <code><br /></code>, but a simplistic
|
297
|
+
“every line break is a <code><br /></code>” rule wouldn’t work for Markdown.
|
298
|
+
Markdown’s email-style <a href="#blockquote">blockquoting</a> and multi-paragraph <a href="#list">list items</a>
|
299
|
+
work best — and look better — when you format them with hard breaks.</p>
|
300
|
+
|
301
|
+
<h3 id="header">Headers</h3>
|
302
|
+
|
303
|
+
<p>Markdown supports two styles of headers, <a href="http://docutils.sourceforge.net/mirror/setext.html">Setext</a> and <a href="http://www.aaronsw.com/2002/atx/">atx</a>.</p>
|
304
|
+
|
305
|
+
<p>Setext-style headers are “underlined” using equal signs (for first-level
|
306
|
+
headers) and dashes (for second-level headers). For example:</p>
|
307
|
+
|
308
|
+
<pre><code>This is an H1
|
309
|
+
=============
|
310
|
+
|
311
|
+
This is an H2
|
312
|
+
-------------
|
313
|
+
</code></pre>
|
314
|
+
|
315
|
+
<p>Any number of underlining <code>=</code>’s or <code>-</code>’s will work.</p>
|
316
|
+
|
317
|
+
<p>Atx-style headers use 1-6 hash characters at the start of the line,
|
318
|
+
corresponding to header levels 1-6. For example:</p>
|
319
|
+
|
320
|
+
<pre><code># This is an H1
|
321
|
+
|
322
|
+
## This is an H2
|
323
|
+
|
324
|
+
###### This is an H6
|
325
|
+
</code></pre>
|
326
|
+
|
327
|
+
<p>Optionally, you may “close” atx-style headers. This is purely
|
328
|
+
cosmetic — you can use this if you think it looks better. The
|
329
|
+
closing hashes don’t even need to match the number of hashes
|
330
|
+
used to open the header. (The number of opening hashes
|
331
|
+
determines the header level.) :</p>
|
332
|
+
|
333
|
+
<pre><code># This is an H1 #
|
334
|
+
|
335
|
+
## This is an H2 ##
|
336
|
+
|
337
|
+
### This is an H3 ######
|
338
|
+
</code></pre>
|
339
|
+
|
340
|
+
<h3 id="blockquote">Blockquotes</h3>
|
341
|
+
|
342
|
+
<p>Markdown uses email-style <code>></code> characters for blockquoting. If you’re
|
343
|
+
familiar with quoting passages of text in an email message, then you
|
344
|
+
know how to create a blockquote in Markdown. It looks best if you hard
|
345
|
+
wrap the text and put a <code>></code> before every line:</p>
|
346
|
+
|
347
|
+
<pre><code>> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
|
348
|
+
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
|
349
|
+
> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
|
350
|
+
>
|
351
|
+
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
|
352
|
+
> id sem consectetuer libero luctus adipiscing.
|
353
|
+
</code></pre>
|
354
|
+
|
355
|
+
<p>Markdown allows you to be lazy and only put the <code>></code> before the first
|
356
|
+
line of a hard-wrapped paragraph:</p>
|
357
|
+
|
358
|
+
<pre><code>> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
|
359
|
+
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
|
360
|
+
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
|
361
|
+
|
362
|
+
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
|
363
|
+
id sem consectetuer libero luctus adipiscing.
|
364
|
+
</code></pre>
|
365
|
+
|
366
|
+
<p>Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by
|
367
|
+
adding additional levels of <code>></code>:</p>
|
368
|
+
|
369
|
+
<pre><code>> This is the first level of quoting.
|
370
|
+
>
|
371
|
+
> > This is nested blockquote.
|
372
|
+
>
|
373
|
+
> Back to the first level.
|
374
|
+
</code></pre>
|
375
|
+
|
376
|
+
<p>Blockquotes can contain other Markdown elements, including headers, lists,
|
377
|
+
and code blocks:</p>
|
378
|
+
|
379
|
+
<pre><code>> ## This is a header.
|
380
|
+
>
|
381
|
+
> 1. This is the first list item.
|
382
|
+
> 2. This is the second list item.
|
383
|
+
>
|
384
|
+
> Here's some example code:
|
385
|
+
>
|
386
|
+
> return shell_exec("echo $input | $markdown_script");
|
387
|
+
</code></pre>
|
388
|
+
|
389
|
+
<p>Any decent text editor should make email-style quoting easy. For
|
390
|
+
example, with BBEdit, you can make a selection and choose Increase
|
391
|
+
Quote Level from the Text menu.</p>
|
392
|
+
|
393
|
+
<h3 id="list">Lists</h3>
|
394
|
+
|
395
|
+
<p>Markdown supports ordered (numbered) and unordered (bulleted) lists.</p>
|
396
|
+
|
397
|
+
<p>Unordered lists use asterisks, pluses, and hyphens — interchangably
|
398
|
+
— as list markers:</p>
|
399
|
+
|
400
|
+
<pre><code>* Red
|
401
|
+
* Green
|
402
|
+
* Blue
|
403
|
+
</code></pre>
|
404
|
+
|
405
|
+
<p>is equivalent to:</p>
|
406
|
+
|
407
|
+
<pre><code>+ Red
|
408
|
+
+ Green
|
409
|
+
+ Blue
|
410
|
+
</code></pre>
|
411
|
+
|
412
|
+
<p>and:</p>
|
413
|
+
|
414
|
+
<pre><code>- Red
|
415
|
+
- Green
|
416
|
+
- Blue
|
417
|
+
</code></pre>
|
418
|
+
|
419
|
+
<p>Ordered lists use numbers followed by periods:</p>
|
420
|
+
|
421
|
+
<pre><code>1. Bird
|
422
|
+
2. McHale
|
423
|
+
3. Parish
|
424
|
+
</code></pre>
|
425
|
+
|
426
|
+
<p>It’s important to note that the actual numbers you use to mark the
|
427
|
+
list have no effect on the HTML output Markdown produces. The HTML
|
428
|
+
Markdown produces from the above list is:</p>
|
429
|
+
|
430
|
+
<pre><code><ol>
|
431
|
+
<li>Bird</li>
|
432
|
+
<li>McHale</li>
|
433
|
+
<li>Parish</li>
|
434
|
+
</ol>
|
435
|
+
</code></pre>
|
436
|
+
|
437
|
+
<p>If you instead wrote the list in Markdown like this:</p>
|
438
|
+
|
439
|
+
<pre><code>1. Bird
|
440
|
+
1. McHale
|
441
|
+
1. Parish
|
442
|
+
</code></pre>
|
443
|
+
|
444
|
+
<p>or even:</p>
|
445
|
+
|
446
|
+
<pre><code>3. Bird
|
447
|
+
1. McHale
|
448
|
+
8. Parish
|
449
|
+
</code></pre>
|
450
|
+
|
451
|
+
<p>you’d get the exact same HTML output. The point is, if you want to,
|
452
|
+
you can use ordinal numbers in your ordered Markdown lists, so that
|
453
|
+
the numbers in your source match the numbers in your published HTML.
|
454
|
+
But if you want to be lazy, you don’t have to.</p>
|
455
|
+
|
456
|
+
<p>If you do use lazy list numbering, however, you should still start the
|
457
|
+
list with the number 1. At some point in the future, Markdown may support
|
458
|
+
starting ordered lists at an arbitrary number.</p>
|
459
|
+
|
460
|
+
<p>List markers typically start at the left margin, but may be indented by
|
461
|
+
up to three spaces. List markers must be followed by one or more spaces
|
462
|
+
or a tab.</p>
|
463
|
+
|
464
|
+
<p>To make lists look nice, you can wrap items with hanging indents:</p>
|
465
|
+
|
466
|
+
<pre><code>* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
|
467
|
+
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
|
468
|
+
viverra nec, fringilla in, laoreet vitae, risus.
|
469
|
+
* Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
|
470
|
+
Suspendisse id sem consectetuer libero luctus adipiscing.
|
471
|
+
</code></pre>
|
472
|
+
|
473
|
+
<p>But if you want to be lazy, you don’t have to:</p>
|
474
|
+
|
475
|
+
<pre><code>* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
|
476
|
+
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
|
477
|
+
viverra nec, fringilla in, laoreet vitae, risus.
|
478
|
+
* Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
|
479
|
+
Suspendisse id sem consectetuer libero luctus adipiscing.
|
480
|
+
</code></pre>
|
481
|
+
|
482
|
+
<p>If list items are separated by blank lines, Markdown will wrap the
|
483
|
+
items in <code><p></code> tags in the HTML output. For example, this input:</p>
|
484
|
+
|
485
|
+
<pre><code>* Bird
|
486
|
+
* Magic
|
487
|
+
</code></pre>
|
488
|
+
|
489
|
+
<p>will turn into:</p>
|
490
|
+
|
491
|
+
<pre><code><ul>
|
492
|
+
<li>Bird</li>
|
493
|
+
<li>Magic</li>
|
494
|
+
</ul>
|
495
|
+
</code></pre>
|
496
|
+
|
497
|
+
<p>But this:</p>
|
498
|
+
|
499
|
+
<pre><code>* Bird
|
500
|
+
|
501
|
+
* Magic
|
502
|
+
</code></pre>
|
503
|
+
|
504
|
+
<p>will turn into:</p>
|
505
|
+
|
506
|
+
<pre><code><ul>
|
507
|
+
<li><p>Bird</p></li>
|
508
|
+
<li><p>Magic</p></li>
|
509
|
+
</ul>
|
510
|
+
</code></pre>
|
511
|
+
|
512
|
+
<p>List items may consist of multiple paragraphs. Each subsequent
|
513
|
+
paragraph in a list item must be indented by either 4 spaces
|
514
|
+
or one tab:</p>
|
515
|
+
|
516
|
+
<pre><code>1. This is a list item with two paragraphs. Lorem ipsum dolor
|
517
|
+
sit amet, consectetuer adipiscing elit. Aliquam hendrerit
|
518
|
+
mi posuere lectus.
|
519
|
+
|
520
|
+
Vestibulum enim wisi, viverra nec, fringilla in, laoreet
|
521
|
+
vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
|
522
|
+
sit amet velit.
|
523
|
+
|
524
|
+
2. Suspendisse id sem consectetuer libero luctus adipiscing.
|
525
|
+
</code></pre>
|
526
|
+
|
527
|
+
<p>It looks nice if you indent every line of the subsequent
|
528
|
+
paragraphs, but here again, Markdown will allow you to be
|
529
|
+
lazy:</p>
|
530
|
+
|
531
|
+
<pre><code>* This is a list item with two paragraphs.
|
532
|
+
|
533
|
+
This is the second paragraph in the list item. You're
|
534
|
+
only required to indent the first line. Lorem ipsum dolor
|
535
|
+
sit amet, consectetuer adipiscing elit.
|
536
|
+
|
537
|
+
* Another item in the same list.
|
538
|
+
</code></pre>
|
539
|
+
|
540
|
+
<p>To put a blockquote within a list item, the blockquote’s <code>></code>
|
541
|
+
delimiters need to be indented:</p>
|
542
|
+
|
543
|
+
<pre><code>* A list item with a blockquote:
|
544
|
+
|
545
|
+
> This is a blockquote
|
546
|
+
> inside a list item.
|
547
|
+
</code></pre>
|
548
|
+
|
549
|
+
<p>To put a code block within a list item, the code block needs
|
550
|
+
to be indented <em>twice</em> — 8 spaces or two tabs:</p>
|
551
|
+
|
552
|
+
<pre><code>* A list item with a code block:
|
553
|
+
|
554
|
+
<code goes here>
|
555
|
+
</code></pre>
|
556
|
+
|
557
|
+
<p>It’s worth noting that it’s possible to trigger an ordered list by
|
558
|
+
accident, by writing something like this:</p>
|
559
|
+
|
560
|
+
<pre><code>1986. What a great season.
|
561
|
+
</code></pre>
|
562
|
+
|
563
|
+
<p>In other words, a <em>number-period-space</em> sequence at the beginning of a
|
564
|
+
line. To avoid this, you can backslash-escape the period:</p>
|
565
|
+
|
566
|
+
<pre><code>1986\. What a great season.
|
567
|
+
</code></pre>
|
568
|
+
|
569
|
+
<h3 id="precode">Code Blocks</h3>
|
570
|
+
|
571
|
+
<p>Pre-formatted code blocks are used for writing about programming or
|
572
|
+
markup source code. Rather than forming normal paragraphs, the lines
|
573
|
+
of a code block are interpreted literally. Markdown wraps a code block
|
574
|
+
in both <code><pre></code> and <code><code></code> tags.</p>
|
575
|
+
|
576
|
+
<p>To produce a code block in Markdown, simply indent every line of the
|
577
|
+
block by at least 4 spaces or 1 tab. For example, given this input:</p>
|
578
|
+
|
579
|
+
<pre><code>This is a normal paragraph:
|
580
|
+
|
581
|
+
This is a code block.
|
582
|
+
</code></pre>
|
583
|
+
|
584
|
+
<p>Markdown will generate:</p>
|
585
|
+
|
586
|
+
<pre><code><p>This is a normal paragraph:</p>
|
587
|
+
|
588
|
+
<pre><code>This is a code block.
|
589
|
+
</code></pre>
|
590
|
+
</code></pre>
|
591
|
+
|
592
|
+
<p>One level of indentation — 4 spaces or 1 tab — is removed from each
|
593
|
+
line of the code block. For example, this:</p>
|
594
|
+
|
595
|
+
<pre><code>Here is an example of AppleScript:
|
596
|
+
|
597
|
+
tell application "Foo"
|
598
|
+
beep
|
599
|
+
end tell
|
600
|
+
</code></pre>
|
601
|
+
|
602
|
+
<p>will turn into:</p>
|
603
|
+
|
604
|
+
<pre><code><p>Here is an example of AppleScript:</p>
|
605
|
+
|
606
|
+
<pre><code>tell application "Foo"
|
607
|
+
beep
|
608
|
+
end tell
|
609
|
+
</code></pre>
|
610
|
+
</code></pre>
|
611
|
+
|
612
|
+
<p>A code block continues until it reaches a line that is not indented
|
613
|
+
(or the end of the article).</p>
|
614
|
+
|
615
|
+
<p>Within a code block, ampersands (<code>&</code>) and angle brackets (<code><</code> and <code>></code>)
|
616
|
+
are automatically converted into HTML entities. This makes it very
|
617
|
+
easy to include example HTML source code using Markdown — just paste
|
618
|
+
it and indent it, and Markdown will handle the hassle of encoding the
|
619
|
+
ampersands and angle brackets. For example, this:</p>
|
620
|
+
|
621
|
+
<pre><code> <div class="footer">
|
622
|
+
&copy; 2004 Foo Corporation
|
623
|
+
</div>
|
624
|
+
</code></pre>
|
625
|
+
|
626
|
+
<p>will turn into:</p>
|
627
|
+
|
628
|
+
<pre><code><pre><code>&lt;div class="footer"&gt;
|
629
|
+
&amp;copy; 2004 Foo Corporation
|
630
|
+
&lt;/div&gt;
|
631
|
+
</code></pre>
|
632
|
+
</code></pre>
|
633
|
+
|
634
|
+
<p>Regular Markdown syntax is not processed within code blocks. E.g.,
|
635
|
+
asterisks are just literal asterisks within a code block. This means
|
636
|
+
it’s also easy to use Markdown to write about Markdown’s own syntax.</p>
|
637
|
+
|
638
|
+
<h3 id="hr">Horizontal Rules</h3>
|
639
|
+
|
640
|
+
<p>You can produce a horizontal rule tag (<code><hr /></code>) by placing three or
|
641
|
+
more hyphens, asterisks, or underscores on a line by themselves. If you
|
642
|
+
wish, you may use spaces between the hyphens or asterisks. Each of the
|
643
|
+
following lines will produce a horizontal rule:</p>
|
644
|
+
|
645
|
+
<pre><code>* * *
|
646
|
+
|
647
|
+
***
|
648
|
+
|
649
|
+
*****
|
650
|
+
|
651
|
+
- - -
|
652
|
+
|
653
|
+
---------------------------------------
|
654
|
+
</code></pre>
|
655
|
+
|
656
|
+
<hr />
|
657
|
+
|
658
|
+
<h2 id="span">Span Elements</h2>
|
659
|
+
|
660
|
+
<h3 id="link">Links</h3>
|
661
|
+
|
662
|
+
<p>Markdown supports two style of links: <em>inline</em> and <em>reference</em>.</p>
|
663
|
+
|
664
|
+
<p>In both styles, the link text is delimited by [square brackets].</p>
|
665
|
+
|
666
|
+
<p>To create an inline link, use a set of regular parentheses immediately
|
667
|
+
after the link text’s closing square bracket. Inside the parentheses,
|
668
|
+
put the URL where you want the link to point, along with an <em>optional</em>
|
669
|
+
title for the link, surrounded in quotes. For example:</p>
|
670
|
+
|
671
|
+
<pre><code>This is [an example](http://example.com/ "Title") inline link.
|
672
|
+
|
673
|
+
[This link](http://example.net/) has no title attribute.
|
674
|
+
</code></pre>
|
675
|
+
|
676
|
+
<p>Will produce:</p>
|
677
|
+
|
678
|
+
<pre><code><p>This is <a href="http://example.com/" title="Title">
|
679
|
+
an example</a> inline link.</p>
|
680
|
+
|
681
|
+
<p><a href="http://example.net/">This link</a> has no
|
682
|
+
title attribute.</p>
|
683
|
+
</code></pre>
|
684
|
+
|
685
|
+
<p>If you’re referring to a local resource on the same server, you can
|
686
|
+
use relative paths:</p>
|
687
|
+
|
688
|
+
<pre><code>See my [About](/about/) page for details.
|
689
|
+
</code></pre>
|
690
|
+
|
691
|
+
<p>Reference-style links use a second set of square brackets, inside
|
692
|
+
which you place a label of your choosing to identify the link:</p>
|
693
|
+
|
694
|
+
<pre><code>This is [an example][id] reference-style link.
|
695
|
+
</code></pre>
|
696
|
+
|
697
|
+
<p>You can optionally use a space to separate the sets of brackets:</p>
|
698
|
+
|
699
|
+
<pre><code>This is [an example] [id] reference-style link.
|
700
|
+
</code></pre>
|
701
|
+
|
702
|
+
<p>Then, anywhere in the document, you define your link label like this,
|
703
|
+
on a line by itself:</p>
|
704
|
+
|
705
|
+
<pre><code>[id]: http://example.com/ "Optional Title Here"
|
706
|
+
</code></pre>
|
707
|
+
|
708
|
+
<p>That is:</p>
|
709
|
+
|
710
|
+
<ul>
|
711
|
+
<li>Square brackets containing the link identifier (optionally
|
712
|
+
indented from the left margin using up to three spaces);</li>
|
713
|
+
<li>followed by a colon;</li>
|
714
|
+
<li>followed by one or more spaces (or tabs);</li>
|
715
|
+
<li>followed by the URL for the link;</li>
|
716
|
+
<li>optionally followed by a title attribute for the link, enclosed
|
717
|
+
in double or single quotes, or enclosed in parentheses.</li>
|
718
|
+
</ul>
|
719
|
+
|
720
|
+
<p>The following three link definitions are equivalent:</p>
|
721
|
+
|
722
|
+
<pre><code>[foo]: http://example.com/ "Optional Title Here"
|
723
|
+
[foo]: http://example.com/ 'Optional Title Here'
|
724
|
+
[foo]: http://example.com/ (Optional Title Here)
|
725
|
+
</code></pre>
|
726
|
+
|
727
|
+
<p><strong>Note:</strong> There is a known bug in Markdown.pl 1.0.1 which prevents
|
728
|
+
single quotes from being used to delimit link titles.</p>
|
729
|
+
|
730
|
+
<p>The link URL may, optionally, be surrounded by angle brackets:</p>
|
731
|
+
|
732
|
+
<pre><code>[id]: <http://example.com/> "Optional Title Here"
|
733
|
+
</code></pre>
|
734
|
+
|
735
|
+
<p>You can put the title attribute on the next line and use extra spaces
|
736
|
+
or tabs for padding, which tends to look better with longer URLs:</p>
|
737
|
+
|
738
|
+
<pre><code>[id]: http://example.com/longish/path/to/resource/here
|
739
|
+
"Optional Title Here"
|
740
|
+
</code></pre>
|
741
|
+
|
742
|
+
<p>Link definitions are only used for creating links during Markdown
|
743
|
+
processing, and are stripped from your document in the HTML output.</p>
|
744
|
+
|
745
|
+
<p>Link definition names may consist of letters, numbers, spaces, and
|
746
|
+
punctuation — but they are <em>not</em> case sensitive. E.g. these two
|
747
|
+
links:</p>
|
748
|
+
|
749
|
+
<pre><code>[link text][a]
|
750
|
+
[link text][A]
|
751
|
+
</code></pre>
|
752
|
+
|
753
|
+
<p>are equivalent.</p>
|
754
|
+
|
755
|
+
<p>The <em>implicit link name</em> shortcut allows you to omit the name of the
|
756
|
+
link, in which case the link text itself is used as the name.
|
757
|
+
Just use an empty set of square brackets — e.g., to link the word
|
758
|
+
“Google” to the google.com web site, you could simply write:</p>
|
759
|
+
|
760
|
+
<pre><code>[Google][]
|
761
|
+
</code></pre>
|
762
|
+
|
763
|
+
<p>And then define the link:</p>
|
764
|
+
|
765
|
+
<pre><code>[Google]: http://google.com/
|
766
|
+
</code></pre>
|
767
|
+
|
768
|
+
<p>Because link names may contain spaces, this shortcut even works for
|
769
|
+
multiple words in the link text:</p>
|
770
|
+
|
771
|
+
<pre><code>Visit [Daring Fireball][] for more information.
|
772
|
+
</code></pre>
|
773
|
+
|
774
|
+
<p>And then define the link:</p>
|
775
|
+
|
776
|
+
<pre><code>[Daring Fireball]: http://daringfireball.net/
|
777
|
+
</code></pre>
|
778
|
+
|
779
|
+
<p>Link definitions can be placed anywhere in your Markdown document. I
|
780
|
+
tend to put them immediately after each paragraph in which they’re
|
781
|
+
used, but if you want, you can put them all at the end of your
|
782
|
+
document, sort of like footnotes.</p>
|
783
|
+
|
784
|
+
<p>Here’s an example of reference links in action:</p>
|
785
|
+
|
786
|
+
<pre><code>I get 10 times more traffic from [Google] [1] than from
|
787
|
+
[Yahoo] [2] or [MSN] [3].
|
788
|
+
|
789
|
+
[1]: http://google.com/ "Google"
|
790
|
+
[2]: http://search.yahoo.com/ "Yahoo Search"
|
791
|
+
[3]: http://search.msn.com/ "MSN Search"
|
792
|
+
</code></pre>
|
793
|
+
|
794
|
+
<p>Using the implicit link name shortcut, you could instead write:</p>
|
795
|
+
|
796
|
+
<pre><code>I get 10 times more traffic from [Google][] than from
|
797
|
+
[Yahoo][] or [MSN][].
|
798
|
+
|
799
|
+
[google]: http://google.com/ "Google"
|
800
|
+
[yahoo]: http://search.yahoo.com/ "Yahoo Search"
|
801
|
+
[msn]: http://search.msn.com/ "MSN Search"
|
802
|
+
</code></pre>
|
803
|
+
|
804
|
+
<p>Both of the above examples will produce the following HTML output:</p>
|
805
|
+
|
806
|
+
<pre><code><p>I get 10 times more traffic from <a href="http://google.com/"
|
807
|
+
title="Google">Google</a> than from
|
808
|
+
<a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
|
809
|
+
or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
|
810
|
+
</code></pre>
|
811
|
+
|
812
|
+
<p>For comparison, here is the same paragraph written using
|
813
|
+
Markdown’s inline link style:</p>
|
814
|
+
|
815
|
+
<pre><code>I get 10 times more traffic from [Google](http://google.com/ "Google")
|
816
|
+
than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
|
817
|
+
[MSN](http://search.msn.com/ "MSN Search").
|
818
|
+
</code></pre>
|
819
|
+
|
820
|
+
<p>The point of reference-style links is not that they’re easier to
|
821
|
+
write. The point is that with reference-style links, your document
|
822
|
+
source is vastly more readable. Compare the above examples: using
|
823
|
+
reference-style links, the paragraph itself is only 81 characters
|
824
|
+
long; with inline-style links, it’s 176 characters; and as raw HTML,
|
825
|
+
it’s 234 characters. In the raw HTML, there’s more markup than there
|
826
|
+
is text.</p>
|
827
|
+
|
828
|
+
<p>With Markdown’s reference-style links, a source document much more
|
829
|
+
closely resembles the final output, as rendered in a browser. By
|
830
|
+
allowing you to move the markup-related metadata out of the paragraph,
|
831
|
+
you can add links without interrupting the narrative flow of your
|
832
|
+
prose.</p>
|
833
|
+
|
834
|
+
<h3 id="em">Emphasis</h3>
|
835
|
+
|
836
|
+
<p>Markdown treats asterisks (<code>*</code>) and underscores (<code>_</code>) as indicators of
|
837
|
+
emphasis. Text wrapped with one <code>*</code> or <code>_</code> will be wrapped with an
|
838
|
+
HTML <code><em></code> tag; double <code>*</code>’s or <code>_</code>’s will be wrapped with an HTML
|
839
|
+
<code><strong></code> tag. E.g., this input:</p>
|
840
|
+
|
841
|
+
<pre><code>*single asterisks*
|
842
|
+
|
843
|
+
_single underscores_
|
844
|
+
|
845
|
+
**double asterisks**
|
846
|
+
|
847
|
+
__double underscores__
|
848
|
+
</code></pre>
|
849
|
+
|
850
|
+
<p>will produce:</p>
|
851
|
+
|
852
|
+
<pre><code><em>single asterisks</em>
|
853
|
+
|
854
|
+
<em>single underscores</em>
|
855
|
+
|
856
|
+
<strong>double asterisks</strong>
|
857
|
+
|
858
|
+
<strong>double underscores</strong>
|
859
|
+
</code></pre>
|
860
|
+
|
861
|
+
<p>You can use whichever style you prefer; the lone restriction is that
|
862
|
+
the same character must be used to open and close an emphasis span.</p>
|
863
|
+
|
864
|
+
<p>Emphasis can be used in the middle of a word:</p>
|
865
|
+
|
866
|
+
<pre><code>un*frigging*believable
|
867
|
+
</code></pre>
|
868
|
+
|
869
|
+
<p>But if you surround an <code>*</code> or <code>_</code> with spaces, it’ll be treated as a
|
870
|
+
literal asterisk or underscore.</p>
|
871
|
+
|
872
|
+
<p>To produce a literal asterisk or underscore at a position where it
|
873
|
+
would otherwise be used as an emphasis delimiter, you can backslash
|
874
|
+
escape it:</p>
|
875
|
+
|
876
|
+
<pre><code>\*this text is surrounded by literal asterisks\*
|
877
|
+
</code></pre>
|
878
|
+
|
879
|
+
<h3 id="code">Code</h3>
|
880
|
+
|
881
|
+
<p>To indicate a span of code, wrap it with backtick quotes (<code>`</code>).
|
882
|
+
Unlike a pre-formatted code block, a code span indicates code within a
|
883
|
+
normal paragraph. For example:</p>
|
884
|
+
|
885
|
+
<pre><code>Use the `printf()` function.
|
886
|
+
</code></pre>
|
887
|
+
|
888
|
+
<p>will produce:</p>
|
889
|
+
|
890
|
+
<pre><code><p>Use the <code>printf()</code> function.</p>
|
891
|
+
</code></pre>
|
892
|
+
|
893
|
+
<p>To include a literal backtick character within a code span, you can use
|
894
|
+
multiple backticks as the opening and closing delimiters:</p>
|
895
|
+
|
896
|
+
<pre><code>``There is a literal backtick (`) here.``
|
897
|
+
</code></pre>
|
898
|
+
|
899
|
+
<p>which will produce this:</p>
|
900
|
+
|
901
|
+
<pre><code><p><code>There is a literal backtick (`) here.</code></p>
|
902
|
+
</code></pre>
|
903
|
+
|
904
|
+
<p>The backtick delimiters surrounding a code span may include spaces —
|
905
|
+
one after the opening, one before the closing. This allows you to place
|
906
|
+
literal backtick characters at the beginning or end of a code span:</p>
|
907
|
+
|
908
|
+
<pre><code>A single backtick in a code span: `` ` ``
|
909
|
+
|
910
|
+
A backtick-delimited string in a code span: `` `foo` ``
|
911
|
+
</code></pre>
|
912
|
+
|
913
|
+
<p>will produce:</p>
|
914
|
+
|
915
|
+
<pre><code><p>A single backtick in a code span: <code>`</code></p>
|
916
|
+
|
917
|
+
<p>A backtick-delimited string in a code span: <code>`foo`</code></p>
|
918
|
+
</code></pre>
|
919
|
+
|
920
|
+
<p>With a code span, ampersands and angle brackets are encoded as HTML
|
921
|
+
entities automatically, which makes it easy to include example HTML
|
922
|
+
tags. Markdown will turn this:</p>
|
923
|
+
|
924
|
+
<pre><code>Please don't use any `<blink>` tags.
|
925
|
+
</code></pre>
|
926
|
+
|
927
|
+
<p>into:</p>
|
928
|
+
|
929
|
+
<pre><code><p>Please don't use any <code>&lt;blink&gt;</code> tags.</p>
|
930
|
+
</code></pre>
|
931
|
+
|
932
|
+
<p>You can write this:</p>
|
933
|
+
|
934
|
+
<pre><code>`&#8212;` is the decimal-encoded equivalent of `&mdash;`.
|
935
|
+
</code></pre>
|
936
|
+
|
937
|
+
<p>to produce:</p>
|
938
|
+
|
939
|
+
<pre><code><p><code>&amp;#8212;</code> is the decimal-encoded
|
940
|
+
equivalent of <code>&amp;mdash;</code>.</p>
|
941
|
+
</code></pre>
|
942
|
+
|
943
|
+
<h3 id="img">Images</h3>
|
944
|
+
|
945
|
+
<p>Admittedly, it’s fairly difficult to devise a “natural” syntax for
|
946
|
+
placing images into a plain text document format.</p>
|
947
|
+
|
948
|
+
<p>Markdown uses an image syntax that is intended to resemble the syntax
|
949
|
+
for links, allowing for two styles: <em>inline</em> and <em>reference</em>.</p>
|
950
|
+
|
951
|
+
<p>Inline image syntax looks like this:</p>
|
952
|
+
|
953
|
+
<pre><code>![Alt text](/path/to/img.jpg)
|
954
|
+
|
955
|
+
![Alt text](/path/to/img.jpg "Optional title")
|
956
|
+
</code></pre>
|
957
|
+
|
958
|
+
<p>That is:</p>
|
959
|
+
|
960
|
+
<ul>
|
961
|
+
<li>An exclamation mark: <code>!</code>;</li>
|
962
|
+
<li>followed by a set of square brackets, containing the <code>alt</code>
|
963
|
+
attribute text for the image;</li>
|
964
|
+
<li>followed by a set of parentheses, containing the URL or path to
|
965
|
+
the image, and an optional <code>title</code> attribute enclosed in double
|
966
|
+
or single quotes.</li>
|
967
|
+
</ul>
|
968
|
+
|
969
|
+
<p>Reference-style image syntax looks like this:</p>
|
970
|
+
|
971
|
+
<pre><code>![Alt text][id]
|
972
|
+
</code></pre>
|
973
|
+
|
974
|
+
<p>Where “id” is the name of a defined image reference. Image references
|
975
|
+
are defined using syntax identical to link references:</p>
|
976
|
+
|
977
|
+
<pre><code>[id]: url/to/image "Optional title attribute"
|
978
|
+
</code></pre>
|
979
|
+
|
980
|
+
<p>As of this writing, Markdown has no syntax for specifying the
|
981
|
+
dimensions of an image; if this is important to you, you can simply
|
982
|
+
use regular HTML <code><img></code> tags.</p>
|
983
|
+
|
984
|
+
<hr />
|
985
|
+
|
986
|
+
<h2 id="misc">Miscellaneous</h2>
|
987
|
+
|
988
|
+
<h3 id="autolink">Automatic Links</h3>
|
989
|
+
|
990
|
+
<p>Markdown supports a shortcut style for creating “automatic” links for URLs and email addresses: simply surround the URL or email address with angle brackets. What this means is that if you want to show the actual text of a URL or email address, and also have it be a clickable link, you can do this:</p>
|
991
|
+
|
992
|
+
<pre><code><http://example.com/>
|
993
|
+
</code></pre>
|
994
|
+
|
995
|
+
<p>Markdown will turn this into:</p>
|
996
|
+
|
997
|
+
<pre><code><a href="http://example.com/">http://example.com/</a>
|
998
|
+
</code></pre>
|
999
|
+
|
1000
|
+
<p>Automatic links for email addresses work similarly, except that
|
1001
|
+
Markdown will also perform a bit of randomized decimal and hex
|
1002
|
+
entity-encoding to help obscure your address from address-harvesting
|
1003
|
+
spambots. For example, Markdown will turn this:</p>
|
1004
|
+
|
1005
|
+
<pre><code><address@example.com>
|
1006
|
+
</code></pre>
|
1007
|
+
|
1008
|
+
<p>into something like this:</p>
|
1009
|
+
|
1010
|
+
<pre><code><a href="&#x6D;&#x61;i&#x6C;&#x74;&#x6F;:&#x61;&#x64;&#x64;&#x72;&#x65;
|
1011
|
+
&#115;&#115;&#64;&#101;&#120;&#x61;&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;
|
1012
|
+
&#109;">&#x61;&#x64;&#x64;&#x72;&#x65;&#115;&#115;&#64;&#101;&#120;&#x61;
|
1013
|
+
&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;&#109;</a>
|
1014
|
+
</code></pre>
|
1015
|
+
|
1016
|
+
<p>which will render in a browser as a clickable link to “address@example.com”.</p>
|
1017
|
+
|
1018
|
+
<p>(This sort of entity-encoding trick will indeed fool many, if not
|
1019
|
+
most, address-harvesting bots, but it definitely won’t fool all of
|
1020
|
+
them. It’s better than nothing, but an address published in this way
|
1021
|
+
will probably eventually start receiving spam.)</p>
|
1022
|
+
|
1023
|
+
<h3 id="backslash">Backslash Escapes</h3>
|
1024
|
+
|
1025
|
+
<p>Markdown allows you to use backslash escapes to generate literal
|
1026
|
+
characters which would otherwise have special meaning in Markdown’s
|
1027
|
+
formatting syntax. For example, if you wanted to surround a word
|
1028
|
+
with literal asterisks (instead of an HTML <code><em></code> tag), you can use
|
1029
|
+
backslashes before the asterisks, like this:</p>
|
1030
|
+
|
1031
|
+
<pre><code>\*literal asterisks\*
|
1032
|
+
</code></pre>
|
1033
|
+
|
1034
|
+
<p>Markdown provides backslash escapes for the following characters:</p>
|
1035
|
+
|
1036
|
+
<pre><code>\ backslash
|
1037
|
+
` backtick
|
1038
|
+
* asterisk
|
1039
|
+
_ underscore
|
1040
|
+
{} curly braces
|
1041
|
+
[] square brackets
|
1042
|
+
() parentheses
|
1043
|
+
# hash mark
|
1044
|
+
+ plus sign
|
1045
|
+
- minus sign (hyphen)
|
1046
|
+
. dot
|
1047
|
+
! exclamation mark
|
1048
|
+
</code></pre>
|
1049
|
+
|
1050
|
+
</div> <!-- article -->
|
1051
|
+
|
1052
|
+
<div id="Footer">
|
1053
|
+
<form id="SiteSearch" action="/search" method="get" style="margin-bottom: 2.5em;">
|
1054
|
+
<div>
|
1055
|
+
<input name="q" type="text" value="" style="margin-right: 8px; width: 26em;" />
|
1056
|
+
<input type="submit" value="Search" />
|
1057
|
+
</div>
|
1058
|
+
</form>
|
1059
|
+
<p class='smallprint'><a href='http://www.amazon.com/exec/obidos/redirect?tag=daringfirebal-20&path=subst/home/home.html'>Shop at Amazon.com and support Daring Fireball</a></p>
|
1060
|
+
|
1061
|
+
<p class="smallprint">
|
1062
|
+
<a href="/linked/" title="Recent Linked List entries and archive.">Linked List</a> | <a href="/preferences/" title="Customize the font size and presentation options for this web site.">Display Preferences</a><br />
|
1063
|
+
Copyright © 2002–2010 John Gruber</p>
|
1064
|
+
</div>
|
1065
|
+
|
1066
|
+
|
1067
|
+
<script type="text/javascript">
|
1068
|
+
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
1069
|
+
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
1070
|
+
</script>
|
1071
|
+
<script type="text/javascript">
|
1072
|
+
try {
|
1073
|
+
var pageTracker = _gat._getTracker("UA-593949-1");
|
1074
|
+
pageTracker._trackPageview();
|
1075
|
+
} catch(err) {}</script>
|
1076
|
+
</div> <!-- Main -->
|
1077
|
+
|
1078
|
+
</div> <!-- box -->
|
1079
|
+
</body>
|
1080
|
+
</html>
|
1081
|
+
<!-- 0.6904 seconds -->
|