kramdown-gist 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - "1.9.3"
4
+ - "1.8.7"
4
5
  script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in kramdown-gist.gemspec
3
+ # RVM metadata
4
+
5
+ #ruby=1.9.3
6
+ #ruby-gemset=kramdown-gist
7
+
8
+ # Use kramdown-gist.gemspec for dependencies
4
9
  gemspec
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
- # kramdown-gist [![Build Status](https://travis-ci.org/rfc1459/kramdown-gist.png)](https://travis-ci.org/rfc1459/kramdown-gist)
1
+ kramdown-gist
2
+ =============
3
+
4
+ [![Build Status](https://travis-ci.org/rfc1459/kramdown-gist.png)](https://travis-ci.org/rfc1459/kramdown-gist)
5
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/rfc1459/kramdown-gist)
2
6
 
3
7
  This gem extends the default [kramdown][] parser with a new block-level
4
8
  element which adds support for embedding [GitHub Gists][gists] via
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  #
3
- # kramdown-gist.rb - kramdown extension for gist tags
3
+ # kramdown-gist.rb - Kramdown extension for gist tags
4
4
  # Copyright (C) 2012 Matteo Panella <morpheus@level28.org>
5
5
  #
6
6
  # This program is free software: you can redistribute it and/or modify
@@ -19,87 +19,17 @@
19
19
  require 'kramdown-gist/version'
20
20
 
21
21
  require 'kramdown'
22
- require 'kramdown/parser/kramdown'
23
22
 
24
23
  module Kramdown
25
24
 
25
+ # Monkey-patch Element class to include :gist as a block-level element
26
26
  # @private
27
27
  class Element
28
28
  # Register :gist as a block-level element
29
29
  CATEGORY[:gist] = :block
30
30
  end
31
31
 
32
- module Parser
33
-
34
- # Standard Kramdown parser with support for embedding GitHub Gists
35
- # in the output.
36
- #
37
- # This class extends the default Kramdown syntax with a new block-level
38
- # element for embedding gists: `*{gist:<id>}`. The element is rendered
39
- # as a `<script>` tag pointing to `http://gist.github.com/<id>.js`.
40
- #
41
- # @author Matteo Panella
42
- class KramdownGist < ::Kramdown::Parser::Kramdown
43
-
44
- # Create a new gist-enabled Kramdown parser with the given `options`.
45
- def initialize(source, options)
46
- super
47
- @block_parsers.unshift(:gist)
48
- end
49
-
50
- # Regex for matching a gist tag
51
- # @private
52
- GIST_START = /^#{OPT_SPACE}\*\{gist:(\h+?)\}\n/
53
-
54
- # Do not use this method directly, it's used internally by Kramdown.
55
- # @api private
56
- def parse_gist
57
- @src.pos += @src.matched_size
58
- gist_id = @src[1]
59
- @tree.children << Element.new(:gist, gist_id)
60
- end
61
- define_parser(:gist, GIST_START)
62
-
63
- end
64
-
65
- end
66
-
67
- module Converter
68
- class Html
69
-
70
- # Convert a gist element into a `<script>` tag suitable for embedding.
71
- #
72
- # @return [String] an HTML fragment representing this element
73
- # @api private
74
- def convert_gist(el, indent)
75
- "#{' '*indent}<script src=\"http://gist.github.com/#{el.value}.js\"></script>\n"
76
- end
77
-
78
- end
79
-
80
- class Kramdown
81
-
82
- # Convert a gist element into the equivalent Kramdown "tag"
83
- #
84
- # @return [String] an Kramdown fragment representing this element
85
- # @api private
86
- def convert_gist(el, opts)
87
- "*{gist:#{el.value}}\n"
88
- end
89
- end
90
-
91
- class Latex
92
-
93
- # Convert a gist element into a LaTeX paragraph stating the Gist ID and
94
- # including the target hyperlink as metadata suitable for some output
95
- # formats (PDF).
96
- #
97
- # @return [String] a LaTeX fragment representing this element
98
- # @api private
99
- def convert_gist(el, opts)
100
- gist_id = el.value
101
- "See \\href{https://gist.github.com/#{gist_id}}{Gist #{gist_id}}.\n\n"
102
- end
103
- end
104
- end
105
32
  end
33
+
34
+ require 'kramdown-gist/parser'
35
+ require 'kramdown-gist/converter'
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+ #
3
+ # converter.rb - monkey-patches for Kramdown converters
4
+ # Copyright (C) 2012 Matteo Panella <morpheus@level28.org>
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ module Kramdown
20
+ module Converter
21
+
22
+ class Html
23
+
24
+ # Convert a gist element into a `<script>` tag suitable for embedding.
25
+ #
26
+ # @return [String] an HTML fragment representing this element
27
+ # @api private
28
+ def convert_gist(el, indent)
29
+ "#{' '*indent}<script src=\"https://gist.github.com/#{el.value}.js\"></script>\n"
30
+ end
31
+
32
+ end
33
+
34
+ class Kramdown
35
+
36
+ # Convert a gist element into the equivalent Kramdown "tag"
37
+ #
38
+ # @return [String] an Kramdown fragment representing this element
39
+ # @api private
40
+ def convert_gist(el, opts)
41
+ "*{gist:#{el.value}}\n"
42
+ end
43
+
44
+ end
45
+
46
+ class Latex
47
+
48
+ # Convert a gist element into a LaTeX paragraph stating the Gist ID and
49
+ # including the target hyperlink as metadata suitable for some output
50
+ # formats (PDF).
51
+ #
52
+ # @return [String] a LaTeX fragment representing this element
53
+ # @api private
54
+ def convert_gist(el, opts)
55
+ gist_id = el.value
56
+ "See \\href{https://gist.github.com/#{gist_id}}{Gist #{gist_id}}.\n\n"
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ #
3
+ # parser.rb - gist-enabled parsers for Kramdown
4
+ # Copyright (C) 2012 Matteo Panella <morpheus@level28.org>
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ # Kramdown parser
20
+ require 'kramdown-gist/parser/kramdown'
21
+ # HTML parser
22
+ require 'kramdown-gist/parser/html'
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+ #
3
+ # html.rb - gist-enabled HTML parser
4
+ # Copyright (C) 2012 Matteo Panella <morpheus@level28.org>
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ require 'kramdown/parser/html'
20
+
21
+ module Kramdown
22
+ module Parser
23
+
24
+ class Html
25
+
26
+ # Monkey-patch the standard Kramdown HTML post-processor so that all
27
+ # references to embedded gists are replaced with a specialized `:gist` Element.
28
+ class ElementConverter
29
+
30
+ # This is the ugliest hack I *ever* wrote, believe me...
31
+ # @private
32
+ original_convert_script = instance_method(:convert_script)
33
+
34
+ # @!method convert_script(el)
35
+ # Hook into the `<script>` tag conversion process so that we have a
36
+ # chance to generate `:gist` elements based on the `src` attribute
37
+ # of the tag.
38
+ # @api private
39
+ define_method(:convert_script) do |el|
40
+ if %r{^https?://gist.github.com/([0-9a-fA-F]+)\.js$} =~ el.attr['src']
41
+ # We're in business, convert el to a gist element
42
+ set_basics(el, :gist)
43
+ el.value = $1
44
+ el.children.clear
45
+ el.attr.delete('src')
46
+ else
47
+ # Fall back to the original method
48
+ original_convert_script.bind(self).call(el)
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+ #
3
+ # kramdown.rb - gist-enabled kramdown parser
4
+ # Copyright (C) 2012 Matteo Panella <morpheus@level28.org>
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ require 'kramdown/parser/kramdown'
20
+
21
+ module Kramdown
22
+ module Parser
23
+
24
+ # Standard Kramdown parser with support for embedding GitHub Gists
25
+ # in the output.
26
+ #
27
+ # This class extends the default Kramdown syntax with a new block-level
28
+ # element for embedding gists: `*{gist:<id>}`. The element is rendered
29
+ # as a `<script>` tag pointing to `http://gist.github.com/<id>.js`.
30
+ #
31
+ # @author Matteo Panella
32
+ class KramdownGist < ::Kramdown::Parser::Kramdown
33
+
34
+ # Create a new gist-enabled Kramdown parser with the given `options`.
35
+ def initialize(source, options)
36
+ super
37
+ @block_parsers.unshift(:gist)
38
+ end
39
+
40
+ # Regex for matching a gist tag
41
+ # @private
42
+ GIST_START = /^#{OPT_SPACE}\*\{gist:([0-9a-fA-F]+?)\}\n/
43
+
44
+ # Do not use this method directly, it's used internally by Kramdown.
45
+ # @api private
46
+ def parse_gist
47
+ @src.pos += @src.matched_size
48
+ gist_id = @src[1]
49
+ @tree.children << Element.new(:gist, gist_id)
50
+ end
51
+ define_parser(:gist, GIST_START)
52
+
53
+ end
54
+
55
+ end
56
+ end
@@ -20,6 +20,6 @@
20
20
  module Kramdown
21
21
  module Parser
22
22
  # Version of {Kramdown::Parser::KramdownGist}
23
- KRAMDOWN_GIST_VERSION = "0.0.2"
23
+ KRAMDOWN_GIST_VERSION = "0.1.0"
24
24
  end
25
25
  end
@@ -0,0 +1,48 @@
1
+ <p>Das ist gewöhnlich <em>ein</em> <a href="http://example.org">Über-Problem</a> mit manchen<br />
2
+ Sälen <a href="http://example.org">http://example.org</a> und <span id="test">anderen Dinge</span>. Siehe
3
+ <img src="http://example.org" alt="Über mich" />!</p>
4
+
5
+ <blockquote class="test">
6
+ <p>Vielleicht <em class="red">höre</em> ich nicht richtig?</p>
7
+ </blockquote>
8
+
9
+ <ul>
10
+ <li>Sollten wir uns das überl<em>egen</em>? <em>Verhöhne</em> mich nicht!</li>
11
+ <li>Ho ho höher! Sind *wir* da?</li>
12
+ </ul>
13
+
14
+ <h1 id="titel-sind-urschn">Titel sind urschön</h1>
15
+
16
+ <h2 id="hot">Manche mögens <em>ärmer</em></h2>
17
+
18
+ <pre><code>öha
19
+ was nun?
20
+ </code></pre>
21
+
22
+ <dl>
23
+ <dt>Töne</dt>
24
+ <dd>Laute Geräusche</dd>
25
+ <dd>vielleicht noch was ä<em>hnliches</em></dd>
26
+ </dl>
27
+
28
+ <table>
29
+ <thead>
30
+ <tr>
31
+ <th>hoch</th>
32
+ <th>höher</th>
33
+ <th>am höchsten</th>
34
+ </tr>
35
+ </thead>
36
+ <tbody>
37
+ <tr>
38
+ <td>über</td>
39
+ <td>drüber</td>
40
+ <td>müde</td>
41
+ </tr>
42
+ </tbody>
43
+ </table>
44
+
45
+ <script src="https://gist.github.com/1234.js"></script>
46
+
47
+ <p>Das ist schön
48
+ gemacht</p>
@@ -0,0 +1,30 @@
1
+ Das ist gewöhnlich *ein* [Über-Problem](http://example.org) mit manchen
2
+ Sälen <http://example.org> und <span id='test'>anderen Dinge</span>. Siehe
3
+ ![Über mich](http://example.org)!
4
+
5
+ > Vielleicht *höre*{:.red} ich nicht richtig?
6
+ {:.test}
7
+
8
+ * Sollten wir uns das überl*egen*? *Verhöhne* mich nicht!
9
+ * Ho ho höher! Sind \*wir\* da?
10
+
11
+ Titel sind urschön
12
+ ==================
13
+
14
+ ## Manche mögens *ärmer* {#hot}
15
+
16
+ öha
17
+ was nun?
18
+
19
+ Töne
20
+ : Laute Geräusche
21
+ : vielleicht noch was ä*hnliches*
22
+
23
+ | hoch | höher | am höchsten |
24
+ |----------------------------|
25
+ | über | drüber | müde |
26
+
27
+ *{gist:1234}
28
+
29
+ <p markdown='1'>Das ist schön
30
+ gemacht</p>
@@ -0,0 +1,39 @@
1
+ Das ist gewöhnlich \emph{ein} \href{http://example.org}{Über-Problem} mit manchen\newline
2
+ Sälen \href{http://example.org}{http://example.org} und . Siehe
3
+ !
4
+
5
+ \begin{quote} % class="test"
6
+ Vielleicht \emph{höre} ich nicht richtig?
7
+ \end{quote} % class="test"
8
+
9
+ \begin{itemize}
10
+ \item Sollten wir uns das überl\emph{egen}? \emph{Verhöhne} mich nicht!
11
+ \item Ho ho höher! Sind *wir* da?
12
+ \end{itemize}
13
+
14
+ \section{Titel sind urschön}\hypertarget{titel-sind-urschn}{}\label{titel-sind-urschn}
15
+
16
+ \subsection{Manche mögens \emph{ärmer}}\hypertarget{hot}{}\label{hot}
17
+
18
+ \begin{verbatim}öha
19
+ was nun?
20
+ \end{verbatim}
21
+
22
+ \begin{description}
23
+ \item[Töne] Laute Geräusche
24
+
25
+
26
+
27
+ vielleicht noch was ä\emph{hnliches}
28
+ \end{description}
29
+
30
+ \begin{longtable}{|l|l|l|}
31
+ \hline
32
+ hoch & höher & am höchsten\\
33
+ \hline
34
+ über & drüber & müde\\
35
+ \hline
36
+ \end{longtable}
37
+
38
+ See \href{https://gist.github.com/1234}{Gist 1234}.
39
+
@@ -0,0 +1,46 @@
1
+ <p>Das ist gewöhnlich <em>ein</em> <a href="http://example.org">Über-Problem</a> mit manchen<br />
2
+ Sälen <a href="http://example.org">http://example.org</a> und <span id="test">anderen Dinge</span>. Siehe
3
+ <img src="http://example.org" alt="Über mich" />!</p>
4
+
5
+ <blockquote class="test">
6
+ <p>Vielleicht <em class="red">höre</em> ich nicht richtig?</p>
7
+ </blockquote>
8
+
9
+ <ul>
10
+ <li>Sollten wir uns das überl<em>egen</em>? <em>Verhöhne</em> mich nicht!</li>
11
+ <li>Ho ho höher! Sind *wir* da?</li>
12
+ </ul>
13
+
14
+ <h1 id="titel-sind-urschn">Titel sind urschön</h1>
15
+
16
+ <h2 id="hot">Manche mögens <em>ärmer</em></h2>
17
+
18
+ <pre><code>öha
19
+ was nun?
20
+ </code></pre>
21
+
22
+ <dl>
23
+ <dt>Töne</dt>
24
+ <dd>Laute Geräusche</dd>
25
+ <dd>vielleicht noch was ä<em>hnliches</em></dd>
26
+ </dl>
27
+
28
+ <table>
29
+ <thead>
30
+ <tr>
31
+ <th>hoch</th>
32
+ <th>höher</th>
33
+ <th>am höchsten</th>
34
+ </tr>
35
+ </thead>
36
+ <tbody>
37
+ <tr>
38
+ <td>über</td>
39
+ <td>drüber</td>
40
+ <td>müde</td>
41
+ </tr>
42
+ </tbody>
43
+ </table>
44
+
45
+ <p>Das ist schön
46
+ gemacht</p>
@@ -0,0 +1,28 @@
1
+ Das ist gewöhnlich *ein* [Über-Problem](http://example.org) mit manchen
2
+ Sälen <http://example.org> und <span id='test'>anderen Dinge</span>. Siehe
3
+ ![Über mich](http://example.org)!
4
+
5
+ > Vielleicht *höre*{:.red} ich nicht richtig?
6
+ {:.test}
7
+
8
+ * Sollten wir uns das überl*egen*? *Verhöhne* mich nicht!
9
+ * Ho ho höher! Sind \*wir\* da?
10
+
11
+ Titel sind urschön
12
+ ==================
13
+
14
+ ## Manche mögens *ärmer* {#hot}
15
+
16
+ öha
17
+ was nun?
18
+
19
+ Töne
20
+ : Laute Geräusche
21
+ : vielleicht noch was ä*hnliches*
22
+
23
+ | hoch | höher | am höchsten |
24
+ |----------------------------|
25
+ | über | drüber | müde |
26
+
27
+ <p markdown='1'>Das ist schön
28
+ gemacht</p>
@@ -0,0 +1,37 @@
1
+ Das ist gewöhnlich \emph{ein} \href{http://example.org}{Über-Problem} mit manchen\newline
2
+ Sälen \href{http://example.org}{http://example.org} und . Siehe
3
+ !
4
+
5
+ \begin{quote} % class="test"
6
+ Vielleicht \emph{höre} ich nicht richtig?
7
+ \end{quote} % class="test"
8
+
9
+ \begin{itemize}
10
+ \item Sollten wir uns das überl\emph{egen}? \emph{Verhöhne} mich nicht!
11
+ \item Ho ho höher! Sind *wir* da?
12
+ \end{itemize}
13
+
14
+ \section{Titel sind urschön}\hypertarget{titel-sind-urschn}{}\label{titel-sind-urschn}
15
+
16
+ \subsection{Manche mögens \emph{ärmer}}\hypertarget{hot}{}\label{hot}
17
+
18
+ \begin{verbatim}öha
19
+ was nun?
20
+ \end{verbatim}
21
+
22
+ \begin{description}
23
+ \item[Töne] Laute Geräusche
24
+
25
+
26
+
27
+ vielleicht noch was ä\emph{hnliches}
28
+ \end{description}
29
+
30
+ \begin{longtable}{|l|l|l|}
31
+ \hline
32
+ hoch & höher & am höchsten\\
33
+ \hline
34
+ über & drüber & müde\\
35
+ \hline
36
+ \end{longtable}
37
+
@@ -19,28 +19,82 @@
19
19
  require 'kramdown-gist'
20
20
 
21
21
  describe Kramdown::Parser::KramdownGist do
22
- it "converts a valid public gist tag to a script tag" do
23
- ::Kramdown::Document.new("*{gist:1234}\n", :input => 'KramdownGist').to_html.should eql("<script src=\"http://gist.github.com/1234.js\"></script>\n")
24
- end
22
+ context "when parsing a simple block" do
23
+ it "converts a valid public gist tag to a script tag" do
24
+ ::Kramdown::Document.new("*{gist:1234}\n", :input => 'KramdownGist').to_html.should eql("<script src=\"https://gist.github.com/1234.js\"></script>\n")
25
+ end
25
26
 
26
- it "converts a valid private gist tag to a script tag" do
27
- ::Kramdown::Document.new("*{gist:deadbeef}", :input => 'KramdownGist').to_html.should eql("<script src=\"http://gist.github.com/deadbeef.js\"></script>\n")
28
- end
27
+ it "converts a valid private gist tag to a script tag" do
28
+ ::Kramdown::Document.new("*{gist:deadbeef}", :input => 'KramdownGist').to_html.should eql("<script src=\"https://gist.github.com/deadbeef.js\"></script>\n")
29
+ end
29
30
 
30
- it "falls back to default behaviour on malformed tag" do
31
- ::Kramdown::Document.new("*{gist:antani}", :input => 'KramdownGist').to_html.should eql("<p>*{gist:antani}</p>\n")
32
- end
31
+ it "falls back to default behaviour when the tag is malformed" do
32
+ ::Kramdown::Document.new("*{gist:antani}", :input => 'KramdownGist').to_html.should eql("<p>*{gist:antani}</p>\n")
33
+ end
34
+
35
+ it "does not treat the gist tag as a span-level element" do
36
+ ::Kramdown::Document.new("testing 123 *{gist:1234}", :input => 'KramdownGist').to_html.should eql("<p>testing 123 *{gist:1234}</p>\n")
37
+ ::Kramdown::Document.new("testing 123\n*{gist:1234}", :input => 'KramdownGist').to_html.should eql("<p>testing 123\n*{gist:1234}</p>\n")
38
+ end
33
39
 
34
- it "does not treat the gist tag as a span-level element" do
35
- ::Kramdown::Document.new("testing 123 *{gist:1234}", :input => 'KramdownGist').to_html.should eql("<p>testing 123 *{gist:1234}</p>\n")
36
- ::Kramdown::Document.new("testing 123\n*{gist:1234}", :input => 'KramdownGist').to_html.should eql("<p>testing 123\n*{gist:1234}</p>\n")
40
+ it "is idempotent when generating kramdown" do
41
+ ::Kramdown::Document.new("*{gist:1234}", :input => 'KramdownGist').to_kramdown.should eql("*{gist:1234}\n\n")
42
+ end
43
+
44
+ it "renders to a suitable placeholder when generating LaTeX" do
45
+ ::Kramdown::Document.new("*{gist:1234}", :input => 'KramdownGist').to_latex.should eql("See \\href{https://gist.github.com/1234}{Gist 1234}.\n\n")
46
+ end
37
47
  end
38
48
 
39
- it "is idempotent when generating kramdown" do
40
- ::Kramdown::Document.new("*{gist:1234}", :input => 'KramdownGist').to_kramdown.should eql("*{gist:1234}\n\n")
49
+ context "when parsing a complex document" do
50
+ # Standard kramdown source and rendered files
51
+ let(:standard_src) { IO.read(File.expand_path("../fixtures/standard.md", __FILE__)) }
52
+ let(:standard_html) { IO.read(File.expand_path("../fixtures/standard.html", __FILE__)) }
53
+ let(:standard_latex) { IO.read(File.expand_path("../fixtures/standard.tex", __FILE__)) }
54
+
55
+ # KramdownGist source and rendered files
56
+ let(:gist_src) { IO.read(File.expand_path("../fixtures/gist.md", __FILE__)) }
57
+ let(:gist_html) { IO.read(File.expand_path("../fixtures/gist.html", __FILE__)) }
58
+ let(:gist_latex) { IO.read(File.expand_path("../fixtures/gist.tex", __FILE__)) }
59
+
60
+ context "without gist tags" do
61
+ it "produces valid HTML output" do
62
+ ::Kramdown::Document.new(standard_src, :input => 'KramdownGist').to_html.should eql(standard_html)
63
+ end
64
+
65
+ it "produces valid LaTeX output" do
66
+ ::Kramdown::Document.new(standard_src, :input => 'KramdownGist').to_latex.should eql(standard_latex)
67
+ end
68
+ end
69
+
70
+ context "with gist tags" do
71
+ it "produces valid HTML output" do
72
+ ::Kramdown::Document.new(gist_src, :input => 'KramdownGist').to_html.should eql(gist_html)
73
+ end
74
+
75
+ it "produces valid LaTeX output" do
76
+ ::Kramdown::Document.new(gist_src, :input => 'KramdownGist').to_latex.should eql(gist_latex)
77
+ end
78
+ end
41
79
  end
80
+ end
81
+
82
+ describe Kramdown::Parser::Html do
83
+ context "when parsing a simple script tag" do
84
+ let(:jquery) { '<script src="http://code.jquery.com/jquery.min.js"></script>' }
85
+ let(:mathjax_src) { '<script type="math/tex; mode=display">1</script>' }
86
+ let(:mathjax_out) { "$$1$$\n\n" }
87
+
88
+ it "should convert embedded gists to gist tags" do
89
+ ::Kramdown::Document.new('<script src="https://gist.github.com/42.js"></script>', :input => 'html').to_kramdown.should eql("*{gist:42}\n\n")
90
+ end
91
+
92
+ it "should leave non-gist script tags as they are" do
93
+ ::Kramdown::Document.new(jquery, :input => 'html').to_kramdown.should eql("#{jquery}\n\n")
94
+ end
42
95
 
43
- it "renders to a suitable placeholder when generating LaTeX" do
44
- ::Kramdown::Document.new("*{gist:1234}", :input => 'KramdownGist').to_latex.should eql("See \\href{https://gist.github.com/1234}{Gist 1234}.\n\n")
96
+ it "should convert MathJax script tags to LaTeX math blocks" do
97
+ ::Kramdown::Document.new(mathjax_src, :input => 'html').to_kramdown.should eql(mathjax_out)
98
+ end
45
99
  end
46
100
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kramdown-gist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-16 00:00:00.000000000 Z
12
+ date: 2012-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: kramdown
@@ -115,7 +115,6 @@ extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
117
  - .gitignore
118
- - .rvmrc
119
118
  - .travis.yml
120
119
  - .yardopts
121
120
  - AUTHORS
@@ -125,7 +124,17 @@ files:
125
124
  - Rakefile
126
125
  - kramdown-gist.gemspec
127
126
  - lib/kramdown-gist.rb
127
+ - lib/kramdown-gist/converter.rb
128
+ - lib/kramdown-gist/parser.rb
129
+ - lib/kramdown-gist/parser/html.rb
130
+ - lib/kramdown-gist/parser/kramdown.rb
128
131
  - lib/kramdown-gist/version.rb
132
+ - spec/fixtures/gist.html
133
+ - spec/fixtures/gist.md
134
+ - spec/fixtures/gist.tex
135
+ - spec/fixtures/standard.html
136
+ - spec/fixtures/standard.md
137
+ - spec/fixtures/standard.tex
129
138
  - spec/kramdown-gist_spec.rb
130
139
  homepage: https://github.com/rfc1459/kramdown-gist
131
140
  licenses: []
@@ -152,5 +161,11 @@ signing_key:
152
161
  specification_version: 3
153
162
  summary: Extend Kramdown syntax to generate script tags for embedded gists
154
163
  test_files:
164
+ - spec/fixtures/gist.html
165
+ - spec/fixtures/gist.md
166
+ - spec/fixtures/gist.tex
167
+ - spec/fixtures/standard.html
168
+ - spec/fixtures/standard.md
169
+ - spec/fixtures/standard.tex
155
170
  - spec/kramdown-gist_spec.rb
156
171
  has_rdoc:
data/.rvmrc DELETED
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
- # development environment upon cd'ing into the directory
5
-
6
- # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
- # Only full ruby name is supported here, for short names use:
8
- # echo "rvm use 1.9.3" > .rvmrc
9
- environment_id="ruby-1.9.3-p286@kramdown-gist"
10
-
11
- # First we attempt to load the desired environment directly from the environment
12
- # file. This is very fast and efficient compared to running through the entire
13
- # CLI and selector. If you want feedback on which environment was used then
14
- # insert the word 'use' after --create as this triggers verbose mode.
15
- if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
16
- && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
17
- then
18
- \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
19
- [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
20
- \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
21
- else
22
- # If the environment file has not yet been created, use the RVM CLI to select.
23
- rvm --create "$environment_id" || {
24
- echo "Failed to create RVM environment '${environment_id}'."
25
- return 1
26
- }
27
- fi