markdown-rails 2.0.0.alpha4 → 2.0.0.alpha6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -8
- data/lib/generators/markdown_rails/install/USAGE +9 -0
- data/lib/generators/{markdown → markdown_rails}/install/install_generator.rb +1 -1
- data/lib/generators/{markdown → markdown_rails}/install/templates/app/markdown/application_markdown.rb +2 -2
- data/lib/generators/{markdown → markdown_rails}/install/templates/config/initializers/markdown.rb +2 -2
- data/lib/markdown-rails/engine.rb +4 -0
- data/lib/markdown-rails/handler/erb.rb +22 -0
- data/lib/markdown-rails/handler/markdown.rb +37 -0
- data/lib/markdown-rails/railtie.rb +4 -0
- data/lib/markdown-rails/renderer/base.rb +26 -0
- data/lib/markdown-rails/renderer/rails.rb +40 -0
- data/lib/markdown-rails/version.rb +3 -0
- data/lib/markdown-rails.rb +18 -1
- metadata +12 -13
- data/lib/generators/markdown/install/USAGE +0 -8
- data/lib/markdown/rails/engine.rb +0 -6
- data/lib/markdown/rails/handler/erb.rb +0 -24
- data/lib/markdown/rails/handler/markdown.rb +0 -39
- data/lib/markdown/rails/railtie.rb +0 -6
- data/lib/markdown/rails/renderer/base.rb +0 -28
- data/lib/markdown/rails/renderer/rails.rb +0 -42
- data/lib/markdown/rails/version.rb +0 -5
- data/lib/markdown/rails.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a73a2cd07081bf36de70e5c18725718b4d327eb18f1db995099d9c564482f6ad
|
4
|
+
data.tar.gz: 856e66e13c5626612f7fdb5f316be468434a35d957091105385bc918736b18b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eebf6fff67b29243d5614f7fe1549944e47dd5706cf7619d1379e04d9bd3fced54a2d95fad00608fc25eebe28393650b3ba6281365114fd6bc5c225dc5a1b08
|
7
|
+
data.tar.gz: 9bd2367ed850cea192c4e06cdd9f774af84b4d51fe066de1a760e597fecea3bc166f03931d6200b624daf443089ada93c76950270be6e358a27953397a6954fd
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ $ bundle add 'markdown-rails'
|
|
26
26
|
Then from the root of your Rails project, run:
|
27
27
|
|
28
28
|
```sh
|
29
|
-
$ bin/rails g
|
29
|
+
$ bin/rails g markdown_rails:install
|
30
30
|
```
|
31
31
|
|
32
32
|
This adds a `config/initializers/markdown.rb` file where you can register template handler for your Markdown renders that are located in `./app/markdown/*.rb`.
|
@@ -44,7 +44,7 @@ gem "markdown-rails", "~> 2.0.0"
|
|
44
44
|
Then from the root of your Rails project, run:
|
45
45
|
|
46
46
|
```sh
|
47
|
-
$ bin/rails g
|
47
|
+
$ bin/rails g markdown_rails:install
|
48
48
|
```
|
49
49
|
|
50
50
|
If you have an existing file in `config/initializers/markdown.rb` you'll need to move those settings over. Note that 1.x used `RDiscount` as the default renderer, which was replaced by `Redcarpet` in 2.x.
|
@@ -58,11 +58,11 @@ Applications commonly need various markdown variants within one application. For
|
|
58
58
|
# Restart the server to see changes made to this file.
|
59
59
|
|
60
60
|
# Setup markdown stacks to work with different template handler in Rails.
|
61
|
-
|
61
|
+
MarkdownRails.handle :md do
|
62
62
|
ApplicationMarkdown.new
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
MarkdownRails.handle :crazymd do
|
66
66
|
MyCrazyMarkdown.new
|
67
67
|
end
|
68
68
|
```
|
@@ -71,11 +71,11 @@ end
|
|
71
71
|
|
72
72
|
Only enable Erb in Markdown if you trust the source of the file. Do not enable it for markdown provided by users or they will be able to execute arbitrary Ruby code.
|
73
73
|
|
74
|
-
To enable Erb, you can tell Rails to render all view files ending with `.markerb` using the `
|
74
|
+
To enable Erb, you can tell Rails to render all view files ending with `.markerb` using the `MarkdownRails::Handler::Erb` handler.
|
75
75
|
|
76
76
|
```ruby
|
77
77
|
# ./config/initializers/markdown.rb
|
78
|
-
|
78
|
+
MarkdownRails.handle :markerb, with: MarkdownRails::Handler::Erb do
|
79
79
|
ApplicationMarkdown.new
|
80
80
|
end
|
81
81
|
```
|
@@ -87,11 +87,11 @@ You *could* change `:markerb` to `:md`, but I don't recommend it for all Markdow
|
|
87
87
|
# Restart the server to see changes made to this file.
|
88
88
|
|
89
89
|
# Setup markdown stacks to work with different template handler in Rails.
|
90
|
-
|
90
|
+
MarkdownRails.handle :md do
|
91
91
|
ApplicationMarkdown.new
|
92
92
|
end
|
93
93
|
|
94
|
-
|
94
|
+
MarkdownRails.handle :markerb, with: MarkdownRails::Handler::Erb do
|
95
95
|
ApplicationMarkdown.new
|
96
96
|
end
|
97
97
|
```
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# You should read the docs at https://github.com/vmg/redcarpet and probably
|
2
2
|
# delete a bunch of stuff below if you don't need it.
|
3
3
|
|
4
|
-
class ApplicationMarkdown <
|
4
|
+
class ApplicationMarkdown < MarkdownRails::Renderer::Rails
|
5
5
|
# Reformats your boring punctation like " and " into “ and ” so you can look
|
6
6
|
# and feel smarter. Read the docs at https://github.com/vmg/redcarpet#also-now-our-pants-are-much-smarter
|
7
7
|
include Redcarpet::Render::SmartyPants
|
8
8
|
|
9
9
|
# If you need access to ActionController::Base.helpers, you can delegate by uncommenting
|
10
|
-
# and adding to the list below. Several are already included for you in the `
|
10
|
+
# and adding to the list below. Several are already included for you in the `MarkdownRails::Renderer::Rails`,
|
11
11
|
# but you can add more here.
|
12
12
|
#
|
13
13
|
# To see a list of methods available run `bin/rails runner "puts ActionController::Base.helpers.public_methods.sort"`
|
data/lib/generators/{markdown → markdown_rails}/install/templates/config/initializers/markdown.rb
RENAMED
@@ -1,13 +1,13 @@
|
|
1
1
|
# Restart the server to see changes made to this file.
|
2
2
|
|
3
3
|
# Setup markdown stacks to work with different template handler in Rails.
|
4
|
-
|
4
|
+
MarkdownRails.handle :md, :markdown do
|
5
5
|
ApplicationMarkdown.new
|
6
6
|
end
|
7
7
|
|
8
8
|
# Don't use Erb for untrusted markdown content created by users; otherwise they
|
9
9
|
# can execute arbitrary code on your server. This should only be used for input you
|
10
10
|
# trust, like content files from your code repo.
|
11
|
-
|
11
|
+
MarkdownRails.handle :markerb, with: MarkdownRails::Handler::Erb do
|
12
12
|
ApplicationMarkdown.new
|
13
13
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module MarkdownRails
|
2
|
+
module Handler
|
3
|
+
class Erb < Markdown
|
4
|
+
def call(template, source = template.source)
|
5
|
+
compiled_source = compile_erb template, source
|
6
|
+
# TODO: This won't properly handle initializer blocks. Somehow
|
7
|
+
# I need to pass a reference to the block that's passed in.
|
8
|
+
"#{markdown.class.name}.new.renderer.render(begin;#{compiled_source};end).html_safe"
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def compile_erb(template, source)
|
14
|
+
erb.call(template, source)
|
15
|
+
end
|
16
|
+
|
17
|
+
def erb
|
18
|
+
ActionView::Template.registered_template_handler(:erb)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module MarkdownRails
|
2
|
+
module Handler
|
3
|
+
# We cannot use MarkdownRails because it conflicts with RDiscount's Markdown class
|
4
|
+
class Markdown
|
5
|
+
def initialize(&block)
|
6
|
+
@markdown = block
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(template, source = template.source)
|
10
|
+
renderer.render(source).inspect + '.html_safe'
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.handle(*extensions, &block)
|
14
|
+
Array(extensions).each do |extension|
|
15
|
+
handler = new &block
|
16
|
+
ActionView::Template.register_template_handler extension, handler
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def markdown
|
23
|
+
@cache = nil unless cache_enabled?
|
24
|
+
@cache ||= @markdown.call
|
25
|
+
end
|
26
|
+
|
27
|
+
def renderer
|
28
|
+
@renderer = nil unless cache_enabled?
|
29
|
+
@renderer ||= markdown.renderer
|
30
|
+
end
|
31
|
+
|
32
|
+
def cache_enabled?
|
33
|
+
::Rails.configuration.cache_classes
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module MarkdownRails
|
2
|
+
module Renderer
|
3
|
+
class Base < Redcarpet::Render::HTML
|
4
|
+
def enable
|
5
|
+
# This is a very restrictive Markdown renderer that errs on the side of safety.
|
6
|
+
# For more details read the docs at https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderer-for-lunch
|
7
|
+
[
|
8
|
+
:filter_html,
|
9
|
+
:no_images,
|
10
|
+
:no_links,
|
11
|
+
:no_styles,
|
12
|
+
:safe_links_only
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
def renderer
|
17
|
+
::Redcarpet::Markdown.new(self.class, **features)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def features
|
22
|
+
Hash[Array(enable).map{ |feature| [ feature, true ] }]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module MarkdownRails
|
2
|
+
module Renderer
|
3
|
+
class Rails < Base
|
4
|
+
include ::Rails.application.routes.url_helpers
|
5
|
+
|
6
|
+
delegate \
|
7
|
+
:asset_digest_path,
|
8
|
+
:asset_path,
|
9
|
+
:asset_url,
|
10
|
+
:audio_path,
|
11
|
+
:audio_tag,
|
12
|
+
:audio_url,
|
13
|
+
:font_path,
|
14
|
+
:font_url,
|
15
|
+
:image_path,
|
16
|
+
:image_tag,
|
17
|
+
:image_url,
|
18
|
+
:video_path,
|
19
|
+
:video_tag,
|
20
|
+
:video_url,
|
21
|
+
:tag,
|
22
|
+
:content_tag,
|
23
|
+
:render,
|
24
|
+
:request,
|
25
|
+
:turbo_frame_tag,
|
26
|
+
:controller,
|
27
|
+
:raw,
|
28
|
+
to: :helpers
|
29
|
+
|
30
|
+
def image(link, title, alt)
|
31
|
+
image_tag link, title: title, alt: alt
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
def helpers
|
36
|
+
::ActionController::Base.helpers
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/markdown-rails.rb
CHANGED
@@ -1 +1,18 @@
|
|
1
|
-
require "markdown/
|
1
|
+
require "markdown-rails/version"
|
2
|
+
require "markdown-rails/engine"
|
3
|
+
|
4
|
+
module MarkdownRails
|
5
|
+
def self.handle(*extensions, with: Handler::Markdown, &block)
|
6
|
+
with.handle *extensions, &block
|
7
|
+
end
|
8
|
+
|
9
|
+
module Handler
|
10
|
+
autoload :Markdown, "markdown-rails/handler/markdown"
|
11
|
+
autoload :Erb, "markdown-rails/handler/erb"
|
12
|
+
end
|
13
|
+
|
14
|
+
module Renderer
|
15
|
+
autoload :Base, "markdown-rails/renderer/base"
|
16
|
+
autoload :Rails, "markdown-rails/renderer/rails"
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markdown-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.alpha6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Gessler
|
@@ -50,19 +50,18 @@ files:
|
|
50
50
|
- README.md
|
51
51
|
- Rakefile
|
52
52
|
- app/assets/config/markdown_rails_manifest.js
|
53
|
-
- lib/generators/
|
54
|
-
- lib/generators/
|
55
|
-
- lib/generators/
|
56
|
-
- lib/generators/
|
53
|
+
- lib/generators/markdown_rails/install/USAGE
|
54
|
+
- lib/generators/markdown_rails/install/install_generator.rb
|
55
|
+
- lib/generators/markdown_rails/install/templates/app/markdown/application_markdown.rb
|
56
|
+
- lib/generators/markdown_rails/install/templates/config/initializers/markdown.rb
|
57
57
|
- lib/markdown-rails.rb
|
58
|
-
- lib/markdown/
|
59
|
-
- lib/markdown
|
60
|
-
- lib/markdown
|
61
|
-
- lib/markdown
|
62
|
-
- lib/markdown
|
63
|
-
- lib/markdown
|
64
|
-
- lib/markdown
|
65
|
-
- lib/markdown/rails/version.rb
|
58
|
+
- lib/markdown-rails/engine.rb
|
59
|
+
- lib/markdown-rails/handler/erb.rb
|
60
|
+
- lib/markdown-rails/handler/markdown.rb
|
61
|
+
- lib/markdown-rails/railtie.rb
|
62
|
+
- lib/markdown-rails/renderer/base.rb
|
63
|
+
- lib/markdown-rails/renderer/rails.rb
|
64
|
+
- lib/markdown-rails/version.rb
|
66
65
|
- lib/tasks/markdown/rails_tasks.rake
|
67
66
|
homepage: https://github.com/sitepress/markdown-rails
|
68
67
|
licenses:
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Markdown
|
2
|
-
module Rails
|
3
|
-
module Handler
|
4
|
-
class Erb < Markdown
|
5
|
-
def call(template, source = template.source)
|
6
|
-
compiled_source = compile_erb template, source
|
7
|
-
# TODO: This won't properly handle initializer blocks. Somehow
|
8
|
-
# I need to pass a reference to the block that's passed in.
|
9
|
-
"#{markdown.class.name}.new.renderer.render(begin;#{compiled_source};end).html_safe"
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def compile_erb(template, source)
|
15
|
-
erb.call(template, source)
|
16
|
-
end
|
17
|
-
|
18
|
-
def erb
|
19
|
-
ActionView::Template.registered_template_handler(:erb)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Markdown
|
2
|
-
module Rails
|
3
|
-
module Handler
|
4
|
-
# We cannot use Markdown::Rails because it conflicts with RDiscount's Markdown class
|
5
|
-
class Markdown
|
6
|
-
def initialize(&block)
|
7
|
-
@markdown = block
|
8
|
-
end
|
9
|
-
|
10
|
-
def call(template, source = template.source)
|
11
|
-
renderer.render(source).inspect + '.html_safe'
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.handle(*extensions, &block)
|
15
|
-
Array(extensions).each do |extension|
|
16
|
-
handler = new &block
|
17
|
-
ActionView::Template.register_template_handler extension, handler
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def markdown
|
24
|
-
@cache = nil unless cache_enabled?
|
25
|
-
@cache ||= @markdown.call
|
26
|
-
end
|
27
|
-
|
28
|
-
def renderer
|
29
|
-
@renderer = nil unless cache_enabled?
|
30
|
-
@renderer ||= markdown.renderer
|
31
|
-
end
|
32
|
-
|
33
|
-
def cache_enabled?
|
34
|
-
::Rails.configuration.cache_classes
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Markdown
|
2
|
-
module Rails
|
3
|
-
module Renderer
|
4
|
-
class Base < Redcarpet::Render::HTML
|
5
|
-
def enable
|
6
|
-
# This is a very restrictive Markdown renderer that errs on the side of safety.
|
7
|
-
# For more details read the docs at https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderer-for-lunch
|
8
|
-
[
|
9
|
-
:filter_html,
|
10
|
-
:no_images,
|
11
|
-
:no_links,
|
12
|
-
:no_styles,
|
13
|
-
:safe_links_only
|
14
|
-
]
|
15
|
-
end
|
16
|
-
|
17
|
-
def renderer
|
18
|
-
::Redcarpet::Markdown.new(self.class, **features)
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
def features
|
23
|
-
Hash[Array(enable).map{ |feature| [ feature, true ] }]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module Markdown
|
2
|
-
module Rails
|
3
|
-
module Renderer
|
4
|
-
class Rails < Base
|
5
|
-
include ::Rails.application.routes.url_helpers
|
6
|
-
|
7
|
-
delegate \
|
8
|
-
:asset_digest_path,
|
9
|
-
:asset_path,
|
10
|
-
:asset_url,
|
11
|
-
:audio_path,
|
12
|
-
:audio_tag,
|
13
|
-
:audio_url,
|
14
|
-
:font_path,
|
15
|
-
:font_url,
|
16
|
-
:image_path,
|
17
|
-
:image_tag,
|
18
|
-
:image_url,
|
19
|
-
:video_path,
|
20
|
-
:video_tag,
|
21
|
-
:video_url,
|
22
|
-
:tag,
|
23
|
-
:content_tag,
|
24
|
-
:render,
|
25
|
-
:request,
|
26
|
-
:turbo_frame_tag,
|
27
|
-
:controller,
|
28
|
-
:raw,
|
29
|
-
to: :helpers
|
30
|
-
|
31
|
-
def image(link, title, alt)
|
32
|
-
image_tag link, title: title, alt: alt
|
33
|
-
end
|
34
|
-
|
35
|
-
protected
|
36
|
-
def helpers
|
37
|
-
::ActionController::Base.helpers
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/lib/markdown/rails.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require "markdown/rails/version"
|
2
|
-
require "markdown/rails/engine"
|
3
|
-
|
4
|
-
module Markdown
|
5
|
-
module Rails
|
6
|
-
def self.handle(*extensions, with: Handler::Markdown, &block)
|
7
|
-
with.handle *extensions, &block
|
8
|
-
end
|
9
|
-
|
10
|
-
module Handler
|
11
|
-
autoload :Markdown, "markdown/rails/handler/markdown"
|
12
|
-
autoload :Erb, "markdown/rails/handler/erb"
|
13
|
-
end
|
14
|
-
|
15
|
-
module Renderer
|
16
|
-
autoload :Base, "markdown/rails/renderer/base"
|
17
|
-
autoload :Rails, "markdown/rails/renderer/rails"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|