ron 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,133 @@
1
+ ron -- the opposite of roff
2
+ ===========================
3
+
4
+ ## DESCRIPTION
5
+
6
+ Ron is a humane text format and toolchain for creating UNIX man
7
+ pages, and things that appear as man pages from a distance. Use it
8
+ to build and install standard UNIX roff man pages or to generate
9
+ nicely formatted HTML manual pages for the web.
10
+
11
+ The Ron file format is based on Markdown. In fact, Ron files are a
12
+ compatible subset of Markdown syntax but have a more rigid structure and
13
+ extend Markdown in some ways to provide features commonly found in man
14
+ pages (e.g., definition lists). The ron(5) manual page defines the
15
+ format in more detail.
16
+
17
+ ## DOCUMENTATION
18
+
19
+ The `.ron` files located under the `man/` directory show off a wide
20
+ range of ron capabilities and are the source of Ron's own documentation.
21
+ The source files and generated HTML / roff output files are available
22
+ at:
23
+
24
+ * [ron(1)](http://rtomayko.github.com/ron/ron.1.html) -
25
+ build markdown based manual pages at the command line.
26
+ [source file](http://github.com/rtomayko/ron/blob/master/man/ron.1.ron),
27
+ [roff output](http://github.com/rtomayko/ron/blob/master/man/ron.1)
28
+
29
+ * [ron(5)](http://rtomayko.github.com/ron/ron.5.html) -
30
+ humane manual page authoring format syntax reference.
31
+ [source file](http://github.com/rtomayko/ron/blob/master/man/ron.5.ron),
32
+ [roff output](http://github.com/rtomayko/ron/blob/master/man/ron.5)
33
+
34
+ * [markdown(5)](http://rtomayko.github.com/ron/markdown.5.html) -
35
+ humane text markup syntax (taken from
36
+ [Markdown Syntax](http://daringfireball.net/projects/markdown/syntax),
37
+ John Gruber)
38
+ [source file](http://github.com/rtomayko/ron/blob/master/man/ron.5.ron),
39
+ [roff output](http://github.com/rtomayko/ron/blob/master/man/ron.5)
40
+
41
+ ## INSTALL
42
+
43
+ Install with Rubygems:
44
+
45
+ $ [sudo] gem install ron
46
+ $ ron --help
47
+
48
+ Or, clone the git repository:
49
+
50
+ $ git clone git://github.com/rtomayko/ron.git
51
+ $ PATH=ron/bin:$PATH
52
+ $ ron --help
53
+
54
+ ## BASIC USAGE
55
+
56
+ To generate a roff man page from the included
57
+ [`markdown.5.ron`](man/markdown.5.ron) file and open it with man(1):
58
+
59
+ $ ron -b man/markdown.5.ron
60
+ building: man/markdown.5
61
+ $ man man/markdown.5
62
+
63
+ To generate a standalone HTML version:
64
+
65
+ $ ron -b --html man/markdown.5.ron
66
+ building: man/markdown.5.html
67
+ $ open man/markdown.5.html
68
+
69
+ To build roff and HTML versions of all ron files:
70
+
71
+ $ ron -b --roff --html man/*.ron
72
+
73
+ If you just want to view a ron file as if it were a man page without
74
+ building intermediate files:
75
+
76
+ $ ron -m man/markdown.5.ron
77
+
78
+ The [ron(1)](http://rtomayko.github.com/ron/ron.1.html) manual page
79
+ includes comprehensive documentation on `ron` command line options.
80
+
81
+ ## ABOUT
82
+
83
+ Some people think UNIX manual pages are a poor and outdated style of
84
+ documentation. I disagree:
85
+
86
+ - Man pages follow a well defined structure that's immediately
87
+ familiar and provides a useful starting point for developers
88
+ documenting new tools, libraries, and formats.
89
+
90
+ - Man pages get to the point. Because they're written in an inverted
91
+ style, with a SYNOPSIS section followed by additional detail,
92
+ prose and references to other sources of information, man pages
93
+ provide the best of both cheat sheet and reference style
94
+ documentation.
95
+
96
+ - Man pages have extremely -- unbelievably -- limited text
97
+ formatting capabilities. You get a couple of headings, lists, bold,
98
+ underline and no more. This is a feature.
99
+
100
+ - Although two levels of section hierarchy are technically
101
+ supported, most man pages use only a single level. Unwieldy
102
+ document hierarchies complicate otherwise good documentation.
103
+ Feynman covered all of physics -- heavenly bodies through QED --
104
+ with only two levels of document hierarchy (_The Feynman Lectures
105
+ on Physics_, 1970).
106
+
107
+ - Man pages have a simple referencing syntax; e.g., sh(1), fork(2),
108
+ markdown(5). HTML versions can use this to generate links between
109
+ pages.
110
+
111
+ - The classical terminal man page display is typographically well
112
+ thought out. Big bold section headings, justified monospace text,
113
+ nicely indented paragraphs, intelligently aligned definition
114
+ lists, and an informational header and footer.
115
+
116
+ Unfortunately, trying to figure out how to create a man page is a
117
+ fairly tedious process. The roff/man macro languages are highly
118
+ extensible, fractured between multiple dialects, and include a bunch
119
+ of device specific stuff that's entirely irrelevant to modern
120
+ publishing tools.
121
+
122
+ Ron aims to address many of the issues with man page creation while
123
+ preserving the things that makes man pages a great form of
124
+ documentation.
125
+
126
+ ## COPYING
127
+
128
+ Ron is Copyright (C) 2009 [Ryan Tomayko](http://tomayko.com/about)
129
+ See the file COPYING for information of licensing and distribution.
130
+
131
+ ## SEE ALSO
132
+
133
+ ron(1), ron(5), markdown(5)
data/Rakefile CHANGED
@@ -1,20 +1,26 @@
1
1
  require 'rake/clean'
2
- require 'rake/testtask'
3
2
 
4
3
  task :default => :test
5
- task :spec => :test
6
4
 
7
- # SPECS ===============================================================
8
-
9
- Rake::TestTask.new(:test) do |t|
10
- t.test_files = FileList['test/*_test.rb']
11
- t.ruby_opts = ['-rubygems'] if defined? Gem
5
+ task :environment do
6
+ require_library 'nokogiri'
7
+ require_library 'rdiscount'
8
+ ENV['RUBYLIB'] = "#{$:.join(':')}:#{ENV['RUBYLIB']}"
9
+ ENV['PATH'] = "bin:#{ENV['PATH']}"
12
10
  end
13
11
 
14
- # DOCS =================================================================
12
+ desc 'Run tests'
13
+ task :test => :environment do
14
+ require_library 'contest'
15
+ if ENV['PATH'].split(':').any? { |p| File.executable?("#{p}/turn") }
16
+ sh 'turn -Ilib test/*_test.rb'
17
+ else
18
+ sh 'testrb Ilib test/*_test.rb'
19
+ end
20
+ end
15
21
 
16
22
  desc 'Build the manual'
17
- task 'man' do
23
+ task :man => :environment do
18
24
  sh "ron -br5 --manual='Ron Manual' --organization='Ryan Tomayko' man/*.ron"
19
25
  end
20
26
 
@@ -78,3 +84,11 @@ file 'ron.gemspec' => FileList['{lib,test}/**','Rakefile'] do |f|
78
84
  File.open(f.name, 'w') { |io| io.write(spec) }
79
85
  puts "updated #{f.name}"
80
86
  end
87
+
88
+ # Misc ===============================================================
89
+
90
+ def require_library(name)
91
+ require name
92
+ rescue LoadError => boom
93
+ abort "fatal: the '#{name}' library is required (gem install #{name})"
94
+ end
data/bin/ron CHANGED
@@ -14,7 +14,7 @@
14
14
  ## -m, --man open man page like man(1)
15
15
  ##
16
16
  ## Formats:
17
- ## --roff generate roff/man text; this is the default behavior
17
+ ## -r, --roff generate roff/man text; this is the default behavior
18
18
  ## -5, --html generate entire HTML page with layout
19
19
  ## -f, --fragment generate HTML fragment instead of entire HTML page
20
20
  ##
@@ -28,6 +28,7 @@
28
28
  ##
29
29
  ## --help show this help message
30
30
  ##
31
+ require 'date'
31
32
  require 'optparse'
32
33
 
33
34
  formats = []
@@ -78,16 +79,20 @@ elsif ARGV.empty?
78
79
  ARGV.push '-'
79
80
  end
80
81
 
81
- # turn the --date arg into
82
- if options[:date]
83
- options[:date] = Date.strptime(options[:date], '%Y-%m-%d')
84
- end
82
+ # turn the --date arg into a real date object
83
+ options[:date] &&= Date.strptime(options[:date], '%Y-%m-%d')
85
84
 
86
85
  formats = ['roff'] if formats.empty?
87
86
  formats.delete('html') if formats.include?('html_fragment')
88
87
  pid = nil
89
88
 
90
- require 'ron'
89
+ begin
90
+ require 'ron'
91
+ rescue LoadError
92
+ $:.unshift File.dirname(__FILE__) + "../lib"
93
+ require 'ron'
94
+ end
95
+
91
96
  wr = STDOUT
92
97
  ARGV.each do |file|
93
98
  doc = Ron.new(file, options) { file == '-' ? STDIN.read : File.read(file) }
@@ -106,12 +111,14 @@ ARGV.each do |file|
106
111
 
107
112
  # write output for each format
108
113
  formats.each do |format|
109
- output = doc.convert(format)
110
114
  if build
111
115
  path = doc.path_for(format)
112
- info "building: #{path}"
116
+ info "building: #{path}" if build
117
+ output = doc.convert(format)
113
118
  File.open(path, 'wb') { |f| f.puts(output) }
119
+ system "man #{path}" if man && format == 'roff'
114
120
  else
121
+ output = doc.convert(format)
115
122
  wr.puts(output)
116
123
  end
117
124
  end
data/lib/ron.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # install standard UNIX roff(7) formatted manpages or to generate
4
4
  # beautiful HTML manpages.
5
5
  module Ron
6
- VERSION = '0.2'
6
+ VERSION = '0.3'
7
7
 
8
8
  require 'ron/document'
9
9
  require 'ron/roff'
data/lib/ron/document.rb CHANGED
@@ -99,7 +99,7 @@ module Ron
99
99
  # Truthful when the name was extracted from the name section
100
100
  # of the document.
101
101
  def name?
102
- @name
102
+ !name.nil?
103
103
  end
104
104
 
105
105
  # Returns the manual page section based first on the document's
@@ -111,7 +111,7 @@ module Ron
111
111
  # True when the section number was extracted from the name
112
112
  # section of the document.
113
113
  def section?
114
- @section
114
+ !section.nil?
115
115
  end
116
116
 
117
117
  # The date the man page was published. If not set explicitly,
data/lib/ron/layout.html CHANGED
@@ -9,22 +9,27 @@
9
9
  #man, #man code, #man pre, #man tt, #man kbd, #man samp {
10
10
  font-family:consolas,monospace;
11
11
  font-size:16px;
12
- line-height:1.25;
13
- color:#434241;
12
+ line-height:1.3;
13
+ color:#343331;
14
14
  background:#fff; }
15
- #man { max-width:85ex; text-align:justify; margin:0 25px 25px 25px }
15
+ #man { max-width:89ex; text-align:justify; margin:0 25px 25px 25px }
16
16
  #man h1, #man h2, #man h3 { color:#232221;clear:left }
17
- #man h1 { font-size:28px; margin:10px 0 30px 0; text-align:center }
18
- #man h2 { font-size:18px; margin-bottom:2px; margin-top:10px; line-height:1.2; }
17
+ #man h1 { font-size:28px; margin:15px 0 30px 0; text-align:center }
18
+ #man h2 { font-size:18px; margin-bottom:0; margin-top:10px; line-height:1.3; }
19
19
  #man h3 { font-size:16px; margin:0 0 0 4ex; }
20
20
  #man p, #man ul, #man ol, #man dl, #man pre { margin:0 0 18px 0; }
21
21
  #man pre {
22
22
  color:#333231;
23
23
  background:#edeceb;
24
- padding:5px 10px;
25
- border-left:2ex solid #ddd;
26
- margin-top:-10px;
27
- margin-bottom:12px; }
24
+ padding:5px 7px;
25
+ margin:0px 0 20px 0;
26
+ border-left:2ex solid #ddd}
27
+ #man pre + h2, #man pre + h3 {
28
+ margin-top:22px;
29
+ }
30
+ #man h2 + pre, #man h3 + pre {
31
+ margin-top:5px;
32
+ }
28
33
  #man > p, #man > ul, #man > ol, #man > dl, #man > pre { margin-left:8ex; }
29
34
  #man dt { margin:0; clear:left }
30
35
  #man dt.flush { float:left; width:8ex }
data/lib/ron/roff.rb CHANGED
@@ -18,7 +18,7 @@ module Ron
18
18
  def title_heading(name, section, tagline, manual, version, date)
19
19
  comment "generated with Ron/v#{Ron::VERSION}"
20
20
  comment "http://github.com/rtomayko/ron/"
21
- macro "TH", %["#{escape(name.upcase)}" #{section} "#{date.strftime('%B %Y')}" "#{version}" "#{manual}"]
21
+ macro "TH", %["#{escape(name.upcase)}" "#{section}" "#{date.strftime('%B %Y')}" "#{version}" "#{manual}"]
22
22
  end
23
23
 
24
24
  def block_filter(node)
@@ -54,9 +54,13 @@ module Ron
54
54
  end
55
55
  inline_filter(node.children)
56
56
  when 'pre'
57
+ indent = prev.nil? || !%w[h1 h2 h3].include?(prev.name)
58
+ macro "IP", %w["" 4] if indent
57
59
  macro "nf"
60
+ write "\n"
58
61
  inline_filter(node.search('code').children)
59
62
  macro "fi"
63
+ macro "IP", %w["" 0] if indent
60
64
 
61
65
  # definition lists
62
66
  when 'dl'
@@ -75,20 +79,23 @@ module Ron
75
79
  write "\n"
76
80
 
77
81
  # ordered/unordered lists
78
- # when 'ul'
79
- # # macro "IP", '\(bu'
80
- # block_filter(node.children)
81
82
  # when 'ol'
82
83
  # macro "IP", '1.'
83
84
  # block_filter(node.children)
84
- # when 'li'
85
- # macro "IP" unless prev.nil?
86
- # if node.search('p').any?
87
- # block_filter(node.children)
88
- # else
89
- # inline_filter(node.children)
90
- # end
91
- # write "\n"
85
+ when 'ul'
86
+ block_filter(node.children)
87
+ macro "IP", %w["" 0]
88
+ when 'li'
89
+ case node.parent.name
90
+ when 'ul'
91
+ macro "IP", %w["\(bu" 4]
92
+ end
93
+ if node.search('p', 'ol', 'ul', 'dl', 'div').any?
94
+ block_filter(node.children)
95
+ else
96
+ inline_filter(node.children)
97
+ end
98
+ write "\n"
92
99
 
93
100
  else
94
101
  warn "unrecognized block tag: %p", node.name
@@ -106,9 +113,14 @@ module Ron
106
113
 
107
114
  case node.name
108
115
  when 'text'
109
- text = node.content
110
- text = text.sub(/^\n+/m, '') if prev && prev.name == 'br'
111
- write escape(text.sub(/\n+$/, ' '))
116
+ text = node.content.dup
117
+ text.sub!(/^\n+/m, '') if prev && prev.name == 'br'
118
+ if node.previous_sibling.nil? && node.next_sibling
119
+ text.sub!(/\n+$/m, '')
120
+ else
121
+ text.sub!(/\n+$/m, ' ')
122
+ end
123
+ write escape(text)
112
124
  when 'code', 'b', 'strong', 'kbd', 'samp'
113
125
  write '\fB'
114
126
  inline_filter(node.children)
@@ -147,7 +159,7 @@ module Ron
147
159
 
148
160
  # write text to output buffer
149
161
  def write(text)
150
- @buf << text
162
+ @buf << text unless text.nil? || text.empty?
151
163
  end
152
164
 
153
165
  # write text to output buffer on a new line.
data/man/markdown.5 ADDED
@@ -0,0 +1,1614 @@
1
+ .\" generated with Ron/v0.2
2
+ .\" http://github.com/rtomayko/ron/
3
+ .
4
+ .TH "MARKDOWN" "5" "December 2009" "Ryan Tomayko" "Ron Manual"
5
+ .
6
+ .SH "NAME"
7
+ \fBmarkdown\fR \-\- humane markup syntax
8
+ .
9
+ .SH "SYNOPSIS"
10
+ .
11
+ .nf
12
+
13
+ # Header 1 #
14
+ ## Header 2 ##
15
+ ### Header 3 ### (Hashes on right are optional)
16
+ #### Header 4 ####
17
+ ##### Header 5 #####
18
+ This is a paragraph, which is text surrounded by whitespace.
19
+ Paragraphs can be on one line (or many), and can drone on for
20
+ hours.
21
+
22
+ [Reference style links][1] and [inline links](http://example.com)
23
+ [1]: http://example.com "Title is optional"
24
+
25
+ Inline markup like _italics_, **bold**, and `code()`.
26
+
27
+ ![picture alt](/images/photo.jpeg "Title is optional")
28
+
29
+ > Blockquotes are like quoted text in email replies
30
+ >> And, they can be nested
31
+
32
+ code blocks are for preformatted
33
+ text and must be indented with four spaces
34
+
35
+ * Bullet lists are easy too
36
+ * You can
37
+ * even
38
+ * nest them
39
+ \- Another one
40
+ + Another one
41
+ .
42
+ .fi
43
+ .
44
+ .SH "DESCRIPTION"
45
+ .
46
+ .SS "Philosophy"
47
+ Markdown is intended to be as easy\-to\-read and easy\-to\-write as is feasible.
48
+ .
49
+ .P
50
+ Readability, however, is emphasized above all else. A Markdown\-formatted
51
+ document should be publishable as\-is, as plain text, without looking
52
+ like it's been marked up with tags or formatting instructions. While
53
+ Markdown's syntax has been influenced by several existing text\-to\-HTML
54
+ filters \-\- including \fISetext\fR, \fIatx\fR, \fITextile\fR, \fIreStructuredText\fR, \fIGrutatext\fR, and \fIEtText\fR \-\- the single biggest source of
55
+ inspiration for Markdown's syntax is the format of plain text email.
56
+ .
57
+ .P
58
+ To this end, Markdown's syntax is comprised entirely of punctuation
59
+ characters, which punctuation characters have been carefully chosen so
60
+ as to look like what they mean. E.g., asterisks around a word actually
61
+ look like *emphasis*. Markdown lists look like, well, lists. Even
62
+ blockquotes look like quoted passages of text, assuming you've ever
63
+ used email.
64
+ .
65
+ .SS "Inline HTML"
66
+ Markdown's syntax is intended for one purpose: to be used as a
67
+ format for \fIwriting\fR for the web.
68
+ .
69
+ .P
70
+ Markdown is not a replacement for HTML, or even close to it. Its
71
+ syntax is very small, corresponding only to a very small subset of
72
+ HTML tags. The idea is \fInot\fR to create a syntax that makes it easier
73
+ to insert HTML tags. In my opinion, HTML tags are already easy to
74
+ insert. The idea for Markdown is to make it easy to read, write, and
75
+ edit prose. HTML is a \fIpublishing\fR format; Markdown is a \fIwriting\fR
76
+ format. Thus, Markdown's formatting syntax only addresses issues that
77
+ can be conveyed in plain text.
78
+ .
79
+ .P
80
+ For any markup that is not covered by Markdown's syntax, you simply
81
+ use HTML itself. There's no need to preface it or delimit it to
82
+ indicate that you're switching from Markdown to HTML; you just use
83
+ the tags.
84
+ .
85
+ .P
86
+ The only restrictions are that block\-level HTML elements \-\- e.g. \fB<div>\fR, \fB<table>\fR, \fB<pre>\fR, \fB<p>\fR, etc. \-\- must be separated from surrounding
87
+ content by blank lines, and the start and end tags of the block should
88
+ not be indented with tabs or spaces. Markdown is smart enough not
89
+ to add extra (unwanted) \fB<p>\fR tags around HTML block\-level tags.
90
+ .
91
+ .P
92
+ For example, to add an HTML table to a Markdown article:
93
+ .
94
+ .IP "" 4
95
+ .
96
+ .nf
97
+
98
+ This is a regular paragraph.
99
+ <table>
100
+ <tr>
101
+ <td>Foo</td>
102
+ </tr>
103
+ </table>
104
+
105
+ This is another regular paragraph.
106
+ .
107
+ .fi
108
+ .
109
+ .IP "" 0
110
+ .
111
+ .P
112
+ Note that Markdown formatting syntax is not processed within block\-level
113
+ HTML tags. E.g., you can't use Markdown\-style \fB*emphasis*\fR inside an
114
+ HTML block.
115
+ .
116
+ .P
117
+ Span\-level HTML tags \-\- e.g. \fB<span>\fR, \fB<cite>\fR, or \fB<del>\fR \-\- can be
118
+ used anywhere in a Markdown paragraph, list item, or header. If you
119
+ want, you can even use HTML tags instead of Markdown formatting; e.g. if
120
+ you'd prefer to use HTML \fB<a>\fR or \fB<img>\fR tags instead of Markdown's
121
+ link or image syntax, go right ahead.
122
+ .
123
+ .P
124
+ Unlike block\-level HTML tags, Markdown syntax \fIis\fR processed within
125
+ span\-level tags.
126
+ .
127
+ .SS "Automatic Escaping for Special Characters"
128
+ In HTML, there are two characters that demand special treatment: \fB<\fR
129
+ and \fB&\fR. Left angle brackets are used to start tags; ampersands are
130
+ used to denote HTML entities. If you want to use them as literal
131
+ characters, you must escape them as entities, e.g. \fB<\fR, and \fB&\fR.
132
+ .
133
+ .P
134
+ Ampersands in particular are bedeviling for web writers. If you want to
135
+ write about 'AT&T', you need to write '\fBAT&T\fR'. You even need to
136
+ escape ampersands within URLs. Thus, if you want to link to:
137
+ .
138
+ .IP "" 4
139
+ .
140
+ .nf
141
+
142
+ http://images.google.com/images?num=30&q=larry+bird
143
+ .
144
+ .fi
145
+ .
146
+ .IP "" 0
147
+ .
148
+ .P
149
+ you need to encode the URL as:
150
+ .
151
+ .IP "" 4
152
+ .
153
+ .nf
154
+
155
+ http://images.google.com/images?num=30&q=larry+bird
156
+ .
157
+ .fi
158
+ .
159
+ .IP "" 0
160
+ .
161
+ .P
162
+ in your anchor tag \fBhref\fR attribute. Needless to say, this is easy to
163
+ forget, and is probably the single most common source of HTML validation
164
+ errors in otherwise well\-marked\-up web sites.
165
+ .
166
+ .P
167
+ Markdown allows you to use these characters naturally, taking care of
168
+ all the necessary escaping for you. If you use an ampersand as part of
169
+ an HTML entity, it remains unchanged; otherwise it will be translated
170
+ into \fB&\fR.
171
+ .
172
+ .P
173
+ So, if you want to include a copyright symbol in your article, you can write:
174
+ .
175
+ .IP "" 4
176
+ .
177
+ .nf
178
+
179
+ &copy;
180
+ .
181
+ .fi
182
+ .
183
+ .IP "" 0
184
+ .
185
+ .P
186
+ and Markdown will leave it alone. But if you write:
187
+ .
188
+ .IP "" 4
189
+ .
190
+ .nf
191
+
192
+ AT&T
193
+ .
194
+ .fi
195
+ .
196
+ .IP "" 0
197
+ .
198
+ .P
199
+ Markdown will translate it to:
200
+ .
201
+ .IP "" 4
202
+ .
203
+ .nf
204
+
205
+ AT&T
206
+ .
207
+ .fi
208
+ .
209
+ .IP "" 0
210
+ .
211
+ .P
212
+ Similarly, because Markdown supports \fIinline HTML\fR, if you use
213
+ angle brackets as delimiters for HTML tags, Markdown will treat them as
214
+ such. But if you write:
215
+ .
216
+ .IP "" 4
217
+ .
218
+ .nf
219
+
220
+ 4 < 5
221
+ .
222
+ .fi
223
+ .
224
+ .IP "" 0
225
+ .
226
+ .P
227
+ Markdown will translate it to:
228
+ .
229
+ .IP "" 4
230
+ .
231
+ .nf
232
+
233
+ 4 < 5
234
+ .
235
+ .fi
236
+ .
237
+ .IP "" 0
238
+ .
239
+ .P
240
+ However, inside Markdown code spans and blocks, angle brackets and
241
+ ampersands are \fIalways\fR encoded automatically. This makes it easy to use
242
+ Markdown to write about HTML code. (As opposed to raw HTML, which is a
243
+ terrible format for writing about HTML syntax, because every single \fB<\fR
244
+ and \fB&\fR in your example code needs to be escaped.)
245
+ .
246
+ .SH "BLOCK ELEMENTS"
247
+ .
248
+ .SS "Paragraphs and Line Breaks"
249
+ A paragraph is simply one or more consecutive lines of text, separated
250
+ by one or more blank lines. (A blank line is any line that looks like a
251
+ blank line \-\- a line containing nothing but spaces or tabs is considered
252
+ blank.) Normal paragraphs should not be indented with spaces or tabs.
253
+ .
254
+ .P
255
+ The implication of the "one or more consecutive lines of text" rule is
256
+ that Markdown supports "hard\-wrapped" text paragraphs. This differs
257
+ significantly from most other text\-to\-HTML formatters (including Movable
258
+ Type's "Convert Line Breaks" option) which translate every line break
259
+ character in a paragraph into a \fB<br />\fR tag.
260
+ .
261
+ .P
262
+ When you \fIdo\fR want to insert a \fB<br />\fR break tag using Markdown, you
263
+ end a line with two or more spaces, then type return.
264
+ .
265
+ .P
266
+ Yes, this takes a tad more effort to create a \fB<br />\fR, but a simplistic
267
+ "every line break is a \fB<br />\fR" rule wouldn't work for Markdown.
268
+ Markdown's email\-style \fIblockquoting\fR and multi\-paragraph \fIlist items\fR
269
+ work best \-\- and look better \-\- when you format them with hard breaks.
270
+ .
271
+ .SS "Headers"
272
+ Markdown supports two styles of headers, \fISetext\fR and \fIatx\fR.
273
+ .
274
+ .P
275
+ Setext\-style headers are "underlined" using equal signs (for first\-level
276
+ headers) and dashes (for second\-level headers). For example:
277
+ .
278
+ .IP "" 4
279
+ .
280
+ .nf
281
+
282
+ This is an H1
283
+ =============
284
+ This is an H2
285
+ \-\-\-\-\-\-\-\-\-\-\-\-\-
286
+ .
287
+ .fi
288
+ .
289
+ .IP "" 0
290
+ .
291
+ .P
292
+ Any number of underlining \fB=\fR's or \fB\-\fR's will work.
293
+ .
294
+ .P
295
+ Atx\-style headers use 1\-6 hash characters at the start of the line,
296
+ corresponding to header levels 1\-6. For example:
297
+ .
298
+ .IP "" 4
299
+ .
300
+ .nf
301
+
302
+ # This is an H1
303
+ ## This is an H2
304
+
305
+ ###### This is an H6
306
+ .
307
+ .fi
308
+ .
309
+ .IP "" 0
310
+ .
311
+ .P
312
+ Optionally, you may "close" atx\-style headers. This is purely
313
+ cosmetic \-\- you can use this if you think it looks better. The
314
+ closing hashes don't even need to match the number of hashes
315
+ used to open the header. (The number of opening hashes
316
+ determines the header level.) :
317
+ .
318
+ .IP "" 4
319
+ .
320
+ .nf
321
+
322
+ # This is an H1 #
323
+ ## This is an H2 ##
324
+
325
+ ### This is an H3 ######
326
+ .
327
+ .fi
328
+ .
329
+ .IP "" 0
330
+ .
331
+ .SS "Blockquotes"
332
+ Markdown uses email\-style \fB>\fR characters for blockquoting. If you're
333
+ familiar with quoting passages of text in an email message, then you
334
+ know how to create a blockquote in Markdown. It looks best if you hard
335
+ wrap the text and put a \fB>\fR before every line:
336
+ .
337
+ .IP "" 4
338
+ .
339
+ .nf
340
+
341
+ > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
342
+ > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
343
+ > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
344
+ >
345
+ > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
346
+ > id sem consectetuer libero luctus adipiscing.
347
+ .
348
+ .fi
349
+ .
350
+ .IP "" 0
351
+ .
352
+ .P
353
+ Markdown allows you to be lazy and only put the \fB>\fR before the first
354
+ line of a hard\-wrapped paragraph:
355
+ .
356
+ .IP "" 4
357
+ .
358
+ .nf
359
+
360
+ > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
361
+ consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
362
+ Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
363
+ > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
364
+ id sem consectetuer libero luctus adipiscing.
365
+ .
366
+ .fi
367
+ .
368
+ .IP "" 0
369
+ .
370
+ .P
371
+ Blockquotes can be nested (i.e. a blockquote\-in\-a\-blockquote) by
372
+ adding additional levels of \fB>\fR:
373
+ .
374
+ .IP "" 4
375
+ .
376
+ .nf
377
+
378
+ > This is the first level of quoting.
379
+ >
380
+ > > This is nested blockquote.
381
+ >
382
+ > Back to the first level.
383
+ .
384
+ .fi
385
+ .
386
+ .IP "" 0
387
+ .
388
+ .P
389
+ Blockquotes can contain other Markdown elements, including headers, lists,
390
+ and code blocks:
391
+ .
392
+ .IP "" 4
393
+ .
394
+ .nf
395
+
396
+ > ## This is a header.
397
+ >
398
+ > 1. This is the first list item.
399
+ > 2. This is the second list item.
400
+ >
401
+ > Here's some example code:
402
+ >
403
+ > return shell_exec("echo $input | $markdown_script");
404
+ .
405
+ .fi
406
+ .
407
+ .IP "" 0
408
+ .
409
+ .P
410
+ Any decent text editor should make email\-style quoting easy. For
411
+ example, with BBEdit, you can make a selection and choose Increase
412
+ Quote Level from the Text menu.
413
+ .
414
+ .SS "Lists"
415
+ Markdown supports ordered (numbered) and unordered (bulleted) lists.
416
+ .
417
+ .P
418
+ Unordered lists use asterisks, pluses, and hyphens \-\- interchangably
419
+ \-\- as list markers:
420
+ .
421
+ .IP "" 4
422
+ .
423
+ .nf
424
+
425
+ * Red
426
+ * Green
427
+ * Blue
428
+ .
429
+ .fi
430
+ .
431
+ .IP "" 0
432
+ .
433
+ .P
434
+ is equivalent to:
435
+ .
436
+ .IP "" 4
437
+ .
438
+ .nf
439
+
440
+ + Red
441
+ + Green
442
+ + Blue
443
+ .
444
+ .fi
445
+ .
446
+ .IP "" 0
447
+ .
448
+ .P
449
+ and:
450
+ .
451
+ .IP "" 4
452
+ .
453
+ .nf
454
+
455
+ \- Red
456
+ \- Green
457
+ \- Blue
458
+ .
459
+ .fi
460
+ .
461
+ .IP "" 0
462
+ .
463
+ .P
464
+ Ordered lists use numbers followed by periods:
465
+ .
466
+ .IP "" 4
467
+ .
468
+ .nf
469
+
470
+ 1. Bird
471
+ 2. McHale
472
+ 3. Parish
473
+ .
474
+ .fi
475
+ .
476
+ .IP "" 0
477
+ .
478
+ .P
479
+ It's important to note that the actual numbers you use to mark the
480
+ list have no effect on the HTML output Markdown produces. The HTML
481
+ Markdown produces from the above list is:
482
+ .
483
+ .IP "" 4
484
+ .
485
+ .nf
486
+
487
+ <ol>
488
+ <li>Bird</li>
489
+ <li>McHale</li>
490
+ <li>Parish</li>
491
+ </ol>
492
+ .
493
+ .fi
494
+ .
495
+ .IP "" 0
496
+ .
497
+ .P
498
+ If you instead wrote the list in Markdown like this:
499
+ .
500
+ .IP "" 4
501
+ .
502
+ .nf
503
+
504
+ 1. Bird
505
+ 1. McHale
506
+ 1. Parish
507
+ .
508
+ .fi
509
+ .
510
+ .IP "" 0
511
+ .
512
+ .P
513
+ or even:
514
+ .
515
+ .IP "" 4
516
+ .
517
+ .nf
518
+
519
+ 3. Bird
520
+ 1. McHale
521
+ 8. Parish
522
+ .
523
+ .fi
524
+ .
525
+ .IP "" 0
526
+ .
527
+ .P
528
+ you'd get the exact same HTML output. The point is, if you want to,
529
+ you can use ordinal numbers in your ordered Markdown lists, so that
530
+ the numbers in your source match the numbers in your published HTML.
531
+ But if you want to be lazy, you don't have to.
532
+ .
533
+ .P
534
+ If you do use lazy list numbering, however, you should still start the
535
+ list with the number 1. At some point in the future, Markdown may support
536
+ starting ordered lists at an arbitrary number.
537
+ .
538
+ .P
539
+ List markers typically start at the left margin, but may be indented by
540
+ up to three spaces. List markers must be followed by one or more spaces
541
+ or a tab.
542
+ .
543
+ .P
544
+ To make lists look nice, you can wrap items with hanging indents:
545
+ .
546
+ .IP "" 4
547
+ .
548
+ .nf
549
+
550
+ * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
551
+ Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
552
+ viverra nec, fringilla in, laoreet vitae, risus.
553
+ * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
554
+ Suspendisse id sem consectetuer libero luctus adipiscing.
555
+ .
556
+ .fi
557
+ .
558
+ .IP "" 0
559
+ .
560
+ .P
561
+ But if you want to be lazy, you don't have to:
562
+ .
563
+ .IP "" 4
564
+ .
565
+ .nf
566
+
567
+ * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
568
+ Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
569
+ viverra nec, fringilla in, laoreet vitae, risus.
570
+ * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
571
+ Suspendisse id sem consectetuer libero luctus adipiscing.
572
+ .
573
+ .fi
574
+ .
575
+ .IP "" 0
576
+ .
577
+ .P
578
+ If list items are separated by blank lines, Markdown will wrap the
579
+ items in \fB<p>\fR tags in the HTML output. For example, this input:
580
+ .
581
+ .IP "" 4
582
+ .
583
+ .nf
584
+
585
+ * Bird
586
+ * Magic
587
+ .
588
+ .fi
589
+ .
590
+ .IP "" 0
591
+ .
592
+ .P
593
+ will turn into:
594
+ .
595
+ .IP "" 4
596
+ .
597
+ .nf
598
+
599
+ <ul>
600
+ <li>Bird</li>
601
+ <li>Magic</li>
602
+ </ul>
603
+ .
604
+ .fi
605
+ .
606
+ .IP "" 0
607
+ .
608
+ .P
609
+ But this:
610
+ .
611
+ .IP "" 4
612
+ .
613
+ .nf
614
+
615
+ * Bird
616
+ * Magic
617
+ .
618
+ .fi
619
+ .
620
+ .IP "" 0
621
+ .
622
+ .P
623
+ will turn into:
624
+ .
625
+ .IP "" 4
626
+ .
627
+ .nf
628
+
629
+ <ul>
630
+ <li><p>Bird</p></li>
631
+ <li><p>Magic</p></li>
632
+ </ul>
633
+ .
634
+ .fi
635
+ .
636
+ .IP "" 0
637
+ .
638
+ .P
639
+ List items may consist of multiple paragraphs. Each subsequent
640
+ paragraph in a list item must be indented by either 4 spaces
641
+ or one tab:
642
+ .
643
+ .IP "" 4
644
+ .
645
+ .nf
646
+
647
+ 1. This is a list item with two paragraphs. Lorem ipsum dolor
648
+ sit amet, consectetuer adipiscing elit. Aliquam hendrerit
649
+ mi posuere lectus.
650
+ Vestibulum enim wisi, viverra nec, fringilla in, laoreet
651
+ vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
652
+ sit amet velit.
653
+
654
+ 2. Suspendisse id sem consectetuer libero luctus adipiscing.
655
+ .
656
+ .fi
657
+ .
658
+ .IP "" 0
659
+ .
660
+ .P
661
+ It looks nice if you indent every line of the subsequent
662
+ paragraphs, but here again, Markdown will allow you to be
663
+ lazy:
664
+ .
665
+ .IP "" 4
666
+ .
667
+ .nf
668
+
669
+ * This is a list item with two paragraphs.
670
+ This is the second paragraph in the list item. You're
671
+ only required to indent the first line. Lorem ipsum dolor
672
+ sit amet, consectetuer adipiscing elit.
673
+
674
+ * Another item in the same list.
675
+ .
676
+ .fi
677
+ .
678
+ .IP "" 0
679
+ .
680
+ .P
681
+ To put a blockquote within a list item, the blockquote's \fB>\fR
682
+ delimiters need to be indented:
683
+ .
684
+ .IP "" 4
685
+ .
686
+ .nf
687
+
688
+ * A list item with a blockquote:
689
+ > This is a blockquote
690
+ > inside a list item.
691
+ .
692
+ .fi
693
+ .
694
+ .IP "" 0
695
+ .
696
+ .P
697
+ To put a code block within a list item, the code block needs
698
+ to be indented \fItwice\fR \-\- 8 spaces or two tabs:
699
+ .
700
+ .IP "" 4
701
+ .
702
+ .nf
703
+
704
+ * A list item with a code block:
705
+ <code goes here>
706
+ .
707
+ .fi
708
+ .
709
+ .IP "" 0
710
+ .
711
+ .P
712
+ It's worth noting that it's possible to trigger an ordered list by
713
+ accident, by writing something like this:
714
+ .
715
+ .IP "" 4
716
+ .
717
+ .nf
718
+
719
+ 1986. What a great season.
720
+ .
721
+ .fi
722
+ .
723
+ .IP "" 0
724
+ .
725
+ .P
726
+ In other words, a \fInumber\-period\-space\fR sequence at the beginning of a
727
+ line. To avoid this, you can backslash\-escape the period:
728
+ .
729
+ .IP "" 4
730
+ .
731
+ .nf
732
+
733
+ 1986\\. What a great season.
734
+ .
735
+ .fi
736
+ .
737
+ .IP "" 0
738
+ .
739
+ .SS "Code Blocks"
740
+ Pre\-formatted code blocks are used for writing about programming or
741
+ markup source code. Rather than forming normal paragraphs, the lines
742
+ of a code block are interpreted literally. Markdown wraps a code block
743
+ in both \fB<pre>\fR and \fB<code>\fR tags.
744
+ .
745
+ .P
746
+ To produce a code block in Markdown, simply indent every line of the
747
+ block by at least 4 spaces or 1 tab. For example, given this input:
748
+ .
749
+ .IP "" 4
750
+ .
751
+ .nf
752
+
753
+ This is a normal paragraph:
754
+ This is a code block.
755
+ .
756
+ .fi
757
+ .
758
+ .IP "" 0
759
+ .
760
+ .P
761
+ Markdown will generate:
762
+ .
763
+ .IP "" 4
764
+ .
765
+ .nf
766
+
767
+ <p>This is a normal paragraph:</p>
768
+ <pre><code>This is a code block.
769
+ </code></pre>
770
+ .
771
+ .fi
772
+ .
773
+ .IP "" 0
774
+ .
775
+ .P
776
+ One level of indentation \-\- 4 spaces or 1 tab \-\- is removed from each
777
+ line of the code block. For example, this:
778
+ .
779
+ .IP "" 4
780
+ .
781
+ .nf
782
+
783
+ Here is an example of AppleScript:
784
+ tell application "Foo"
785
+ beep
786
+ end tell
787
+ .
788
+ .fi
789
+ .
790
+ .IP "" 0
791
+ .
792
+ .P
793
+ will turn into:
794
+ .
795
+ .IP "" 4
796
+ .
797
+ .nf
798
+
799
+ <p>Here is an example of AppleScript:</p>
800
+ <pre><code>tell application "Foo"
801
+ beep
802
+ end tell
803
+ </code></pre>
804
+ .
805
+ .fi
806
+ .
807
+ .IP "" 0
808
+ .
809
+ .P
810
+ A code block continues until it reaches a line that is not indented
811
+ (or the end of the article).
812
+ .
813
+ .P
814
+ Within a code block, ampersands (\fB&\fR) and angle brackets (\fB<\fR and \fB>\fR)
815
+ are automatically converted into HTML entities. This makes it very
816
+ easy to include example HTML source code using Markdown \-\- just paste
817
+ it and indent it, and Markdown will handle the hassle of encoding the
818
+ ampersands and angle brackets. For example, this:
819
+ .
820
+ .IP "" 4
821
+ .
822
+ .nf
823
+
824
+ <div class="footer">
825
+ &copy; 2004 Foo Corporation
826
+ </div>
827
+ .
828
+ .fi
829
+ .
830
+ .IP "" 0
831
+ .
832
+ .P
833
+ will turn into:
834
+ .
835
+ .IP "" 4
836
+ .
837
+ .nf
838
+
839
+ <pre><code><div class="footer">
840
+ &copy; 2004 Foo Corporation
841
+ </div>
842
+ </code></pre>
843
+ .
844
+ .fi
845
+ .
846
+ .IP "" 0
847
+ .
848
+ .P
849
+ Regular Markdown syntax is not processed within code blocks. E.g.,
850
+ asterisks are just literal asterisks within a code block. This means
851
+ it's also easy to use Markdown to write about Markdown's own syntax.
852
+ .
853
+ .SS "Horizontal Rules"
854
+ You can produce a horizontal rule tag (\fB<hr />\fR) by placing three or
855
+ more hyphens, asterisks, or underscores on a line by themselves. If you
856
+ wish, you may use spaces between the hyphens or asterisks. Each of the
857
+ following lines will produce a horizontal rule:
858
+ .
859
+ .IP "" 4
860
+ .
861
+ .nf
862
+
863
+ * * *
864
+ ***
865
+
866
+ *****
867
+
868
+ \- \- \-
869
+
870
+ \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
871
+ .
872
+ .fi
873
+ .
874
+ .IP "" 0
875
+ .
876
+ .SH "SPAN ELEMENTS"
877
+ .
878
+ .SS "Links"
879
+ Markdown supports two style of links: \fIinline\fR and \fIreference\fR.
880
+ .
881
+ .P
882
+ In both styles, the link text is delimited by [square brackets].
883
+ .
884
+ .P
885
+ To create an inline link, use a set of regular parentheses immediately
886
+ after the link text's closing square bracket. Inside the parentheses,
887
+ put the URL where you want the link to point, along with an \fIoptional\fR
888
+ title for the link, surrounded in quotes. For example:
889
+ .
890
+ .IP "" 4
891
+ .
892
+ .nf
893
+
894
+ This is [an example](http://example.com/ "Title") inline link.
895
+ [This link](http://example.net/) has no title attribute.
896
+ .
897
+ .fi
898
+ .
899
+ .IP "" 0
900
+ .
901
+ .P
902
+ Will produce:
903
+ .
904
+ .IP "" 4
905
+ .
906
+ .nf
907
+
908
+ <p>This is <a href="http://example.com/" title="Title">
909
+ an example</a> inline link.</p>
910
+ <p><a href="http://example.net/">This link</a> has no
911
+ title attribute.</p>
912
+ .
913
+ .fi
914
+ .
915
+ .IP "" 0
916
+ .
917
+ .P
918
+ If you're referring to a local resource on the same server, you can
919
+ use relative paths:
920
+ .
921
+ .IP "" 4
922
+ .
923
+ .nf
924
+
925
+ See my [About](/about/) page for details.
926
+ .
927
+ .fi
928
+ .
929
+ .IP "" 0
930
+ .
931
+ .P
932
+ Reference\-style links use a second set of square brackets, inside
933
+ which you place a label of your choosing to identify the link:
934
+ .
935
+ .IP "" 4
936
+ .
937
+ .nf
938
+
939
+ This is [an example][id] reference\-style link.
940
+ .
941
+ .fi
942
+ .
943
+ .IP "" 0
944
+ .
945
+ .P
946
+ You can optionally use a space to separate the sets of brackets:
947
+ .
948
+ .IP "" 4
949
+ .
950
+ .nf
951
+
952
+ This is [an example] [id] reference\-style link.
953
+ .
954
+ .fi
955
+ .
956
+ .IP "" 0
957
+ .
958
+ .P
959
+ Then, anywhere in the document, you define your link label like this,
960
+ on a line by itself:
961
+ .
962
+ .IP "" 4
963
+ .
964
+ .nf
965
+
966
+ [id]: http://example.com/ "Optional Title Here"
967
+ .
968
+ .fi
969
+ .
970
+ .IP "" 0
971
+ .
972
+ .P
973
+ That is:
974
+ .
975
+ .IP "\(bu" 4
976
+ Square brackets containing the link identifier (optionally
977
+ indented from the left margin using up to three spaces);
978
+ .
979
+ .IP "\(bu" 4
980
+ followed by a colon;
981
+ .
982
+ .IP "\(bu" 4
983
+ followed by one or more spaces (or tabs);
984
+ .
985
+ .IP "\(bu" 4
986
+ followed by the URL for the link;
987
+ .
988
+ .IP "\(bu" 4
989
+ optionally followed by a title attribute for the link, enclosed
990
+ in double or single quotes, or enclosed in parentheses.
991
+ .
992
+ .IP "" 0
993
+ .
994
+ .P
995
+ The following three link definitions are equivalent:
996
+ .
997
+ .IP "" 4
998
+ .
999
+ .nf
1000
+
1001
+ [foo]: http://example.com/ "Optional Title Here"
1002
+ [foo]: http://example.com/ 'Optional Title Here'
1003
+ [foo]: http://example.com/ (Optional Title Here)
1004
+ .
1005
+ .fi
1006
+ .
1007
+ .IP "" 0
1008
+ .
1009
+ .P
1010
+ \fBNote:\fR There is a known bug in Markdown.pl 1.0.1 which prevents
1011
+ single quotes from being used to delimit link titles.
1012
+ .
1013
+ .P
1014
+ The link URL may, optionally, be surrounded by angle brackets:
1015
+ .
1016
+ .IP "" 4
1017
+ .
1018
+ .nf
1019
+
1020
+ [id]: <http://example.com/> "Optional Title Here"
1021
+ .
1022
+ .fi
1023
+ .
1024
+ .IP "" 0
1025
+ .
1026
+ .P
1027
+ You can put the title attribute on the next line and use extra spaces
1028
+ or tabs for padding, which tends to look better with longer URLs:
1029
+ .
1030
+ .IP "" 4
1031
+ .
1032
+ .nf
1033
+
1034
+ [id]: http://example.com/longish/path/to/resource/here
1035
+ "Optional Title Here"
1036
+ .
1037
+ .fi
1038
+ .
1039
+ .IP "" 0
1040
+ .
1041
+ .P
1042
+ Link definitions are only used for creating links during Markdown
1043
+ processing, and are stripped from your document in the HTML output.
1044
+ .
1045
+ .P
1046
+ Link definition names may consist of letters, numbers, spaces, and
1047
+ punctuation \-\- but they are \fInot\fR case sensitive. E.g. these two
1048
+ links:
1049
+ .
1050
+ .IP "" 4
1051
+ .
1052
+ .nf
1053
+
1054
+ [link text][a]
1055
+ [link text][A]
1056
+ .
1057
+ .fi
1058
+ .
1059
+ .IP "" 0
1060
+ .
1061
+ .P
1062
+ are equivalent.
1063
+ .
1064
+ .P
1065
+ The \fIimplicit link name\fR shortcut allows you to omit the name of the
1066
+ link, in which case the link text itself is used as the name.
1067
+ Just use an empty set of square brackets \-\- e.g., to link the word
1068
+ "Google" to the google.com web site, you could simply write:
1069
+ .
1070
+ .IP "" 4
1071
+ .
1072
+ .nf
1073
+
1074
+ [Google][]
1075
+ .
1076
+ .fi
1077
+ .
1078
+ .IP "" 0
1079
+ .
1080
+ .P
1081
+ And then define the link:
1082
+ .
1083
+ .IP "" 4
1084
+ .
1085
+ .nf
1086
+
1087
+ [Google]: http://google.com/
1088
+ .
1089
+ .fi
1090
+ .
1091
+ .IP "" 0
1092
+ .
1093
+ .P
1094
+ Because link names may contain spaces, this shortcut even works for
1095
+ multiple words in the link text:
1096
+ .
1097
+ .IP "" 4
1098
+ .
1099
+ .nf
1100
+
1101
+ Visit [Daring Fireball][] for more information.
1102
+ .
1103
+ .fi
1104
+ .
1105
+ .IP "" 0
1106
+ .
1107
+ .P
1108
+ And then define the link:
1109
+ .
1110
+ .IP "" 4
1111
+ .
1112
+ .nf
1113
+
1114
+ [Daring Fireball]: http://daringfireball.net/
1115
+ .
1116
+ .fi
1117
+ .
1118
+ .IP "" 0
1119
+ .
1120
+ .P
1121
+ Link definitions can be placed anywhere in your Markdown document. I
1122
+ tend to put them immediately after each paragraph in which they're
1123
+ used, but if you want, you can put them all at the end of your
1124
+ document, sort of like footnotes.
1125
+ .
1126
+ .P
1127
+ Here's an example of reference links in action:
1128
+ .
1129
+ .IP "" 4
1130
+ .
1131
+ .nf
1132
+
1133
+ I get 10 times more traffic from [Google] [1] than from
1134
+ [Yahoo] [2] or [MSN] [3].
1135
+ [1]: http://google.com/ "Google"
1136
+ [2]: http://search.yahoo.com/ "Yahoo Search"
1137
+ [3]: http://search.msn.com/ "MSN Search"
1138
+ .
1139
+ .fi
1140
+ .
1141
+ .IP "" 0
1142
+ .
1143
+ .P
1144
+ Using the implicit link name shortcut, you could instead write:
1145
+ .
1146
+ .IP "" 4
1147
+ .
1148
+ .nf
1149
+
1150
+ I get 10 times more traffic from [Google][] than from
1151
+ [Yahoo][] or [MSN][].
1152
+ [google]: http://google.com/ "Google"
1153
+ [yahoo]: http://search.yahoo.com/ "Yahoo Search"
1154
+ [msn]: http://search.msn.com/ "MSN Search"
1155
+ .
1156
+ .fi
1157
+ .
1158
+ .IP "" 0
1159
+ .
1160
+ .P
1161
+ Both of the above examples will produce the following HTML output:
1162
+ .
1163
+ .IP "" 4
1164
+ .
1165
+ .nf
1166
+
1167
+ <p>I get 10 times more traffic from <a href="http://google.com/"
1168
+ title="Google">Google</a> than from
1169
+ <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
1170
+ or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
1171
+ .
1172
+ .fi
1173
+ .
1174
+ .IP "" 0
1175
+ .
1176
+ .P
1177
+ For comparison, here is the same paragraph written using
1178
+ Markdown's inline link style:
1179
+ .
1180
+ .IP "" 4
1181
+ .
1182
+ .nf
1183
+
1184
+ I get 10 times more traffic from [Google](http://google.com/ "Google")
1185
+ than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
1186
+ [MSN](http://search.msn.com/ "MSN Search").
1187
+ .
1188
+ .fi
1189
+ .
1190
+ .IP "" 0
1191
+ .
1192
+ .P
1193
+ The point of reference\-style links is not that they're easier to
1194
+ write. The point is that with reference\-style links, your document
1195
+ source is vastly more readable. Compare the above examples: using
1196
+ reference\-style links, the paragraph itself is only 81 characters
1197
+ long; with inline\-style links, it's 176 characters; and as raw HTML,
1198
+ it's 234 characters. In the raw HTML, there's more markup than there
1199
+ is text.
1200
+ .
1201
+ .P
1202
+ With Markdown's reference\-style links, a source document much more
1203
+ closely resembles the final output, as rendered in a browser. By
1204
+ allowing you to move the markup\-related metadata out of the paragraph,
1205
+ you can add links without interrupting the narrative flow of your
1206
+ prose.
1207
+ .
1208
+ .SS "Emphasis"
1209
+ Markdown treats asterisks (\fB*\fR) and underscores (\fB_\fR) as indicators of
1210
+ emphasis. Text wrapped with one \fB*\fR or \fB_\fR will be wrapped with an
1211
+ HTML \fB<em>\fR tag; double \fB*\fR's or \fB_\fR's will be wrapped with an HTML \fB<strong>\fR tag. E.g., this input:
1212
+ .
1213
+ .IP "" 4
1214
+ .
1215
+ .nf
1216
+
1217
+ *single asterisks*
1218
+ _single underscores_
1219
+
1220
+ **double asterisks**
1221
+
1222
+ __double underscores__
1223
+ .
1224
+ .fi
1225
+ .
1226
+ .IP "" 0
1227
+ .
1228
+ .P
1229
+ will produce:
1230
+ .
1231
+ .IP "" 4
1232
+ .
1233
+ .nf
1234
+
1235
+ <em>single asterisks</em>
1236
+ <em>single underscores</em>
1237
+
1238
+ <strong>double asterisks</strong>
1239
+
1240
+ <strong>double underscores</strong>
1241
+ .
1242
+ .fi
1243
+ .
1244
+ .IP "" 0
1245
+ .
1246
+ .P
1247
+ You can use whichever style you prefer; the lone restriction is that
1248
+ the same character must be used to open and close an emphasis span.
1249
+ .
1250
+ .P
1251
+ Emphasis can be used in the middle of a word:
1252
+ .
1253
+ .IP "" 4
1254
+ .
1255
+ .nf
1256
+
1257
+ un*frigging*believable
1258
+ .
1259
+ .fi
1260
+ .
1261
+ .IP "" 0
1262
+ .
1263
+ .P
1264
+ But if you surround an \fB*\fR or \fB_\fR with spaces, it'll be treated as a
1265
+ literal asterisk or underscore.
1266
+ .
1267
+ .P
1268
+ To produce a literal asterisk or underscore at a position where it
1269
+ would otherwise be used as an emphasis delimiter, you can backslash
1270
+ escape it:
1271
+ .
1272
+ .IP "" 4
1273
+ .
1274
+ .nf
1275
+
1276
+ \\*this text is surrounded by literal asterisks\\*
1277
+ .
1278
+ .fi
1279
+ .
1280
+ .IP "" 0
1281
+ .
1282
+ .SS "Code"
1283
+ To indicate a span of code, wrap it with backtick quotes (\fB`\fR).
1284
+ Unlike a pre\-formatted code block, a code span indicates code within a
1285
+ normal paragraph. For example:
1286
+ .
1287
+ .IP "" 4
1288
+ .
1289
+ .nf
1290
+
1291
+ Use the `printf()` function.
1292
+ .
1293
+ .fi
1294
+ .
1295
+ .IP "" 0
1296
+ .
1297
+ .P
1298
+ will produce:
1299
+ .
1300
+ .IP "" 4
1301
+ .
1302
+ .nf
1303
+
1304
+ <p>Use the <code>printf()</code> function.</p>
1305
+ .
1306
+ .fi
1307
+ .
1308
+ .IP "" 0
1309
+ .
1310
+ .P
1311
+ To include a literal backtick character within a code span, you can use
1312
+ multiple backticks as the opening and closing delimiters:
1313
+ .
1314
+ .IP "" 4
1315
+ .
1316
+ .nf
1317
+
1318
+ ``There is a literal backtick (`) here.``
1319
+ .
1320
+ .fi
1321
+ .
1322
+ .IP "" 0
1323
+ .
1324
+ .P
1325
+ which will produce this:
1326
+ .
1327
+ .IP "" 4
1328
+ .
1329
+ .nf
1330
+
1331
+ <p><code>There is a literal backtick (`) here.</code></p>
1332
+ .
1333
+ .fi
1334
+ .
1335
+ .IP "" 0
1336
+ .
1337
+ .P
1338
+ The backtick delimiters surrounding a code span may include spaces \-\-
1339
+ one after the opening, one before the closing. This allows you to place
1340
+ literal backtick characters at the beginning or end of a code span:
1341
+ .
1342
+ .IP "" 4
1343
+ .
1344
+ .nf
1345
+
1346
+ A single backtick in a code span: `` ` ``
1347
+ A backtick\-delimited string in a code span: `` `foo` ``
1348
+ .
1349
+ .fi
1350
+ .
1351
+ .IP "" 0
1352
+ .
1353
+ .P
1354
+ will produce:
1355
+ .
1356
+ .IP "" 4
1357
+ .
1358
+ .nf
1359
+
1360
+ <p>A single backtick in a code span: <code>`</code></p>
1361
+ <p>A backtick\-delimited string in a code span: <code>`foo`</code></p>
1362
+ .
1363
+ .fi
1364
+ .
1365
+ .IP "" 0
1366
+ .
1367
+ .P
1368
+ With a code span, ampersands and angle brackets are encoded as HTML
1369
+ entities automatically, which makes it easy to include example HTML
1370
+ tags. Markdown will turn this:
1371
+ .
1372
+ .IP "" 4
1373
+ .
1374
+ .nf
1375
+
1376
+ Please don't use any `<blink>` tags.
1377
+ .
1378
+ .fi
1379
+ .
1380
+ .IP "" 0
1381
+ .
1382
+ .P
1383
+ into:
1384
+ .
1385
+ .IP "" 4
1386
+ .
1387
+ .nf
1388
+
1389
+ <p>Please don't use any <code><blink></code> tags.</p>
1390
+ .
1391
+ .fi
1392
+ .
1393
+ .IP "" 0
1394
+ .
1395
+ .P
1396
+ You can write this:
1397
+ .
1398
+ .IP "" 4
1399
+ .
1400
+ .nf
1401
+
1402
+ `&#8212;` is the decimal\-encoded equivalent of `&mdash;`.
1403
+ .
1404
+ .fi
1405
+ .
1406
+ .IP "" 0
1407
+ .
1408
+ .P
1409
+ to produce:
1410
+ .
1411
+ .IP "" 4
1412
+ .
1413
+ .nf
1414
+
1415
+ <p><code>&#8212;</code> is the decimal\-encoded
1416
+ equivalent of <code>&mdash;</code>.</p>
1417
+ .
1418
+ .fi
1419
+ .
1420
+ .IP "" 0
1421
+ .
1422
+ .SS "Images"
1423
+ Admittedly, it's fairly difficult to devise a "natural" syntax for
1424
+ placing images into a plain text document format.
1425
+ .
1426
+ .P
1427
+ Markdown uses an image syntax that is intended to resemble the syntax
1428
+ for links, allowing for two styles: \fIinline\fR and \fIreference\fR.
1429
+ .
1430
+ .P
1431
+ Inline image syntax looks like this:
1432
+ .
1433
+ .IP "" 4
1434
+ .
1435
+ .nf
1436
+
1437
+ ![Alt text](/path/to/img.jpg)
1438
+ ![Alt text](/path/to/img.jpg "Optional title")
1439
+ .
1440
+ .fi
1441
+ .
1442
+ .IP "" 0
1443
+ .
1444
+ .P
1445
+ That is:
1446
+ .
1447
+ .IP "\(bu" 4
1448
+ An exclamation mark: \fB!\fR;
1449
+ .
1450
+ .IP "\(bu" 4
1451
+ followed by a set of square brackets, containing the \fBalt\fR
1452
+ attribute text for the image;
1453
+ .
1454
+ .IP "\(bu" 4
1455
+ followed by a set of parentheses, containing the URL or path to
1456
+ the image, and an optional \fBtitle\fR attribute enclosed in double
1457
+ or single quotes.
1458
+ .
1459
+ .IP "" 0
1460
+ .
1461
+ .P
1462
+ Reference\-style image syntax looks like this:
1463
+ .
1464
+ .IP "" 4
1465
+ .
1466
+ .nf
1467
+
1468
+ ![Alt text][id]
1469
+ .
1470
+ .fi
1471
+ .
1472
+ .IP "" 0
1473
+ .
1474
+ .P
1475
+ Where "id" is the name of a defined image reference. Image references
1476
+ are defined using syntax identical to link references:
1477
+ .
1478
+ .IP "" 4
1479
+ .
1480
+ .nf
1481
+
1482
+ [id]: url/to/image "Optional title attribute"
1483
+ .
1484
+ .fi
1485
+ .
1486
+ .IP "" 0
1487
+ .
1488
+ .P
1489
+ As of this writing, Markdown has no syntax for specifying the
1490
+ dimensions of an image; if this is important to you, you can simply
1491
+ use regular HTML \fB<img>\fR tags.
1492
+ .
1493
+ .SH "MISCELLANEOUS"
1494
+ .
1495
+ .SS "Automatic Links"
1496
+ 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:
1497
+ .
1498
+ .IP "" 4
1499
+ .
1500
+ .nf
1501
+
1502
+ <http://example.com/>
1503
+ .
1504
+ .fi
1505
+ .
1506
+ .IP "" 0
1507
+ .
1508
+ .P
1509
+ Markdown will turn this into:
1510
+ .
1511
+ .IP "" 4
1512
+ .
1513
+ .nf
1514
+
1515
+ <a href="http://example.com/">http://example.com/</a>
1516
+ .
1517
+ .fi
1518
+ .
1519
+ .IP "" 0
1520
+ .
1521
+ .P
1522
+ Automatic links for email addresses work similarly, except that
1523
+ Markdown will also perform a bit of randomized decimal and hex
1524
+ entity\-encoding to help obscure your address from address\-harvesting
1525
+ spambots. For example, Markdown will turn this:
1526
+ .
1527
+ .IP "" 4
1528
+ .
1529
+ .nf
1530
+
1531
+ <address@example.com>
1532
+ .
1533
+ .fi
1534
+ .
1535
+ .IP "" 0
1536
+ .
1537
+ .P
1538
+ into something like this:
1539
+ .
1540
+ .IP "" 4
1541
+ .
1542
+ .nf
1543
+
1544
+ <a href="&#x6D;&#x61;i&#x6C;&#x74;&#x6F;:&#x61;&#x64;&#x64;&#x72;&#x65;
1545
+ &#115;&#115;&#64;&#101;&#120;&#x61;&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;
1546
+ &#109;">&#x61;&#x64;&#x64;&#x72;&#x65;&#115;&#115;&#64;&#101;&#120;&#x61;
1547
+ &#109;&#x70;&#x6C;e&#x2E;&#99;&#111;&#109;</a>
1548
+ .
1549
+ .fi
1550
+ .
1551
+ .IP "" 0
1552
+ .
1553
+ .P
1554
+ which will render in a browser as a clickable link to "address@example.com".
1555
+ .
1556
+ .P
1557
+ (This sort of entity\-encoding trick will indeed fool many, if not
1558
+ most, address\-harvesting bots, but it definitely won't fool all of
1559
+ them. It's better than nothing, but an address published in this way
1560
+ will probably eventually start receiving spam.)
1561
+ .
1562
+ .SS "Backslash Escapes"
1563
+ Markdown allows you to use backslash escapes to generate literal
1564
+ characters which would otherwise have special meaning in Markdown's
1565
+ formatting syntax. For example, if you wanted to surround a word
1566
+ with literal asterisks (instead of an HTML \fB<em>\fR tag), you can use
1567
+ backslashes before the asterisks, like this:
1568
+ .
1569
+ .IP "" 4
1570
+ .
1571
+ .nf
1572
+
1573
+ \\*literal asterisks\\*
1574
+ .
1575
+ .fi
1576
+ .
1577
+ .IP "" 0
1578
+ .
1579
+ .P
1580
+ Markdown provides backslash escapes for the following characters:
1581
+ .
1582
+ .IP "" 4
1583
+ .
1584
+ .nf
1585
+
1586
+ \\ backslash
1587
+ ` backtick
1588
+ * asterisk
1589
+ _ underscore
1590
+ {} curly braces
1591
+ [] square brackets
1592
+ () parentheses
1593
+ # hash mark
1594
+ + plus sign
1595
+ \- minus sign (hyphen)
1596
+ . dot
1597
+ ! exclamation mark
1598
+ .
1599
+ .fi
1600
+ .
1601
+ .IP "" 0
1602
+ .
1603
+ .SH "AUTHOR"
1604
+ Markdown was created by John Gruber.
1605
+ .
1606
+ .P
1607
+ Manual page by Ryan Tomayko. It's pretty much a direct copy of the\fIMarkdown Syntax Reference\fR,
1608
+ also by John Gruber.
1609
+ .
1610
+ .SH "SEE ALSO"
1611
+ ron(5)
1612
+ .
1613
+ .br
1614
+ \fIhttp://daringfireball.net/projects/markdown/\fR