commonmarker-rouge 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 30f8a8522109e5dcf59cb138710483eaeb584054
4
+ data.tar.gz: 58c79d60e499663755c375fedff69e00ebcc67b2
5
+ SHA512:
6
+ metadata.gz: 426e93070c3a72e4f8881b80b955a3536da1f4f29e4cb61d4110ac9c68790aaf4b704ffbbcf26c3839b840bc9a4a14a56b1a5a0e2ff82b18cf37db5d86a56a75
7
+ data.tar.gz: ebb854343214a9ec370e59c0388ec64475f72eb9016f7d7a7bff7e4cdd06e7cdfc34e39dcbf4b1320166135dbebe0b9e530b5d479789b4e1b02070b5f02b7ecc
data/.gitignore ADDED
@@ -0,0 +1,33 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+ Gemfile.lock
29
+ .ruby-version
30
+ .ruby-gemset
31
+
32
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
33
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.10
5
+ - 2.2.4
6
+ - 2.3.0
7
+ - rbx
8
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Anton Smirnov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # CommonMarker+Rouge
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/commonmarker-rouge.svg)](https://badge.fury.io/rb/commonmarker-rouge)
4
+ [![Code Climate](https://codeclimate.com/github/sandfoxme/commonmarker-rouge/badges/gpa.svg)](https://codeclimate.com/github/sandfoxme/commonmarker-rouge)
5
+
6
+ A [CommonMarker](https://rubygems.org/gems/commonmarker) wrapper with
7
+ syntax highlight support by [Rouge](https://rubygems.org/gems/rouge).
8
+
9
+ ## Installation
10
+
11
+ Add these lines to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'commonmarker-rouge'
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ # use default CommonMarker class and Rouge::Formatters::HTML formatter
21
+ CommonMarker::Rouge.render_html(content)
22
+
23
+ # get CommonMarker parsed AST
24
+ CommonMarker::Rouge.render_doc(content)
25
+
26
+ # pass options to CommonMarker
27
+ CommonMarker::Rouge.render_html(content, [:normalize, :sourcepos])
28
+
29
+ # use custom CommonMarker wrapper (must provide compatible render_doc)
30
+ CommonMarker::Rouge.render_html(content, cmark_class: CommonMarkerWrapper)
31
+
32
+ # use custom Rouge formatter
33
+ CommonMarker::Rouge.render_html(content, formatter: Rouge::Formatters::HTMLLinewise)
34
+
35
+ # pass some options to Rouge
36
+ CommonMarker::Rouge.render_html(content, options: { css_class: 'custom-class' })
37
+ ```
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
42
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'commonmarker/rouge'
5
+
6
+ require 'pry'
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'commonmarker/rouge/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'commonmarker-rouge'
8
+ spec.version = CommonMarker::Rouge::VERSION
9
+ spec.authors = ['Anton Smirnov']
10
+ spec.email = ['sandfox@sandfox.me']
11
+
12
+ spec.summary = 'CommonMarker wrapper with Rouge syntax highlighter'
13
+ spec.homepage = 'https://github.com/sandfoxme/commonmarker-rouge'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.required_ruby_version = '>= 2.0.0'
22
+
23
+ spec.add_dependency 'commonmarker', '~> 0.8.0'
24
+ spec.add_dependency 'rouge', '~> 1.10'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.11'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'simplecov'
30
+ end
@@ -0,0 +1,5 @@
1
+ module CommonMarker
2
+ module Rouge
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ require 'commonmarker/rouge/version'
2
+
3
+ require 'commonmarker'
4
+ require 'rouge'
5
+
6
+ module CommonMarker
7
+ module Rouge
8
+ module_function
9
+
10
+ def render_doc(text, cmark_options = :default, **highmark_options)
11
+ cmark = highmark_options[:cmark_class] || ::CommonMarker
12
+
13
+ ast = cmark.render_doc(text, cmark_options)
14
+ process_ast(ast, highmark_options)
15
+ ast
16
+ end
17
+
18
+ def render_html(text, cmark_options = :default)
19
+ render_doc(text, cmark_options).to_html
20
+ end
21
+
22
+ def process_ast(ast, highmark_options)
23
+ ast.walk do |node|
24
+ if node.type == :code_block
25
+ next if node.fence_info == ''
26
+
27
+ source = node.string_content
28
+
29
+ lexer = ::Rouge::Lexer.find_fancy(node.fence_info)
30
+
31
+ formatter = (highmark_options[:formatter] || ::Rouge::Formatters::HTML).new(highmark_options[:options] || {})
32
+
33
+ html = '<div class="highlighter-rouge">' + formatter.format(lexer.lex(source)) + '</div>'
34
+
35
+ new_node = ::CommonMarker::Node.new(:html)
36
+ new_node.string_content = html
37
+
38
+ node.insert_before(new_node)
39
+ node.delete
40
+ end
41
+ end
42
+ end
43
+
44
+ private_class_method :process_ast
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commonmarker-rouge
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Anton Smirnov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: commonmarker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rouge
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - sandfox@sandfox.me
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - commonmarker-rouge.gemspec
114
+ - lib/commonmarker/rouge.rb
115
+ - lib/commonmarker/rouge/version.rb
116
+ homepage: https://github.com/sandfoxme/commonmarker-rouge
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 2.0.0
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.4.8
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: CommonMarker wrapper with Rouge syntax highlighter
140
+ test_files: []