reverse_markdown 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae1d23f69d1494799f0b6773df49559fb53c6979
4
- data.tar.gz: 65231dac3cf20c1a549dd3807ad9c8a9c44a05ca
3
+ metadata.gz: d1ee719972c0c06f84c6df44ff2cacdec0d3630c
4
+ data.tar.gz: 857ee9cfc3c01374fe0904dbed85ed63fb58ce79
5
5
  SHA512:
6
- metadata.gz: 850a262c23e1ef0c661fa4e338cba4fc3e4a7c420ca5f7381eeaf65c63280ba00d861ee11f92b7340d7336caf441981eab1453f8b9c89d592678935eda0ec121
7
- data.tar.gz: d135d8464c76aa9a10cf03cbafe7670b8100c2dd10b9b7c62245f4b8bde79441eb9aeffaa13ec630c153595bde78d8f069a3929533109a7f19eb24fe77e8d68a
6
+ metadata.gz: 4f5d772f3847ed3cb6e82e8f177dc70cc1143bb6f38edaf98eaa554d0d2965f6a8f85fe14d7999b72ef824ea10a4d5eb93d991a6c7d51d609f34aafa8faf8859
7
+ data.tar.gz: dbb1c987a62990504c492879026ebdb37d3fb82bc7f12b16bdb60be920cb489e90cbf574162c39d96bdae145054abfdaddcd9eb7de7f66f7753fc3af77b73abb
@@ -10,4 +10,4 @@ script: "bundle exec rake spec"
10
10
  notifications:
11
11
  disabled: false
12
12
  recipients:
13
- - xijo@gmx.de
13
+ - johannes.opper@gmail.com
@@ -1,6 +1,10 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## 0.7.0 - February 2015
5
+ ### Added
6
+ - pre-tags support syntax github and confluence syntax highlighting now
7
+
4
8
  ## 0.6.1 - January 2015
5
9
  ### Changed
6
10
  - Setting config options in block style will last for all following `convert` calls.
data/README.md CHANGED
@@ -100,8 +100,11 @@ end
100
100
 
101
101
  # Thanks
102
102
 
103
- ..to Ben Woosley for his improvements to the first version.
104
-
105
- ..to Harlan T. Wood for his help with the newer versions.
106
-
107
- ..and all contributors
103
+ Thanks to all [contributors](https://github.com/xijo/reverse_markdown/graphs/contributors) and all other helpers:
104
+
105
+ - [Empact](https://github.com/Empact) Ben Woosley
106
+ - [harlantwood](https://github.com/harlantwood) Harlan T. Wood
107
+ - [aprescott](https://github.com/aprescott) Adam Prescott
108
+ - [danschultzer](https://github.com/danschultzer) Dan Schultzer
109
+ - [Benjamin-Dobell](https://github.com/Benjamin-Dobell) Benjamin Dobell
110
+ - [schkovich](https://github.com/schkovich) Goran Miskovic
@@ -1,15 +1,28 @@
1
- require 'base64'
2
-
3
1
  module ReverseMarkdown
4
2
  module Converters
5
3
  class Pre < Base
6
4
  def convert(node)
7
5
  if ReverseMarkdown.config.github_flavored
8
- "```\n" << node.text.strip << "\n```\n"
6
+ "\n```#{language(node)}\n" << node.text.strip << "\n```\n"
9
7
  else
10
8
  "\n\n " << node.text.strip.lines.to_a.join(" ") << "\n\n"
11
9
  end
12
10
  end
11
+
12
+ private
13
+
14
+ def language(node)
15
+ lang = language_from_highlight_class(node)
16
+ lang || language_from_confluence_class(node)
17
+ end
18
+
19
+ def language_from_highlight_class(node)
20
+ node.parent['class'].to_s[/highlight-([a-zA-Z0-9]+)/, 1]
21
+ end
22
+
23
+ def language_from_confluence_class(node)
24
+ node['class'].to_s[/brush:\s?(:?.*);/, 1]
25
+ end
13
26
  end
14
27
 
15
28
  register :pre, Pre.new
@@ -1,3 +1,3 @@
1
1
  module ReverseMarkdown
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -5,13 +5,13 @@ describe ReverseMarkdown::Converters::Blockquote do
5
5
  let(:converter) { ReverseMarkdown::Converters::Blockquote.new }
6
6
 
7
7
  it 'converts nested elements as well' do
8
- input = Nokogiri::XML.parse("<blockquote><ul><li>foo</li></ul></blockquote>").root
8
+ input = node_for("<blockquote><ul><li>foo</li></ul></blockquote>")
9
9
  result = converter.convert(input)
10
10
  expect(result).to eq "> - foo"
11
11
  end
12
12
 
13
13
  it 'can deal with paragraphs inside' do
14
- input = Nokogiri::XML.parse("<blockquote><p>Some text.</p><p>Some more text.</p></blockquote>").root
14
+ input = node_for("<blockquote><p>Some text.</p><p>Some more text.</p></blockquote>")
15
15
  result = converter.convert(input)
16
16
  expect(result).to eq "> Some text.\n> \n> Some more text."
17
17
  end
@@ -7,12 +7,12 @@ describe ReverseMarkdown::Converters::Del do
7
7
  before { ReverseMarkdown.config.github_flavored = true }
8
8
 
9
9
  it 'converts the input as expected' do
10
- input = Nokogiri::XML.parse('<del>deldeldel</del>').root
10
+ input = node_for('<del>deldeldel</del>')
11
11
  expect(converter.convert(input)).to eq '~~deldeldel~~'
12
12
  end
13
13
 
14
14
  it 'skips empty tags' do
15
- input = Nokogiri::XML.parse('<del></del>').root
15
+ input = node_for('<del></del>')
16
16
  expect(converter.convert(input)).to eq ''
17
17
  end
18
18
 
@@ -26,7 +26,7 @@ describe ReverseMarkdown::Converters::Del do
26
26
  before { ReverseMarkdown.config.github_flavored = false }
27
27
 
28
28
  it 'does not convert anything' do
29
- input = Nokogiri::XML.parse('<del>deldeldel</del>').root
29
+ input = node_for('<del>deldeldel</del>')
30
30
  expect(converter.convert(input)).to eq 'deldeldel'
31
31
  end
32
32
 
@@ -5,7 +5,7 @@ describe ReverseMarkdown::Converters::Li do
5
5
  let(:converter) { ReverseMarkdown::Converters::Li.new }
6
6
 
7
7
  it 'does not fail without a valid parent context' do
8
- input = Nokogiri::XML.parse("<li>foo</li>").root
8
+ input = node_for("<li>foo</li>")
9
9
  result = converter.convert(input)
10
10
  expect(result).to eq "- foo\n"
11
11
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe ReverseMarkdown::Converters::Pre do
4
+
5
+ let(:converter) { ReverseMarkdown::Converters::Pre.new }
6
+
7
+ context 'for standard markdown' do
8
+ before { ReverseMarkdown.config.github_flavored = false }
9
+
10
+ it 'converts with indentation' do
11
+ node = node_for("<pre>puts foo</pre>")
12
+ expect(converter.convert(node)).to include " puts foo\n"
13
+ end
14
+ end
15
+
16
+ context 'for github_flavored markdown' do
17
+ before { ReverseMarkdown.config.github_flavored = true }
18
+
19
+ it 'converts with backticks' do
20
+ node = node_for("<pre>puts foo</pre>")
21
+ expect(converter.convert(node)).to include "```\nputs foo\n```"
22
+ end
23
+
24
+ context 'syntax highlighting' do
25
+ it 'works for "highlight-lang" mechanism' do
26
+ div = node_for("<div class='highlight highlight-ruby'><pre>puts foo</pre></div>")
27
+ pre = div.children.first
28
+ expect(converter.convert(pre)).to include "```ruby\n"
29
+ end
30
+
31
+ it 'works for the confluence mechanism' do
32
+ pre = node_for("<pre class='theme: Confluence; brush: html/xml; gutter: false'>puts foo</pre>")
33
+ expect(converter.convert(pre)).to include "```html/xml\n"
34
+ end
35
+ end
36
+ end
37
+
38
+ end
@@ -5,25 +5,25 @@ describe ReverseMarkdown::Converters::Text do
5
5
  let(:converter) { ReverseMarkdown::Converters::Text.new }
6
6
 
7
7
  it 'treats newline within text as a single whitespace' do
8
- input = Nokogiri::XML.parse("<p>foo\nbar</p>").root
8
+ input = node_for("<p>foo\nbar</p>")
9
9
  result = converter.convert(input)
10
10
  expect(result).to eq 'foo bar'
11
11
  end
12
12
 
13
13
  it 'removes leading newlines' do
14
- input = Nokogiri::XML.parse("<p>\n\nfoo bar</p>").root
14
+ input = node_for("<p>\n\nfoo bar</p>")
15
15
  result = converter.convert(input)
16
16
  expect(result).to eq 'foo bar'
17
17
  end
18
18
 
19
19
  it 'removes trailing newlines' do
20
- input = Nokogiri::XML.parse("<p>foo bar\n\n</p>").root
20
+ input = node_for("<p>foo bar\n\n</p>")
21
21
  result = converter.convert(input)
22
22
  expect(result).to eq 'foo bar'
23
23
  end
24
24
 
25
25
  it 'keeps nbsps' do
26
- input = Nokogiri::XML.parse("<p>foo\u00A0bar \u00A0</p>").root
26
+ input = node_for("<p>foo\u00A0bar \u00A0</p>")
27
27
  result = converter.convert(input)
28
28
  expect(result).to eq "foo&nbsp;bar &nbsp;"
29
29
  end
@@ -18,3 +18,7 @@ RSpec.configure do |config|
18
18
  ReverseMarkdown.instance_variable_set(:@config, nil)
19
19
  end
20
20
  end
21
+
22
+ def node_for(html)
23
+ Nokogiri::XML.parse(html).root
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reverse_markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Opper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-25 00:00:00.000000000 Z
11
+ date: 2015-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -174,6 +174,7 @@ files:
174
174
  - spec/lib/reverse_markdown/converters/br_spec.rb
175
175
  - spec/lib/reverse_markdown/converters/del_spec.rb
176
176
  - spec/lib/reverse_markdown/converters/li_spec.rb
177
+ - spec/lib/reverse_markdown/converters/pre_spec.rb
177
178
  - spec/lib/reverse_markdown/converters/text_spec.rb
178
179
  - spec/lib/reverse_markdown_spec.rb
179
180
  - spec/spec_helper.rb
@@ -232,6 +233,7 @@ test_files:
232
233
  - spec/lib/reverse_markdown/converters/br_spec.rb
233
234
  - spec/lib/reverse_markdown/converters/del_spec.rb
234
235
  - spec/lib/reverse_markdown/converters/li_spec.rb
236
+ - spec/lib/reverse_markdown/converters/pre_spec.rb
235
237
  - spec/lib/reverse_markdown/converters/text_spec.rb
236
238
  - spec/lib/reverse_markdown_spec.rb
237
239
  - spec/spec_helper.rb