emd 0.3.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +65 -22
- data/app/assets/javascripts/emd.js +12 -0
- data/app/assets/stylesheets/emd.scss +36 -0
- data/config/initializers/markdown_template_handler.rb +9 -4
- data/lib/emd/version.rb +1 -1
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1057ad153eab8a0f90c99e96bf865fe7c91c42b5dad62a85c9b0faea346182e1
|
4
|
+
data.tar.gz: 598ea55c1fda7b8b58ba6e3cd4f15925d6178b229bc7089c15384852474a9fb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 962543192bd7344fe0eed7b1321ed148f5983cf849e972c0fcc9eaf775a1b37a586fe0b5ab9a94828d90f1afe757c8eccd4a4a6114d4f9ee248dd7acdeb6b8e7
|
7
|
+
data.tar.gz: ab22746d9fa60ffd996cd07c24adadbcee89d01d254de75c394d4141327b5e81e4711c4e724ace98c5200653943f4123e1853a60663c03a70c6ee38fdf73a9c1
|
data/README.md
CHANGED
@@ -23,18 +23,18 @@ bundle
|
|
23
23
|
|
24
24
|
1. Create a `markdown.html.md` view at `app/view/home/markdown.html.md` and add the following Markdown code:
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
```markdown
|
27
|
+
## This is a sample Markdown code
|
28
|
+
- [google](http://google.com)
|
29
|
+
- [emd](https://github.com/ytbryan/emd/)
|
30
|
+
```
|
31
31
|
|
32
32
|
1. Generate a home controller using the following command `rails generate controller home`
|
33
33
|
|
34
34
|
1. Add the following line to `route.rb`:
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
```
|
36
|
+
get '/markdown', to: 'home#markdown'
|
37
|
+
```
|
38
38
|
1. And finally, visit the Markdown view at [http://localhost:3000/markdown](http://localhost:3000/markdown)
|
39
39
|
|
40
40
|
|
@@ -42,20 +42,20 @@ bundle
|
|
42
42
|
|
43
43
|
1. Create a `_component.html.md` partial at `app/view/home/_component.html.md`:
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
```markdown
|
46
|
+
### This is a component
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
- This is item 1
|
49
|
+
- This is iiem 2
|
50
|
+
- [This is a link to google] (http://google.com)
|
51
|
+
```
|
52
52
|
|
53
53
|
1. Use this partial using `<%= render "component" %>` within any view like at `home/index.html.erb`
|
54
54
|
|
55
55
|
1. Add the following line to `route.rb`:
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
```
|
57
|
+
get '/home', to: 'home#index'
|
58
|
+
```
|
59
59
|
1. And finally, visit the Rails view with Markdown partial at [http://localhost:3000/home](http://localhost:3000/home)
|
60
60
|
|
61
61
|
|
@@ -72,15 +72,56 @@ This will turn all the code block into:
|
|
72
72
|
|
73
73
|
```ruby
|
74
74
|
```ruby
|
75
|
-
|
76
|
-
|
75
|
+
class Something
|
76
|
+
end
|
77
77
|
```
|
78
78
|
```
|
79
79
|
|
80
80
|
```ruby
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
class Something
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
Also, you can enable inline code highlighting by adding `code` style to your `index.css`
|
86
|
+
|
87
|
+
```
|
88
|
+
code {
|
89
|
+
background-color: rgba(27,31,35,.1);
|
90
|
+
border-radius: 3px;
|
91
|
+
font-size: 85%;
|
92
|
+
margin: 0;
|
93
|
+
padding: .2em .4em;
|
94
|
+
}
|
95
|
+
```
|
96
|
+
|
97
|
+
### Enable number lines in your markdown's code block
|
98
|
+
|
99
|
+
To display number lines in your code block, add `emd.js` in `app/assets/javascripts/application.js`
|
100
|
+
|
101
|
+
```javascript
|
102
|
+
//= require emd
|
103
|
+
//= require_tree .
|
104
|
+
```
|
105
|
+
|
106
|
+
And add `emd.css` in `app/assets/stylesheets/application.css`
|
107
|
+
|
108
|
+
```css
|
109
|
+
*= require emd
|
110
|
+
*= require_self
|
111
|
+
```
|
112
|
+
|
113
|
+
### Changing the color of the code block
|
114
|
+
|
115
|
+
To change the color of the code block, please use the following css selector:
|
116
|
+
|
117
|
+
```css
|
118
|
+
div.code pre {
|
119
|
+
background-color: #fff;
|
120
|
+
}
|
121
|
+
```
|
122
|
+
|
123
|
+
The default color is `#eee`
|
124
|
+
|
84
125
|
|
85
126
|
### Control which extensions Redcarpet uses
|
86
127
|
|
@@ -128,12 +169,14 @@ Special thanks to [these folks](http://stackoverflow.com/questions/4163560/how-c
|
|
128
169
|
## TODO
|
129
170
|
|
130
171
|
- [x] Syntax highlighting
|
172
|
+
- [x] Number lines in code block
|
131
173
|
- [ ] Tests
|
132
174
|
- [ ] Scaffolders
|
133
175
|
- [ ] Example repo
|
134
176
|
- [ ] Add a copy button to the code block
|
135
177
|
|
136
178
|
|
179
|
+
|
137
180
|
## Benefits
|
138
181
|
|
139
182
|
EMD uses a Rails engine and a simple initializer to initiate a markdown template handler with the help of Redcarpet and syntax highlighting from Coderay.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
document.addEventListener('DOMContentLoaded', () => {
|
2
|
+
var pre = document.getElementsByTagName('pre'),
|
3
|
+
pl = pre.length;
|
4
|
+
for (var i = 0; i < pl; i++) {
|
5
|
+
pre[i].innerHTML = '<span class="line-number"></span>' + pre[i].innerHTML + '<span class="cl"></span>';
|
6
|
+
var num = pre[i].innerHTML.split(/\n/).length;
|
7
|
+
for (var j = 0; j < (num - 1); j++) {
|
8
|
+
var line_num = pre[i].getElementsByTagName('span')[0];
|
9
|
+
line_num.innerHTML += '<span>' + (j + 1) + '</span>';
|
10
|
+
}
|
11
|
+
}
|
12
|
+
})
|
@@ -0,0 +1,36 @@
|
|
1
|
+
pre {
|
2
|
+
display: block;
|
3
|
+
margin-top: 0;
|
4
|
+
margin-bottom: 1rem;
|
5
|
+
font-size: 0.7rem;
|
6
|
+
line-height: 1.4;
|
7
|
+
white-space: pre;
|
8
|
+
overflow: auto;
|
9
|
+
background-color:#eee;
|
10
|
+
border: 1px solid #ddd;
|
11
|
+
padding: .5rem;
|
12
|
+
max-height: 800px;
|
13
|
+
font-family: monospace;
|
14
|
+
code {
|
15
|
+
color: inherit;
|
16
|
+
background-color: transparent;
|
17
|
+
padding: 0;
|
18
|
+
display: block;
|
19
|
+
}
|
20
|
+
.line-number {
|
21
|
+
display: block;
|
22
|
+
float: left;
|
23
|
+
margin: 0 1em 0 -1em;
|
24
|
+
border-right: 1px solid #ddd;
|
25
|
+
text-align: right;
|
26
|
+
span {
|
27
|
+
display: block;
|
28
|
+
padding: 0 .5em 0 1em;
|
29
|
+
color: #ccc;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
.cl {
|
33
|
+
display: block;
|
34
|
+
clear: both;
|
35
|
+
}
|
36
|
+
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class CodeRayify < Redcarpet::Render::HTML
|
2
2
|
def block_code(code, language)
|
3
3
|
if !Gem.loaded_specs.has_key?('coderay') || language == nil || language == ""
|
4
|
-
%(<pre>#{code}</pre>)
|
4
|
+
%(<div class="CodeRay"><div class="code"><pre>#{code}</pre></div></div>)
|
5
5
|
else
|
6
6
|
CodeRay.scan(code, language).div
|
7
7
|
end
|
@@ -13,10 +13,15 @@ module MarkdownTemplateHandler
|
|
13
13
|
@erb ||= ActionView::Template.registered_template_handler(:erb)
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.call(template)
|
17
|
-
|
16
|
+
def self.call(template, source = nil)
|
17
|
+
|
18
|
+
compiled_source = if source
|
19
|
+
erb.call(template, source)
|
20
|
+
else
|
21
|
+
erb.call(template)
|
22
|
+
end
|
18
23
|
|
19
|
-
%(Redcarpet::Markdown.new(CodeRayify.new(:filter_html =>
|
24
|
+
%(Redcarpet::Markdown.new(CodeRayify.new(:filter_html => false,
|
20
25
|
:hard_wrap => true),
|
21
26
|
no_intra_emphasis: true,
|
22
27
|
fenced_code_blocks: true,
|
data/lib/emd/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Lim
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redcarpet
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
19
|
+
version: 3.5.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.
|
26
|
+
version: 3.5.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.1.
|
61
|
+
version: 1.1.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.1.
|
68
|
+
version: 1.1.3
|
69
69
|
description: Embedded markdown template for Ruby on Rails
|
70
70
|
email:
|
71
71
|
- ytbryan@gmail.com
|
@@ -74,6 +74,8 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- README.md
|
77
|
+
- app/assets/javascripts/emd.js
|
78
|
+
- app/assets/stylesheets/emd.scss
|
77
79
|
- app/helpers/emd_helper.rb
|
78
80
|
- config/initializers/markdown_template_handler.rb
|
79
81
|
- lib/emd.rb
|
@@ -101,8 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
103
|
- !ruby/object:Gem::Version
|
102
104
|
version: '0'
|
103
105
|
requirements: []
|
104
|
-
rubygems_version: 3.
|
105
|
-
signing_key:
|
106
|
+
rubygems_version: 3.1.2
|
107
|
+
signing_key:
|
106
108
|
specification_version: 4
|
107
109
|
summary: Markdown partial and .html.md on Rails View
|
108
110
|
test_files: []
|