mark_it_zero 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +10 -0
- data/lib/mark_it_zero.rb +1 -0
- data/lib/mark_it_zero/converts_markdown.rb +1 -38
- data/lib/mark_it_zero/markdown.rb +46 -0
- data/lib/mark_it_zero/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99943d71e88e2ca914ba0c060a2b57205b214859
|
4
|
+
data.tar.gz: c0dbc1d4d3eaa210f77f6a38a7309ab1c5bbc9cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab301074f156d54e1ff2535bed0fa4c18e6e132eaf1c8d821cf5ae90db9bf0d96aa1a7cf779418e7ba5dbc97c3b6d8202e5e537a07b2c7f7155ec61f267cbe87
|
7
|
+
data.tar.gz: 6f81879b6c07990cd8eac9ce2da524047b4ffa37f1e068854bdb5cd4e6a6c7badb5cc98c2560efd75a24dbc169cec722349b0811388746b7bc10e86c94785568
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -104,6 +104,16 @@ We use Pygments.rb to add classes for syntax highlighting to code blocks. Most
|
|
104
104
|
of what I'm doing is contained within [this
|
105
105
|
Railscast](http://railscasts.com/episodes/207-syntax-highlighting-revised).
|
106
106
|
|
107
|
+
### Without Active Record
|
108
|
+
|
109
|
+
You can use Mark It Zero! without ActiveRecord. Just use the `Markdown` class'
|
110
|
+
`to_html` method.
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
MarkItZero::Markdown.to_html("# Heading 1\n\n> A really cool quote ...")
|
114
|
+
# => "<h1 id=\"heading-1\">Heading 1</h1>\n\n<blockquote>\n<p>A really cool quote ...</p>\n</blockquote>\n"
|
115
|
+
```
|
116
|
+
|
107
117
|
Special Thanks!
|
108
118
|
----------
|
109
119
|
|
data/lib/mark_it_zero.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'redcarpet'
|
2
|
-
require 'pygments.rb'
|
3
|
-
|
4
1
|
class << ActiveRecord::Base
|
5
2
|
|
6
3
|
def converts_markdown(markdown = :markdown, html = :html)
|
@@ -10,44 +7,10 @@ class << ActiveRecord::Base
|
|
10
7
|
after_save :"convert_#{markdown}_to_#{html}"
|
11
8
|
|
12
9
|
define_method "convert_#{markdown}_to_#{html}" do
|
13
|
-
renderer = Redcarpet::Markdown.new(
|
14
|
-
HTMLwithPygments.new(:hard_wrap => false, :with_toc_data => true),
|
15
|
-
{
|
16
|
-
:autolink => true,
|
17
|
-
:fenced_code_blocks => true,
|
18
|
-
:highlight => true,
|
19
|
-
:space_after_headers => true,
|
20
|
-
:strikethrough => true,
|
21
|
-
:tables => true,
|
22
|
-
:underline => true,
|
23
|
-
}
|
24
|
-
)
|
25
|
-
|
26
10
|
update_columns(
|
27
|
-
html.to_sym =>
|
11
|
+
html.to_sym => MarkItZero::Markdown.to_html(self.send(markdown))
|
28
12
|
)
|
29
13
|
end
|
30
|
-
|
31
|
-
define_method "clean_#{markdown}" do
|
32
|
-
md = self.send(markdown)
|
33
|
-
return "" if md.blank?
|
34
|
-
md.gsub(
|
35
|
-
/(?:http[s]?:\/\/)?(?:www\.)?(?:youtu\.be)\/(?:watch\?v=)?(.+)/,
|
36
|
-
'<iframe width="420" height="345" src="http://www.youtube.com/embed/\1" frameborder="0" allowfullscreen></iframe>'
|
37
|
-
).gsub(
|
38
|
-
/[”“]/,
|
39
|
-
'"'
|
40
|
-
).gsub(
|
41
|
-
/\[file\:(.*)\]/,
|
42
|
-
'<p class="file"><code>\1</code></p>'
|
43
|
-
)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class HTMLwithPygments < Redcarpet::Render::HTML
|
48
|
-
def block_code(code, language)
|
49
|
-
Pygments.highlight(code, lexer: language)
|
50
|
-
end
|
51
14
|
end
|
52
15
|
|
53
16
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
require 'pygments.rb'
|
3
|
+
|
4
|
+
module MarkItZero
|
5
|
+
|
6
|
+
class HTMLwithPygments < Redcarpet::Render::HTML
|
7
|
+
def block_code(code, language)
|
8
|
+
Pygments.highlight(code, lexer: language)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Markdown
|
13
|
+
|
14
|
+
@@renderer = Redcarpet::Markdown.new(
|
15
|
+
HTMLwithPygments.new(:hard_wrap => false, :with_toc_data => true),
|
16
|
+
{
|
17
|
+
:autolink => true,
|
18
|
+
:fenced_code_blocks => true,
|
19
|
+
:highlight => true,
|
20
|
+
:space_after_headers => true,
|
21
|
+
:strikethrough => true,
|
22
|
+
:tables => true,
|
23
|
+
:underline => true,
|
24
|
+
}
|
25
|
+
)
|
26
|
+
|
27
|
+
def self.cleanse(text)
|
28
|
+
return "" if text.blank?
|
29
|
+
text.gsub(
|
30
|
+
/(?:http[s]?:\/\/)?(?:www\.)?(?:youtu\.be)\/(?:watch\?v=)?(.+)/,
|
31
|
+
'<iframe width="420" height="345" src="http://www.youtube.com/embed/\1" frameborder="0" allowfullscreen></iframe>'
|
32
|
+
).gsub(
|
33
|
+
/[”“]/,
|
34
|
+
'"'
|
35
|
+
).gsub(
|
36
|
+
/\[file\:(.*)\]/,
|
37
|
+
'<p class="file"><code>\1</code></p>'
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.to_html(text)
|
42
|
+
@@renderer.render(cleanse(text))
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/mark_it_zero/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mark_it_zero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean C Davis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- lib/mark_it_zero.rb
|
140
140
|
- lib/mark_it_zero/converts_markdown.rb
|
141
141
|
- lib/mark_it_zero/engine.rb
|
142
|
+
- lib/mark_it_zero/markdown.rb
|
142
143
|
- lib/mark_it_zero/version.rb
|
143
144
|
- mark_it_zero.gemspec
|
144
145
|
- test/dummy/README.rdoc
|
@@ -220,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
221
|
version: '0'
|
221
222
|
requirements: []
|
222
223
|
rubyforge_project:
|
223
|
-
rubygems_version: 2.
|
224
|
+
rubygems_version: 2.4.6
|
224
225
|
signing_key:
|
225
226
|
specification_version: 4
|
226
227
|
summary: Syntax highlighted markdown editor for rails
|