thredded-markdown_coderay 0.1.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: 0e53bf20c59640b5e4c301e6d82c94b4de21a242
4
+ data.tar.gz: 0d13156754ec8bd8a6fe8217f148d7fc76564408
5
+ SHA512:
6
+ metadata.gz: e31b62d8fa72c2b53fad286118a1102b7dc65cabba9a9ea560c59fb80f9781bbf6cdf2ca357936dcf4a975788be044a8adb15cdf3a7b45b3f46a55bfb33ac42c
7
+ data.tar.gz: 39a0204a0057dbb81c6459b0f6dd33bd469179cbae6ca94769aef1fa07ed91780e3b4c007b80912791d1a0bec45ff1c9609ca1fff9bd279182df64ca7916d1d3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Gleb Mazovetskiy
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Thredded Plugin: Syntax Highlighting in Markdown via Coderay [![Build Status](https://travis-ci.org/thredded/thredded-markdown_coderay.svg?branch=master)](https://travis-ci.org/thredded/thredded-markdown_coderay) [![Test Coverage](https://codeclimate.com/github/thredded/thredded-markdown_coderay/badges/coverage.svg)](https://codeclimate.com/github/thredded/thredded-markdown_coderay/coverage)
2
+
3
+ A Thredded plugin that Highlights code syntax in your Markdown posts via
4
+ [Coderay](https://github.com/rubychan/coderay).
5
+
6
+ The result with the default styles looks like this:
7
+
8
+ ![thredded-markdown_coderay](https://cloud.githubusercontent.com/assets/216339/20035926/46650068-a3b5-11e6-90b0-2530bf1d98f5.png)
9
+
10
+ Code language is not inferred, and must be specified, e.g.:
11
+
12
+ ```ruby
13
+ puts 'hi'
14
+ ```
15
+
16
+ or
17
+
18
+ ~~~ ruby
19
+ puts 'hi'
20
+ ~~~
21
+
22
+ Currently only supports the default Thredded markdown parser:
23
+ [Kramdown](https://github.com/gettalong/kramdown).
24
+
25
+ ## Installation
26
+
27
+ Add this line to your application's Gemfile:
28
+
29
+ ```ruby
30
+ gem 'thredded-markdown_coderay'
31
+ ```
32
+
33
+ And then execute:
34
+
35
+ ```bash
36
+ bundle
37
+ rails g thredded:markdown_coderay:install
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ \-
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies.
47
+ Then, run `rake spec` to run the tests. You can also run `bin/console` for an
48
+ interactive prompt that will allow you to experiment.
49
+
50
+ To install this gem onto your local machine, run `bundle exec rake install`.
51
+ To release a new version, update the version number in `version.rb`, and then
52
+ run `bundle exec rake release`, which will create a git tag for the version,
53
+ push git commits and tags, and push the `.gem` file to
54
+ [rubygems.org](https://rubygems.org).
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thredded/thredded-markdown_coderay. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
59
+
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the
64
+ [MIT License](http://opensource.org/licenses/MIT).
65
+
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+ module Thredded
3
+ module MarkdownCoderay
4
+ class InstallGenerator < Rails::Generators::Base
5
+ desc 'Installs Thredded Markdown Coderay plugin.'
6
+ source_root File.expand_path(
7
+ '../../../templates/thredded/markdown_coderay/install',
8
+ File.dirname(__FILE__)
9
+ )
10
+ public_task :install
11
+
12
+ def install
13
+ copy_file '_thredded-coderay.scss',
14
+ 'app/assets/stylesheets/_thredded-coderay.scss'
15
+ append_to_file 'app/assets/stylesheets/application.scss', <<~'SCSS'
16
+ @import "thredded-coderay";
17
+ SCSS
18
+ end
19
+
20
+ private
21
+
22
+ def coderay_css
23
+ require 'coderay'
24
+ CodeRay::Encoders[:html]::CSS.new(:default).stylesheet
25
+ end
26
+
27
+ def indent(multiplier, content)
28
+ spaces = ' ' * multiplier
29
+ content.each_line.map do |line|
30
+ line.blank? ? line : "#{spaces}#{line}"
31
+ end.join
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,139 @@
1
+ .thredded--post--content {
2
+ .CodeRay {
3
+ margin: 1rem 0;
4
+ }
5
+
6
+ .CodeRay {
7
+ color: #333;
8
+ }
9
+
10
+ .CodeRay pre {
11
+ margin: 0;
12
+ padding: 1em;
13
+ }
14
+
15
+ div.CodeRay { }
16
+ span.CodeRay { white-space: pre; border: 0; padding: 2px }
17
+
18
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
19
+ table.CodeRay td {
20
+ padding: 1em 0.5em;
21
+ vertical-align: top;
22
+ }
23
+
24
+ .CodeRay .line-numbers {
25
+ color: #AAA;
26
+ text-align: right;
27
+ user-select: none;
28
+ }
29
+
30
+ .CodeRay .line-numbers pre {
31
+ word-break: normal;
32
+ }
33
+
34
+ .CodeRay .line-numbers a {
35
+ color: #AAA;
36
+ }
37
+
38
+ .CodeRay .line-numbers tt { font-weight: bold }
39
+ .CodeRay .line-numbers .highlighted { color: red }
40
+ .CodeRay .line { display: block; float: left; width: 100%; }
41
+ .CodeRay span.line-numbers { padding: 0 10px 0 0 }
42
+ .CodeRay .code { width: 100% }
43
+
44
+ ol.CodeRay { font-size: 10pt }
45
+ ol.CodeRay li { white-space: pre }
46
+
47
+ .CodeRay .code pre { overflow: auto }
48
+ .CodeRay .debug { color:white ! important; background:blue ! important; }
49
+
50
+ .CodeRay .annotation { color:#007 }
51
+ .CodeRay .attribute-name { color:#f08 }
52
+ .CodeRay .attribute-value { color:#700 }
53
+ .CodeRay .binary { color:#509; font-weight:bold }
54
+ .CodeRay .comment { color:#998; font-style: italic;}
55
+ .CodeRay .char { color:#04D }
56
+ .CodeRay .char .content { color:#04D }
57
+ .CodeRay .char .delimiter { color:#039 }
58
+ .CodeRay .class { color:#458; font-weight:bold }
59
+ .CodeRay .complex { color:#A08; font-weight:bold }
60
+ .CodeRay .constant { color:teal; }
61
+ .CodeRay .color { color:#0A0 }
62
+ .CodeRay .class-variable { color:#369 }
63
+ .CodeRay .decorator { color:#B0B; }
64
+ .CodeRay .definition { color:#099; font-weight:bold }
65
+ .CodeRay .directive { color:#088; font-weight:bold }
66
+ .CodeRay .delimiter { color:black }
67
+ .CodeRay .doc { color:#970 }
68
+ .CodeRay .doctype { color:#34b }
69
+ .CodeRay .doc-string { color:#D42; font-weight:bold }
70
+ .CodeRay .escape { color:#666; font-weight:bold }
71
+ .CodeRay .entity { color:#800; font-weight:bold }
72
+ .CodeRay .error { color:#F00; background-color:#FAA }
73
+ .CodeRay .exception { color:#C00; font-weight:bold }
74
+ .CodeRay .filename { color:#099; }
75
+ .CodeRay .function { color:#900; font-weight:bold }
76
+ .CodeRay .global-variable { color:teal; font-weight:bold }
77
+ .CodeRay .hex { color:#058; font-weight:bold }
78
+ .CodeRay .integer { color:#099; }
79
+ .CodeRay .include { color:#B44; font-weight:bold }
80
+ .CodeRay .inline { color: black }
81
+ .CodeRay .inline .inline { background: #ccc }
82
+ .CodeRay .inline .inline .inline { background: #bbb }
83
+ .CodeRay .inline .inline-delimiter { color: #D14; }
84
+ .CodeRay .inline-delimiter { color: #D14; }
85
+ .CodeRay .important { color:#f00; }
86
+ .CodeRay .interpreted { color:#B2B; font-weight:bold }
87
+ .CodeRay .instance-variable { color:teal }
88
+ .CodeRay .label { color:#970; font-weight:bold }
89
+ .CodeRay .local-variable { color:#963 }
90
+ .CodeRay .octal { color:#40E; font-weight:bold }
91
+ .CodeRay .operator { }
92
+ .CodeRay .predefined-constant { font-weight:bold }
93
+ .CodeRay .predefined { color:#369; font-weight:bold }
94
+ .CodeRay .preprocessor { color:#579; }
95
+ .CodeRay .pseudo-class { color:#00C; font-weight:bold }
96
+ .CodeRay .predefined-type { color:#074; font-weight:bold }
97
+ .CodeRay .reserved, .keyword { color:#000; font-weight:bold }
98
+
99
+ .CodeRay .key { color: #808; }
100
+ .CodeRay .key .delimiter { color: #606; }
101
+ .CodeRay .key .char { color: #80f; }
102
+ .CodeRay .value { color: #088; }
103
+
104
+ .CodeRay .regexp { background-color:#fff0ff }
105
+ .CodeRay .regexp .content { color:#808 }
106
+ .CodeRay .regexp .delimiter { color:#404 }
107
+ .CodeRay .regexp .modifier { color:#C2C }
108
+ .CodeRay .regexp .function { color:#404; font-weight: bold }
109
+
110
+ .CodeRay .string { color: #D20; }
111
+ .CodeRay .string .string { }
112
+ .CodeRay .string .string .string { background-color:#ffd0d0 }
113
+ .CodeRay .string .content { color: #D14; }
114
+ .CodeRay .string .char { color: #D14; }
115
+ .CodeRay .string .delimiter { color: #D14; }
116
+
117
+ .CodeRay .shell { color:#D14 }
118
+ .CodeRay .shell .content { }
119
+ .CodeRay .shell .delimiter { color:#D14 }
120
+
121
+ .CodeRay .symbol { color:#990073 }
122
+ .CodeRay .symbol .content { color:#A60 }
123
+ .CodeRay .symbol .delimiter { color:#630 }
124
+
125
+ .CodeRay .tag { color:#070 }
126
+ .CodeRay .tag-special { color:#D70; font-weight:bold }
127
+ .CodeRay .type { color:#339; font-weight:bold }
128
+ .CodeRay .variable { color:#036 }
129
+
130
+ .CodeRay .insert { background: #afa; }
131
+ .CodeRay .delete { background: #faa; }
132
+ .CodeRay .change { color: #aaf; background: #007; }
133
+ .CodeRay .head { color: #f8f; background: #505 }
134
+
135
+ .CodeRay .insert .insert { color: #080; font-weight:bold }
136
+ .CodeRay .delete .delete { color: #800; font-weight:bold }
137
+ .CodeRay .change .change { color: #66f; }
138
+ .CodeRay .head .head { color: #f4f; }
139
+ }
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+ require 'thredded/markdown_coderay/version'
3
+ require 'thredded/markdown_coderay/railtie' if defined?(Rails)
4
+
5
+ module Thredded
6
+ module MarkdownCoderay
7
+ class << self
8
+ attr_accessor :options
9
+
10
+ def setup!
11
+ assert_pipeline_contains! 'Thredded::HtmlPipeline::KramdownFilter'
12
+ Thredded::HtmlPipeline::KramdownFilter.options.update(options)
13
+ %w(div span code table td ol).each do |tag|
14
+ whitelist_attribute! tag, 'class'
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def assert_pipeline_contains!(name)
21
+ return if pipeline_contains?(name)
22
+ raise "#{self.class.name} requires #{name} in" \
23
+ 'Thredded::ContentFormatter.pipeline_filters'
24
+ end
25
+
26
+ def pipeline_contains?(name)
27
+ Thredded::ContentFormatter.pipeline_filters.map(&:name).include?(name)
28
+ end
29
+
30
+ def whitelist_attribute!(tag, attribute)
31
+ whitelist_attr = Thredded::ContentFormatter.whitelist[:attributes]
32
+ whitelist_attr[tag] ||= []
33
+ return if whitelist_attr[tag].include?(attribute)
34
+ whitelist_attr[tag] << attribute
35
+ end
36
+ end
37
+
38
+ self.options = {
39
+ enable_coderay: true,
40
+ syntax_highlighter: 'coderay',
41
+ # See
42
+ syntax_highlighter_opts: {
43
+ css: 'class',
44
+ line_number_anchors: false
45
+ }
46
+ }
47
+ end
48
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module Thredded
3
+ module MarkdownCoderay
4
+ class Railtie < Rails::Railtie
5
+ initializer 'thredded.markdown_coderay', after: 'thredded' do
6
+ Thredded::MarkdownCoderay.setup!
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ module Thredded
3
+ module MarkdownCoderay
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thredded-markdown_coderay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gleb Mazovetskiy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: coderay
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.45'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.45'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thredded
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.0
83
+ description: Highlights code syntax in your Markdown posts via Coderay.
84
+ email:
85
+ - glex.spb@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE.txt
91
+ - README.md
92
+ - lib/generators/thredded/markdown_coderay/install_generator.rb
93
+ - lib/templates/thredded/markdown_coderay/install/_thredded-coderay.scss
94
+ - lib/thredded/markdown_coderay.rb
95
+ - lib/thredded/markdown_coderay/railtie.rb
96
+ - lib/thredded/markdown_coderay/version.rb
97
+ homepage: https://github.com/thredded/thredded-markdown_coderay
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '2.3'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.6.8
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Thredded Markdown code blocks highlighting via Coderay.
121
+ test_files: []