octodown 1.0.0 → 1.0.1

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: 1ae27659b96dc1aed9d8e54fc5fae1eb5af80ecb
4
- data.tar.gz: a312690de332fd10839cc6d554c1caeb60043ed9
3
+ metadata.gz: bce562e8fb22b507adb9254a3a477e580e8476aa
4
+ data.tar.gz: 8bad0909539c3c0ec5976b899e3d8591db901b7c
5
5
  SHA512:
6
- metadata.gz: 01102c2586155236c32827b65e9ec201ed96b32e90beb10ceb594a08a6a3318e2ff4cdce647f07cb3cecf61d36f5a8ab18b6762e5fd7e5df3030b9cfcc4dc85d
7
- data.tar.gz: a27239bef742f5a5f4d42b63c0558f478428fe2e6992e671945cb5f181584db336c057e82970bd2a9d4961ad4dfb2304871ba5fbb61e3ced8a0bbb6f6e2695e4
6
+ metadata.gz: 52a608f823bea53fd6bfc09ba7cc4c5f5c40954d7977e798a6635c040e68e252c55c6013f1034b0e9e0ee574c7b0b24e694312f5c34ee0edd6d80702916e972a
7
+ data.tar.gz: 5e4d3e21b4127e3ac90ea4edbbc85231b771953c57ff1844f3490e218a92447c12bbc27d4ed4b24d17ccbf8e81e3adbcde6ad0b0276293218d77843fe6df90f9
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -7,16 +7,18 @@ Ever wanted to easily preview what you markdown would look like *exactly* on
7
7
  Github? Ever wanted to do that from inside of a Terminal? Well this Gem is for
8
8
  you. Dead simple. Never get caught writing ugly markdown again.
9
9
 
10
+ ![Octodown GIF](assets/octodown.gif?raw=true)
11
+
10
12
  ## Features:
11
13
 
12
14
  * Uses the same markdown parsers and CSS as Github for true duplication.
13
- - Yes emojis *are* included
15
+ - Yes emojis *are* included.
14
16
  * Fast. `octodown` uses native parsers to ensure performance.
15
- * Multiple CSS styles. Choose from either:
17
+ * Multiple CSS styles. Choose from either.
16
18
  - `$ octodown --style atom README.md`
17
19
  - The `github.com` markdown (default)
18
20
  - The `Atom` text editor markdown
19
- * Properly parses `STDIN`
21
+ * Properly parses `STDIN`.
20
22
  - `$ cat README.md | octodown`
21
23
 
22
24
  ## Installation
@@ -33,17 +35,17 @@ you. Dead simple. Never get caught writing ugly markdown again.
33
35
 
34
36
  1. Basic:
35
37
  * `$ octodown README.md`
36
- 2. Markdown preview styling
38
+ 2. Markdown preview styling:
37
39
  * `$ octodown --style atom README.md`
38
- 3. *nix lovers
40
+ 3. *nix lovers:
39
41
  * `$ echo '# Hello world!' | octodown --raw > index.html`
40
42
 
41
43
  ## Notes
42
44
 
43
- 1. With no arguments given, octodown will read STDIN until EOF is reached. In
44
- order to work with this mode, type what you want into the input, then press
45
+ 1. With no arguments given, octodown will read `STDIN` until `EOF` is reached.
46
+ * In order to work with this mode, type what you want into the input, then press
45
47
  `Ctrl-D` when finished.
46
- 2. octodown attempts to use default OS support for opening HTML files from
48
+ 2. `octodown` attempts to use default OS support for opening HTML files from
47
49
  terminal. In Mac, this would be the `open` command; for Linux it is either
48
50
  `xdg-open` or `x-www-browser`. If these are not set, octodown will not
49
51
  automatically open the file in the browser. If octodown doesn't have the
Binary file
data/bin/octodown CHANGED
@@ -11,10 +11,7 @@ OptionParser.new do |opts|
11
11
  opts.banner = 'Usage: octodown [options]'
12
12
 
13
13
  opts.on(
14
- '-s',
15
- '--style [STYLE]',
16
- [:github, :atom],
17
- 'Choose style (atom, github)'
14
+ '-s', '--style [STYLE]', [:github, :atom], 'Choose style (atom, github)'
18
15
  ) do |s|
19
16
  options[:style] = s
20
17
  end
@@ -32,15 +29,15 @@ end.parse!
32
29
  def main(options)
33
30
  include Octodown::Support
34
31
 
35
- input_contents = ARGF.read
32
+ content = ARGF.read
36
33
  style = options[:style] || 'github'
34
+ path = File.dirname(File.expand_path(ARGF.path))
37
35
 
38
36
  if options[:raw]
39
- puts Helpers.markdown_to_raw_html input_contents, style
37
+ puts Helpers.markdown_to_raw_html content, style, path
40
38
  else
41
- browser = Browser.new
42
- html_file = Helpers.markdown_to_html input_contents, style
43
- browser.open html_file
39
+ html_file = Helpers.markdown_to_html content, style, path
40
+ Browser.new.open html_file
44
41
  end
45
42
  end
46
43
 
@@ -5,10 +5,11 @@ require 'html/pipeline'
5
5
  module Octodown
6
6
  module Renderer
7
7
  class GithubMarkdown
8
- attr_reader :content
8
+ attr_reader :content, :document_root
9
9
 
10
- def initialize(content)
10
+ def initialize(content, document_root)
11
11
  @content = content
12
+ @document_root = document_root
12
13
  end
13
14
 
14
15
  def to_html
@@ -18,12 +19,16 @@ module Octodown
18
19
  private
19
20
 
20
21
  def context
21
- { :asset_root => 'https://assets-cdn.github.com/images/icons/' }
22
+ {
23
+ :asset_root => 'https://assets-cdn.github.com/images/icons/',
24
+ :original_document_root => document_root
25
+ }
22
26
  end
23
27
 
24
28
  def pipeline
25
29
  ::HTML::Pipeline.new [
26
30
  ::HTML::Pipeline::MarkdownFilter,
31
+ ::Octodown::Support::RelativeRootFilter,
27
32
  ::HTML::Pipeline::SanitizationFilter,
28
33
  ::HTML::Pipeline::ImageMaxWidthFilter,
29
34
  ::HTML::Pipeline::MentionFilter,
@@ -1,16 +1,18 @@
1
1
  module Octodown
2
2
  module Support
3
3
  module Helpers
4
+ include Octodown::Renderer
5
+
4
6
  # TODO: Find a better home for this logic
5
- def self.markdown_to_html(contents, template)
6
- html = markdown_to_raw_html(contents, template)
7
+ def self.markdown_to_html(content, template, path)
8
+ html = markdown_to_raw_html(content, template, path)
7
9
  tmp = Octodown::Support::HTMLFile.new 'octodown'
8
10
  tmp.persistent_write html
9
11
  end
10
12
 
11
- def self.markdown_to_raw_html(contents, template)
12
- unstyled_html = Octodown::Renderer::GithubMarkdown.new(contents).to_html
13
- Octodown::Renderer::HTML.new(unstyled_html, template).render
13
+ def self.markdown_to_raw_html(content, template, path)
14
+ unstyled_html = GithubMarkdown.new(content, path).to_html
15
+ HTML.new(unstyled_html, template).render
14
16
  end
15
17
  end
16
18
  end
@@ -0,0 +1,28 @@
1
+ require 'uri'
2
+
3
+ module Octodown
4
+ module Support
5
+ class RelativeRootFilter < HTML::Pipeline::Filter
6
+ def call
7
+ doc.search('img').each do |img|
8
+ next if img['src'].nil?
9
+
10
+ src = img['src'].strip
11
+
12
+ img['src'] = relative_path_from_document_root src unless http_uri? src
13
+ end
14
+
15
+ doc
16
+ end
17
+
18
+ def relative_path_from_document_root(src)
19
+ File.join(context[:original_document_root], src).to_s
20
+ end
21
+
22
+ def http_uri?(src)
23
+ parsed_uri = URI.parse src
24
+ parsed_uri.is_a? URI::HTTP
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Octodown
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
data/lib/octodown.rb CHANGED
@@ -2,6 +2,7 @@ require 'octodown/renderer/github_markdown'
2
2
  require 'octodown/renderer/html'
3
3
  require 'octodown/support/browser'
4
4
  require 'octodown/support/helpers'
5
+ require 'octodown/support/relative_root_filter'
5
6
  require 'octodown/support/html_file'
6
7
  require 'octodown/version'
7
8
 
@@ -3,7 +3,7 @@ require 'tempfile'
3
3
  describe Octodown::Renderer::GithubMarkdown do
4
4
  let(:dummy_path) { File.join(File.dirname(__FILE__), 'dummy', 'test.md') }
5
5
  let(:html) do
6
- Octodown::Renderer::GithubMarkdown.new(File.read(dummy_path)).to_html
6
+ Octodown::Renderer::GithubMarkdown.new(File.read(dummy_path), 'tmp').to_html
7
7
  end
8
8
 
9
9
  it 'create HTML from markdown file' do
@@ -0,0 +1,14 @@
1
+ require 'tempfile'
2
+
3
+ describe Octodown::Renderer::GithubMarkdown do
4
+ subject { Octodown::Support::RelativeRootFilter.new(nil) }
5
+
6
+ it 'detects an non-HTTP/HTTPS URI correctly' do
7
+ expect(subject.http_uri?('assets/test.png')).to eq false
8
+ end
9
+
10
+ it 'detects HTTP/HTTPS URI correctly' do
11
+ expect(subject.http_uri?('http://foo.com/assets/test.png')).to eq true
12
+ expect(subject.http_uri?('https://foo.com/assets/test.png')).to eq true
13
+ end
14
+ end
@@ -3,7 +3,7 @@ require 'tempfile'
3
3
  describe Octodown::Renderer::HTML do
4
4
  let(:dummy_path) { File.join(File.dirname(__FILE__), 'dummy', 'test.md') }
5
5
  let(:html) do
6
- Octodown::Renderer::GithubMarkdown.new(File.read(dummy_path)).to_html
6
+ Octodown::Renderer::GithubMarkdown.new(File.read(dummy_path), 'tmp').to_html
7
7
  end
8
8
 
9
9
  subject { Octodown::Renderer::HTML.new(html, 'github').render }
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octodown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Ker-Seymer
@@ -30,7 +30,7 @@ cert_chain:
30
30
  YGBeYMyEy7Q4wf7k4k5yyDUZyyaeg0DF/kNEN5llspJ9DHMP2cQqOiH+IQSNiUhR
31
31
  32sJqaZRHeJLDhZPLi5yXItTsQnPy6uob2oyypwFYTM=
32
32
  -----END CERTIFICATE-----
33
- date: 2015-01-02 00:00:00.000000000 Z
33
+ date: 2015-01-03 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: github-markup
@@ -205,6 +205,7 @@ files:
205
205
  - assets/atom.css
206
206
  - assets/favicon.png
207
207
  - assets/github.css
208
+ - assets/octodown.gif
208
209
  - bin/octodown
209
210
  - lib/octodown.rb
210
211
  - lib/octodown/renderer/github_markdown.rb
@@ -212,12 +213,14 @@ files:
212
213
  - lib/octodown/support/browser.rb
213
214
  - lib/octodown/support/helpers.rb
214
215
  - lib/octodown/support/html_file.rb
216
+ - lib/octodown/support/relative_root_filter.rb
215
217
  - lib/octodown/template/octodown.html.erb
216
218
  - lib/octodown/version.rb
217
219
  - octodown.gemspec
218
220
  - spec/browser_spec.rb
219
221
  - spec/dummy/test.md
220
222
  - spec/markdown_generation_spec.rb
223
+ - spec/relative_root_filter_spec.rb
221
224
  - spec/spec_helper.rb
222
225
  - spec/template_rendering_spec.rb
223
226
  homepage: https://github.com/ianks/octodown
@@ -248,5 +251,6 @@ test_files:
248
251
  - spec/browser_spec.rb
249
252
  - spec/dummy/test.md
250
253
  - spec/markdown_generation_spec.rb
254
+ - spec/relative_root_filter_spec.rb
251
255
  - spec/spec_helper.rb
252
256
  - spec/template_rendering_spec.rb
metadata.gz.sig CHANGED
Binary file