├── test
├── files
│ ├── Test File 2.md
│ ├── format.plain
│ ├── reference.doc
│ ├── reference.docx
│ ├── Test File 1.md
│ ├── format.asciidoc
│ ├── format.markdown
│ ├── format.textile
│ ├── format.man
│ ├── format.rst
│ ├── format.latex
│ ├── format.mediawiki
│ ├── format.html
│ ├── format.html5
│ ├── format.org
│ ├── format.beamer
│ ├── format.context
│ ├── format.s5
│ ├── format.slidy
│ ├── format.dzslides
│ ├── format.rtf
│ ├── format.texinfo
│ ├── format.docbook
│ ├── format.opendocument
│ ├── bomb.tex
│ └── benchmark.txt
├── helper.rb
├── benchmark.rb
├── test_conversions.rb
└── test_pandoc_ruby.rb
├── .github
├── FUNDING.yml
└── workflows
│ └── tests.yml
├── .document
├── .gitignore
├── Gemfile
├── pandoc-ruby.gemspec
├── LICENSE
├── Gemfile.lock
├── Rakefile
├── .rubocop.yml
├── .rubocop_todo.yml
├── README.md
└── lib
└── pandoc-ruby.rb
/test/files/Test File 2.md:
--------------------------------------------------------------------------------
1 | # A Second Title
2 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: xwmx
2 | custom: https://paypal.me/WilliamMelody
3 |
--------------------------------------------------------------------------------
/test/files/format.plain:
--------------------------------------------------------------------------------
1 | This is a Title
2 |
3 | Some emphasized text and a link
4 |
--------------------------------------------------------------------------------
/.document:
--------------------------------------------------------------------------------
1 | README.markdown
2 | lib/**/*.rb
3 | bin/*
4 | features/**/*.feature
5 | LICENSE
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.sw?
2 | .DS_Store
3 | coverage
4 | rdoc
5 | pkg
6 | .rvmrc
7 | .bundle
8 | *.gem
9 |
--------------------------------------------------------------------------------
/test/files/reference.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwmx/pandoc-ruby/HEAD/test/files/reference.doc
--------------------------------------------------------------------------------
/test/files/reference.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xwmx/pandoc-ruby/HEAD/test/files/reference.docx
--------------------------------------------------------------------------------
/test/files/Test File 1.md:
--------------------------------------------------------------------------------
1 | # This is a Title
2 |
3 | Some *emphasized text* and
4 | [a link](http://daringfireball.net/projects/markdown/)
5 |
--------------------------------------------------------------------------------
/test/files/format.asciidoc:
--------------------------------------------------------------------------------
1 | == This is a Title
2 |
3 | Some _emphasized text_ and
4 | http://daringfireball.net/projects/markdown/[a link]
5 |
--------------------------------------------------------------------------------
/test/files/format.markdown:
--------------------------------------------------------------------------------
1 | # This is a Title
2 |
3 | Some *emphasized text* and [a
4 | link](http://daringfireball.net/projects/markdown/)
5 |
--------------------------------------------------------------------------------
/test/files/format.textile:
--------------------------------------------------------------------------------
1 | h1(#this-is-a-title). This is a Title
2 |
3 | Some _emphasized text_ and "a link":http://daringfireball.net/projects/markdown/
4 |
--------------------------------------------------------------------------------
/test/files/format.man:
--------------------------------------------------------------------------------
1 | .SH This is a Title
2 | Some \f[I]emphasized text\f[R] and \c
3 | .UR http://daringfireball.net/projects/markdown/
4 | a link
5 | .UE \c
6 |
--------------------------------------------------------------------------------
/test/files/format.rst:
--------------------------------------------------------------------------------
1 | This is a Title
2 | ===============
3 |
4 | Some *emphasized text* and `a
5 | link `__
6 |
--------------------------------------------------------------------------------
/test/files/format.latex:
--------------------------------------------------------------------------------
1 | \section{This is a Title}\label{this-is-a-title}
2 |
3 | Some \emph{emphasized text} and
4 | \href{http://daringfireball.net/projects/markdown/}{a link}
5 |
--------------------------------------------------------------------------------
/test/files/format.mediawiki:
--------------------------------------------------------------------------------
1 |
2 | = This is a Title =
3 |
4 | Some ''emphasized text'' and [http://daringfireball.net/projects/markdown/ a link]
5 |
--------------------------------------------------------------------------------
/test/files/format.html:
--------------------------------------------------------------------------------
1 |
'markdown',
53 | :to => to
54 | )
55 |
56 | File.open(to_file, 'w') do |file|
57 | file.write(converted_content)
58 | end
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/test/benchmark.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # From on Ryan Tomayako's benchmark script from:
4 | # http://tomayko.com/writings/ruby-markdown-libraries-real-cheap-for-you-two-for-price-of-one
5 |
6 | iterations = 100
7 | test_file = File.join(File.dirname(__FILE__), 'files', 'benchmark.txt')
8 | impl_gems = {
9 | 'BlueCloth' => 'bluecloth',
10 | 'RDiscount' => 'rdiscount',
11 | 'Maruku' => 'maruku',
12 | 'PandocRuby' => 'pandoc-ruby'
13 | }
14 |
15 | implementations = impl_gems.keys
16 |
17 | # Attempt to require each implementation and remove any that are not
18 | # installed.
19 | implementations.reject! do |class_name|
20 | begin
21 | require impl_gems[class_name]
22 | false
23 | rescue LoadError => boom
24 | puts "#{class_name} excluded. Try: gem install #{impl_gems[class_name]}"
25 | true
26 | end
27 | end
28 |
29 | # Grab actual class objects.
30 | implementations.map! { |class_name| Object.const_get(class_name) }
31 |
32 | def benchmark(implementation, text, iterations)
33 | start = Time.now
34 | iterations.times do |_i|
35 | implementation.new(text).to_html
36 | end
37 | Time.now - start
38 | end
39 |
40 | test_data = File.read(test_file)
41 |
42 | puts 'Spinning up ...'
43 | implementations.each { |impl| benchmark(impl, test_data, 1) }
44 |
45 | puts 'Running benchmarks ...'
46 | results =
47 | implementations.inject([]) do |r, impl|
48 | GC.start
49 | r << [impl, benchmark(impl, test_data, iterations)]
50 | end
51 |
52 | puts "Results for #{iterations} iterations:"
53 | results.each do |impl, time|
54 | printf " %10s %09.06fs total time, %09.06fs average\n",
55 | "#{impl}:",
56 | time,
57 | time / iterations
58 | end
59 |
--------------------------------------------------------------------------------
/.rubocop.yml:
--------------------------------------------------------------------------------
1 | # .rubocop.yml
2 | #
3 | # Configuration for rubocop, a static code analyzer for Ruby.
4 | #
5 | # https://github.com/bbatsov/rubocop#configuration
6 |
7 | inherit_from: .rubocop_todo.yml
8 |
9 | # Layout/AccessModifierIndentation
10 | #
11 | # Indent access modifiers like `protected` and `private`.
12 | Layout/AccessModifierIndentation:
13 | EnforcedStyle: indent
14 |
15 | Layout/FirstHashElementIndentation:
16 | EnforcedStyle: consistent
17 |
18 | Layout/HashAlignment:
19 | EnforcedHashRocketStyle: table
20 |
21 | # Layout/IndentationConsistency
22 | #
23 | # Use Rails-style access modifier indentation.
24 | #
25 | # Example:
26 | # ```
27 | # class Foo
28 | # def bar
29 | # puts 'bar'
30 | # end
31 | #
32 | # private
33 | #
34 | # def baz
35 | # puts 'baz'
36 | # end
37 | # end
38 | # ```
39 | Layout/IndentationConsistency:
40 | EnforcedStyle: indented_internal_methods
41 |
42 | Layout/SpaceAroundOperators:
43 | Enabled: false
44 |
45 | Metrics/AbcSize:
46 | Enabled: false
47 |
48 | Metrics/BlockLength:
49 | Enabled: false
50 |
51 | Metrics/ClassLength:
52 | Enabled: false
53 |
54 | # Naming/FileName
55 | #
56 | # Long, long ago, this was named with a dash rather than an underscore. Now
57 | # it's unconventional, but let's consider it retro and leave it for now so we
58 | # don't have to rename the gem. TODO: Rename using an underscore.
59 | Naming/FileName:
60 | Exclude:
61 | - 'lib/pandoc-ruby.rb'
62 |
63 | Style/AccessorGrouping:
64 | Enabled: false
65 |
66 | Style/HashSyntax:
67 | EnforcedStyle: hash_rockets
68 |
69 | # Style/RedundantBegin
70 | #
71 | # Permit redundant `begin` block to support Ruby 2.4 and earlier.
72 | #
73 | # See also:
74 | # https://github.com/xwmx/pandoc-ruby/issues/47
75 | # https://github.com/xwmx/pandoc-ruby/issues/41
76 | Style/RedundantBegin:
77 | Enabled: false
78 |
79 | # Style/SymbolArray
80 | #
81 | # Avoid `%i` syntax so symbols look like symbols.
82 | Style/SymbolArray:
83 | EnforcedStyle: brackets
84 |
85 | # Style/RedundantSelf
86 | #
87 | # Explicit `self` is currently preferred in this project in order to
88 | # better distinguish between accessors and local variables.
89 | Style/RedundantSelf:
90 | Exclude:
91 | - 'lib/pandoc-ruby.rb'
92 |
--------------------------------------------------------------------------------
/test/test_conversions.rb:
--------------------------------------------------------------------------------
1 | require 'helper'
2 |
3 | # Generate tests for converting to and from various formats. Use two nested
4 | # loops to iterate over each source and destination format, using files with
5 | # names of the following structure: "format.#{format_name}"
6 | describe 'Conversions' do
7 | @extensions = []
8 | Dir.glob(File.join(File.dirname(__FILE__), 'files', 'format*')) do |f|
9 | @extensions << f.match(/format\.(\w+)\Z/)[1]
10 | end
11 |
12 | [:markdown, :html, :rst, :latex].each do |from|
13 | @extensions.each do |to|
14 | next if from == to
15 |
16 | it "converts #{from} to #{to}" do
17 | files_dir = File.join(File.dirname(__FILE__), 'files')
18 | from_content = File.read(File.join(files_dir, "format.#{from}"))
19 | to_content = File.read(File.join(files_dir, "format.#{to}"))
20 |
21 | converted_content = PandocRuby.convert(
22 | from_content,
23 | :from => from,
24 | :to => to
25 | )
26 |
27 | assert_equal(
28 | to_content.strip,
29 | converted_content.strip,
30 | <<-HEREDOC
31 | ---------
32 | EXPECTED:
33 | ---------
34 | #{to_content.strip}
35 | ---------
36 | -------
37 | ACTUAL:
38 | -------
39 | #{converted_content.strip}
40 | -------
41 | HEREDOC
42 | )
43 | end
44 | end
45 | end
46 |
47 | describe '.docx' do
48 | it "converts from docx to html" do
49 | converted_content = PandocRuby.convert(
50 | ['./test/files/reference.docx'],
51 | :from => 'docx',
52 | :to => 'html'
53 | )
54 | assert_equal("Hello World.
", converted_content.strip)
55 | end
56 |
57 | it "raises an error when attempting to convert doc with docx format" do
58 | error = assert_raises(RuntimeError) do
59 | PandocRuby.convert(
60 | ['./test/files/reference.doc'],
61 | :from => 'docx',
62 | :to => 'html'
63 | )
64 | end
65 |
66 | assert_match(/couldn't unpack docx container/, error.message)
67 | end
68 |
69 | it "raises an error when attempting to convert doc with doc format" do
70 | error = assert_raises(RuntimeError) do
71 | PandocRuby.convert(
72 | ['./test/files/reference.doc'],
73 | :from => 'doc',
74 | :to => 'html'
75 | )
76 | end
77 |
78 | assert_match(/Pandoc can convert from DOCX, but not from DOC./, error.message)
79 | end
80 | end
81 | end
82 |
--------------------------------------------------------------------------------
/.rubocop_todo.yml:
--------------------------------------------------------------------------------
1 | # This configuration was generated by
2 | # `rubocop --auto-gen-config`
3 | # on 2023-11-25 00:17:47 UTC using RuboCop version 1.57.2.
4 | # The point is for the user to remove these configuration records
5 | # one by one as the offenses are removed from the code base.
6 | # Note that changes in the inspected code, or installation of new
7 | # versions of RuboCop, may require this file to be generated again.
8 |
9 | # Offense count: 1
10 | # Configuration parameters: Severity, Include.
11 | # Include: **/*.gemspec
12 | Gemspec/RequiredRubyVersion:
13 | Exclude:
14 | - 'pandoc-ruby.gemspec'
15 |
16 | # Offense count: 1
17 | # This cop supports safe autocorrection (--autocorrect).
18 | Layout/HeredocIndentation:
19 | Exclude:
20 | - 'test/test_conversions.rb'
21 |
22 | # Offense count: 1
23 | # This cop supports unsafe autocorrection (--autocorrect-all).
24 | Lint/UselessAssignment:
25 | Exclude:
26 | - 'test/benchmark.rb'
27 |
28 | # Offense count: 1
29 | # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
30 | Metrics/MethodLength:
31 | Max: 19
32 |
33 | # Offense count: 2
34 | # This cop supports safe autocorrection (--autocorrect).
35 | # Configuration parameters: PreferredName.
36 | Naming/RescuedExceptionsVariableName:
37 | Exclude:
38 | - 'lib/pandoc-ruby.rb'
39 | - 'test/benchmark.rb'
40 |
41 | # Offense count: 1
42 | # Configuration parameters: AllowedConstants.
43 | Style/Documentation:
44 | Exclude:
45 | - 'spec/**/*'
46 | - 'test/**/*'
47 | - 'lib/pandoc-ruby.rb'
48 |
49 | # Offense count: 3
50 | # This cop supports safe autocorrection (--autocorrect).
51 | # Configuration parameters: MaxUnannotatedPlaceholdersAllowed, AllowedMethods, AllowedPatterns.
52 | # SupportedStyles: annotated, template, unannotated
53 | Style/FormatStringToken:
54 | EnforcedStyle: unannotated
55 |
56 | # Offense count: 8
57 | # This cop supports unsafe autocorrection (--autocorrect-all).
58 | # Configuration parameters: EnforcedStyle.
59 | # SupportedStyles: always, always_true, never
60 | Style/FrozenStringLiteralComment:
61 | Exclude:
62 | - 'Gemfile'
63 | - 'Rakefile'
64 | - 'lib/pandoc-ruby.rb'
65 | - 'pandoc-ruby.gemspec'
66 | - 'test/benchmark.rb'
67 | - 'test/helper.rb'
68 | - 'test/test_conversions.rb'
69 | - 'test/test_pandoc_ruby.rb'
70 |
71 | # Offense count: 1
72 | # This cop supports safe autocorrection (--autocorrect).
73 | Style/RedundantFileExtensionInRequire:
74 | Exclude:
75 | - 'Rakefile'
76 |
77 | # Offense count: 1
78 | # This cop supports safe autocorrection (--autocorrect).
79 | # Configuration parameters: AllowMultipleReturnValues.
80 | Style/RedundantReturn:
81 | Exclude:
82 | - 'lib/pandoc-ruby.rb'
83 |
84 | # Offense count: 1
85 | # This cop supports unsafe autocorrection (--autocorrect-all).
86 | # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
87 | # AllowedMethods: present?, blank?, presence, try, try!
88 | Style/SafeNavigation:
89 | Exclude:
90 | - 'lib/pandoc-ruby.rb'
91 |
92 | # Offense count: 4
93 | # This cop supports safe autocorrection (--autocorrect).
94 | # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
95 | # SupportedStyles: single_quotes, double_quotes
96 | Style/StringLiterals:
97 | Exclude:
98 | - 'test/test_conversions.rb'
99 |
100 | # Offense count: 1
101 | # This cop supports safe autocorrection (--autocorrect).
102 | # Configuration parameters: EnforcedStyle, MinSize, WordRegex.
103 | # SupportedStyles: percent, brackets
104 | Style/WordArray:
105 | Exclude:
106 | - 'pandoc-ruby.gemspec'
107 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PandocRuby
2 |
3 | [](https://github.com/xwmx/pandoc-ruby/actions)
4 | [](http://rubygems.org/gems/pandoc-ruby)
5 | [](http://rubygems.org/gems/pandoc-ruby)
6 |
7 | PandocRuby is a wrapper for [Pandoc](http://pandoc.org), a
8 | Haskell library with command line tools for converting one markup format to
9 | another.
10 |
11 | Pandoc can convert documents from a variety of formats including markdown,
12 | reStructuredText, textile, HTML, DocBook, LaTeX, and MediaWiki markup to a
13 | variety of other formats, including markdown, reStructuredText, HTML, LaTeX,
14 | ConTeXt, PDF, RTF, DocBook XML, OpenDocument XML, ODT, GNU Texinfo, MediaWiki
15 | markup, groff man pages, HTML slide shows, EPUB, Microsoft Word docx, and more.
16 |
17 | ## Installation
18 |
19 | First, [install Pandoc](https://pandoc.org/installing.html).
20 |
21 | PandocRuby is available on [RubyGems](http://rubygems.org/gems/pandoc-ruby):
22 |
23 | ```bash
24 | gem install pandoc-ruby
25 | ```
26 |
27 | To install with [Bundler](https://bundler.io/), add the following to your
28 | Gemfile:
29 |
30 | ```ruby
31 | gem 'pandoc-ruby'
32 | ```
33 |
34 | Then run `bundle install`
35 |
36 | ## Usage
37 |
38 | ```ruby
39 | require 'pandoc-ruby'
40 | @converter = PandocRuby.new('# Markdown Title', from: :markdown, to: :rst)
41 | puts @converter.convert
42 | ```
43 |
44 | This takes the Markdown formatted string and converts it to reStructuredText.
45 |
46 | You can also use the `#convert` class method:
47 |
48 | ```ruby
49 | puts PandocRuby.convert('# Markdown Title', from: :markdown, to: :html)
50 | ```
51 |
52 | Other arguments are simply converted into command line options, accepting
53 | symbols and strings for options and hashes for options with arguments.
54 |
55 | ```ruby
56 | PandocRuby.convert('# Markdown Title', :s, {f: :markdown, to: :rst}, '--wrap=none', :table_of_contents)
57 | ```
58 |
59 | is equivalent to
60 |
61 | ```bash
62 | echo "# Markdown Title" | pandoc -s -f markdown --to=rst --wrap=none --table-of-contents
63 | ```
64 |
65 | Also provided are `#to_[writer]` instance methods for each of the writers,
66 | and these can also accept options:
67 |
68 | ```ruby
69 | PandocRuby.new('# Example').to_html(:ascii)
70 | # => "Example
"
71 | # or
72 | PandocRuby.new("# Example").to_rst
73 | # => "Example
74 | # ======="
75 | ```
76 |
77 | Similarly, there are class methods for each of the readers, so readers
78 | and writers can be specified like this:
79 |
80 | ```ruby
81 | PandocRuby.html("hello
").to_latex
82 | # => "\\section{hello}"
83 | ```
84 |
85 | Available readers and writers are can be found in the following
86 | variables:
87 | - [`PandocRuby::READERS`](lib/pandoc-ruby.rb#L10)
88 | - [`PandocRuby::STRING_WRITERS`](lib/pandoc-ruby.rb#L48)
89 | - [`PandocRuby::BINARY_WRITERS`](lib/pandoc-ruby.rb#L104)
90 | - [`PandocRuby::WRITERS`](lib/pandoc-ruby.rb#L113)
91 |
92 | PandocRuby assumes the `pandoc` executable is in your environment's `$PATH`
93 | variable. If you'd like to set an explicit path to the `pandoc` executable,
94 | you can do so with `PandocRuby.pandoc_path = '/path/to/pandoc'`
95 |
96 | ### Converting Files
97 |
98 | PandocRuby can also take an array of one or more file paths as the first
99 | argument. The files will be concatenated together with a blank line between
100 | each and used as input.
101 |
102 | ```ruby
103 | # One file path as a single-element array.
104 | PandocRuby.new(['/path/to/file1.docx'], from: 'docx').to_html
105 | # Multiple file paths as an array.
106 | PandocRuby.new(['/path/to/file1.docx', '/path/to/file1.docx'], from: 'docx').to_html
107 | ```
108 |
109 | If you are trying to generate a standalone file with full file headers rather
110 | than just a marked up fragment, remember to pass the `:standalone` option so
111 | the correct header and footer are added.
112 |
113 | ```ruby
114 | PandocRuby.new("# Some title", :standalone).to_rtf
115 | ```
116 |
117 | ### Extensions
118 |
119 | Pandoc [extensions](https://pandoc.org/MANUAL.html#extensions) can be
120 | used to modify the behavior of readers and writers. To use an extension,
121 | add the extension with a `+` or `-` after the reader or writer name:
122 |
123 | ```ruby
124 | # Without extension:
125 | PandocRuby.new("Line 1\n# Heading", from: 'markdown_strict').to_html
126 | # => "Line 1
\nHeading
\n"
127 |
128 | # With `+blank_before_header` extension:
129 | PandocRuby.new("Line 1\n# Heading", from: 'markdown_strict+blank_before_header').to_html
130 | # => "Line 1 # Heading
\n
131 | ```
132 |
133 | ### More Information
134 |
135 | For more information on Pandoc, see the
136 | [Pandoc documentation](http://pandoc.org)
137 | or run `man pandoc`
138 | ([also available here](https://pandoc.org/MANUAL.html)).
139 |
140 | If you'd prefer a pure-Ruby extended markdown interpreter that can output a
141 | few different formats, take a look at
142 | [kramdown](https://kramdown.gettalong.org/). If you want to use the full
143 | reStructuredText syntax from within Ruby, check out
144 | [RbST](https://github.com/xwmx/rbst), a docutils wrapper.
145 |
146 | This gem was inspired by [Albino](http://github.com/github/albino). For a
147 | slightly different approach to using Pandoc with Ruby, see
148 | [Pandoku](http://github.com/dahlia/pandoku).
149 |
150 | ## Note on Patches/Pull Requests
151 |
152 | * Fork the project.
153 | * Make your feature addition or bug fix.
154 | * Add tests for it. This is important so I don't break it in a
155 | future version unintentionally.
156 | * Commit, do not mess with rakefile, version, or history.
157 | (if you want to have your own version, that is fine but
158 | bump version in a commit by itself I can ignore when I pull)
159 | * Send me a pull request. Bonus points for topic branches.
160 |
--------------------------------------------------------------------------------
/test/files/benchmark.txt:
--------------------------------------------------------------------------------
1 | Markdown: Basics
2 | ================
3 |
4 |
11 |
12 |
13 | Getting the Gist of Markdown's Formatting Syntax
14 | ------------------------------------------------
15 |
16 | This page offers a brief overview of what it's like to use Markdown.
17 | The [syntax page] [s] provides complete, detailed documentation for
18 | every feature, but Markdown should be very easy to pick up simply by
19 | looking at a few examples of it in action. The examples on this page
20 | are written in a before/after style, showing example syntax and the
21 | HTML output produced by Markdown.
22 |
23 | It's also helpful to simply try Markdown out; the [Dingus] [d] is a
24 | web application that allows you type your own Markdown-formatted text
25 | and translate it to XHTML.
26 |
27 | **Note:** This document is itself written using Markdown; you
28 | can [see the source for it by adding '.text' to the URL] [src].
29 |
30 | [s]: /projects/markdown/syntax "Markdown Syntax"
31 | [d]: /projects/markdown/dingus "Markdown Dingus"
32 | [src]: /projects/markdown/basics.text
33 |
34 |
35 | ## Paragraphs, Headers, Blockquotes ##
36 |
37 | A paragraph is simply one or more consecutive lines of text, separated
38 | by one or more blank lines. (A blank line is any line that looks like a
39 | blank line -- a line containing nothing spaces or tabs is considered
40 | blank.) Normal paragraphs should not be intended with spaces or tabs.
41 |
42 | Markdown offers two styles of headers: *Setext* and *atx*.
43 | Setext-style headers for `` and `` are created by
44 | "underlining" with equal signs (`=`) and hyphens (`-`), respectively.
45 | To create an atx-style header, you put 1-6 hash marks (`#`) at the
46 | beginning of the line -- the number of hashes equals the resulting
47 | HTML header level.
48 |
49 | Blockquotes are indicated using email-style '`>`' angle brackets.
50 |
51 | Markdown:
52 |
53 | A First Level Header
54 | ====================
55 |
56 | A Second Level Header
57 | ---------------------
58 |
59 | Now is the time for all good men to come to
60 | the aid of their country. This is just a
61 | regular paragraph.
62 |
63 | The quick brown fox jumped over the lazy
64 | dog's back.
65 |
66 | ### Header 3
67 |
68 | > This is a blockquote.
69 | >
70 | > This is the second paragraph in the blockquote.
71 | >
72 | > ## This is an H2 in a blockquote
73 |
74 |
75 | Output:
76 |
77 | A First Level Header
78 |
79 | A Second Level Header
80 |
81 |
Now is the time for all good men to come to
82 | the aid of their country. This is just a
83 | regular paragraph.
84 |
85 | The quick brown fox jumped over the lazy
86 | dog's back.
87 |
88 | Header 3
89 |
90 |
91 | This is a blockquote.
92 |
93 | This is the second paragraph in the blockquote.
94 |
95 | This is an H2 in a blockquote
96 |
97 |
98 |
99 |
100 | ### Phrase Emphasis ###
101 |
102 | Markdown uses asterisks and underscores to indicate spans of emphasis.
103 |
104 | Markdown:
105 |
106 | Some of these words *are emphasized*.
107 | Some of these words _are emphasized also_.
108 |
109 | Use two asterisks for **strong emphasis**.
110 | Or, if you prefer, __use two underscores instead__.
111 |
112 | Output:
113 |
114 | Some of these words are emphasized.
115 | Some of these words are emphasized also.
116 |
117 | Use two asterisks for strong emphasis.
118 | Or, if you prefer, use two underscores instead.
119 |
120 |
121 |
122 | ## Lists ##
123 |
124 | Unordered (bulleted) lists use asterisks, pluses, and hyphens (`*`,
125 | `+`, and `-`) as list markers. These three markers are
126 | interchangable; this:
127 |
128 | * Candy.
129 | * Gum.
130 | * Booze.
131 |
132 | this:
133 |
134 | + Candy.
135 | + Gum.
136 | + Booze.
137 |
138 | and this:
139 |
140 | - Candy.
141 | - Gum.
142 | - Booze.
143 |
144 | all produce the same output:
145 |
146 |
147 | - Candy.
148 | - Gum.
149 | - Booze.
150 |
151 |
152 | Ordered (numbered) lists use regular numbers, followed by periods, as
153 | list markers:
154 |
155 | 1. Red
156 | 2. Green
157 | 3. Blue
158 |
159 | Output:
160 |
161 |
162 | - Red
163 | - Green
164 | - Blue
165 |
166 |
167 | If you put blank lines between items, you'll get `` tags for the
168 | list item text. You can create multi-paragraph list items by indenting
169 | the paragraphs by 4 spaces or 1 tab:
170 |
171 | * A list item.
172 |
173 | With multiple paragraphs.
174 |
175 | * Another item in the list.
176 |
177 | Output:
178 |
179 |
184 |
185 |
186 |
187 | ### Links ###
188 |
189 | Markdown supports two styles for creating links: *inline* and
190 | *reference*. With both styles, you use square brackets to delimit the
191 | text you want to turn into a link.
192 |
193 | Inline-style links use parentheses immediately after the link text.
194 | For example:
195 |
196 | This is an [example link](http://example.com/).
197 |
198 | Output:
199 |
200 | This is an
201 | example link.
202 |
203 | Optionally, you may include a title attribute in the parentheses:
204 |
205 | This is an [example link](http://example.com/ "With a Title").
206 |
207 | Output:
208 |
209 | This is an
210 | example link.
211 |
212 | Reference-style links allow you to refer to your links by names, which
213 | you define elsewhere in your document:
214 |
215 | I get 10 times more traffic from [Google][1] than from
216 | [Yahoo][2] or [MSN][3].
217 |
218 | [1]: http://google.com/ "Google"
219 | [2]: http://search.yahoo.com/ "Yahoo Search"
220 | [3]: http://search.msn.com/ "MSN Search"
221 |
222 | Output:
223 |
224 | I get 10 times more traffic from Google than from Yahoo or MSN.
228 |
229 | The title attribute is optional. Link names may contain letters,
230 | numbers and spaces, but are *not* case sensitive:
231 |
232 | I start my morning with a cup of coffee and
233 | [The New York Times][NY Times].
234 |
235 | [ny times]: http://www.nytimes.com/
236 |
237 | Output:
238 |
239 | I start my morning with a cup of coffee and
240 | The New York Times.
241 |
242 |
243 | ### Images ###
244 |
245 | Image syntax is very much like link syntax.
246 |
247 | Inline (titles are optional):
248 |
249 | 
250 |
251 | Reference-style:
252 |
253 | ![alt text][id]
254 |
255 | [id]: /path/to/img.jpg "Title"
256 |
257 | Both of the above examples produce the same output:
258 |
259 |
260 |
261 |
262 |
263 | ### Code ###
264 |
265 | In a regular paragraph, you can create code span by wrapping text in
266 | backtick quotes. Any ampersands (`&`) and angle brackets (`<` or
267 | `>`) will automatically be translated into HTML entities. This makes
268 | it easy to use Markdown to write about HTML example code:
269 |
270 | I strongly recommend against using any `