marksmith 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +24 -22
- data/app/assets/javascripts/list_continuation_controller-full.esm.js +1 -1
- data/app/assets/javascripts/list_continuation_controller-no-stimulus.esm.js +1 -1
- data/app/assets/javascripts/marksmith_controller-full.esm.js +2 -2
- data/app/assets/javascripts/marksmith_controller-no-stimulus.esm.js +2 -2
- data/app/components/marksmith/markdown_field/show_component.html.erb +1 -1
- data/app/controllers/marksmith/markdown_previews_controller.rb +1 -1
- data/app/frontend/entrypoints/javascript/controllers/marksmith_controller.js +1 -1
- data/app/models/marksmith/renderer.rb +20 -4
- data/lib/marksmith/configuration.rb +1 -0
- data/lib/marksmith/helper.rb +1 -1
- data/lib/marksmith/version.rb +1 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56e19c3a798fe08b0a94496122a474c12f86290e1bb8a5b4fff861d4aa6364aa
|
4
|
+
data.tar.gz: f93776bd5fd3d8a18ce3d7d037902488afd38708cd3decc85f1d3524fde77536
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc4374a4aec89463df75d437a8c5a78d417c6551bfbff1136a060220c98847e0acdff03ede9e2d93e1ca8c2296ee815be0518203fe4cbf6a710f373e28ec7f64
|
7
|
+
data.tar.gz: 822a0b2071008c2a898330283ad0a3518ca4f7493e6a2465a08863c5b741263ca4d183f31e28a226ead98b2d4f3c05e5e5d2815d825274a45410abafafea964b
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ Temporary live demo here, under the description field: [https://main.avodemo.com
|
|
28
28
|
Have Bundler add it by running this command:
|
29
29
|
|
30
30
|
```bash
|
31
|
-
bundle add marksmith
|
31
|
+
bundle add marksmith commonmarker
|
32
32
|
```
|
33
33
|
|
34
34
|
Or manually install it.
|
@@ -38,6 +38,8 @@ Add this line to your application's Gemfile:
|
|
38
38
|
```ruby
|
39
39
|
# Gemfile
|
40
40
|
gem "marksmith"
|
41
|
+
# Add a markdown parser
|
42
|
+
gem "commonmarker"
|
41
43
|
```
|
42
44
|
|
43
45
|
#### 2. Install the NPM package to import the StimulusJS controller.
|
@@ -154,8 +156,8 @@ end
|
|
154
156
|
|
155
157
|
## Built-in preview renderer
|
156
158
|
|
157
|
-
The renderer is powered by [`Redcarpet`](https://github.com/vmg/redcarpet).
|
158
|
-
It supports basic styles
|
159
|
+
The renderer is powered by [`Commonmarker`](https://github.com/gjtorikian/commonmarker) by default but it can be changed to [`Redcarpet`](https://github.com/vmg/redcarpet) in the configuration or add your own logic by customizing the `Marksmith::Renderer` model.
|
160
|
+
It supports basic styles like headings, `strong`, `italic` and others.
|
159
161
|
|
160
162
|
In your `show.html.erb` view or the place where you want to render the compiled markup use the `marksmithed` helper and it will run the content through the renderer.
|
161
163
|
|
@@ -172,31 +174,31 @@ In your `show.html.erb` view or the place where you want to render the compiled
|
|
172
174
|
> sanitize(body, tags: %w(table th tr td span) + ActionView::Helpers::SanitizeHelper.sanitizer_vendor.safe_list_sanitizer.allowed_tags.to_a)
|
173
175
|
> ```
|
174
176
|
|
175
|
-
|
177
|
+
## Customize the renderer
|
176
178
|
|
177
|
-
|
179
|
+
Marksmith comes with a default renderer that uses `Commonmarker` by default but it can be changed to `Redcarpet` in the configuration.
|
178
180
|
|
179
181
|
```ruby
|
180
|
-
#
|
181
|
-
|
182
|
+
# config/initializers/marksmith.rb
|
183
|
+
Marksmith.configure do |config|
|
184
|
+
config.parser = "redcarpet"
|
185
|
+
end
|
186
|
+
```
|
187
|
+
|
188
|
+
### Add your own renderer
|
182
189
|
|
190
|
+
You can completely customize the renderer by overriding the `Marksmith::Renderer` model.
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
# app/models/marksmith/renderer.rb
|
183
194
|
module Marksmith
|
184
195
|
class Renderer
|
185
|
-
def
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
space_after_headers: true,
|
192
|
-
hard_wrap: true,
|
193
|
-
autolink: true,
|
194
|
-
strikethrough: true,
|
195
|
-
underline: true,
|
196
|
-
highlight: true,
|
197
|
-
quote: true,
|
198
|
-
with_toc_data: true
|
199
|
-
)
|
196
|
+
def initialize(body:)
|
197
|
+
@body = body
|
198
|
+
end
|
199
|
+
|
200
|
+
def render
|
201
|
+
# Your custom renderer logic here
|
200
202
|
end
|
201
203
|
end
|
202
204
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
Marksmith 0.1
|
2
|
+
Marksmith 0.2.1
|
3
3
|
*/
|
4
4
|
var MarksmithController = (function () {
|
5
5
|
'use strict';
|
@@ -2949,7 +2949,7 @@ var MarksmithController = (function () {
|
|
2949
2949
|
}
|
2950
2950
|
|
2951
2951
|
#pathFromBlob(blob) {
|
2952
|
-
return `/rails/active_storage/blobs/redirect/${blob.signed_id}/${blob.filename}`
|
2952
|
+
return `/rails/active_storage/blobs/redirect/${blob.signed_id}/${encodeURIComponent(blob.filename)}`
|
2953
2953
|
}
|
2954
2954
|
|
2955
2955
|
#markdownLinkFromUrl(filename, url, contentType) {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
Marksmith 0.1
|
2
|
+
Marksmith 0.2.1
|
3
3
|
*/
|
4
4
|
var MarksmithController = (function (stimulus) {
|
5
5
|
'use strict';
|
@@ -2459,7 +2459,7 @@ var MarksmithController = (function (stimulus) {
|
|
2459
2459
|
}
|
2460
2460
|
|
2461
2461
|
#pathFromBlob(blob) {
|
2462
|
-
return `/rails/active_storage/blobs/redirect/${blob.signed_id}/${blob.filename}`
|
2462
|
+
return `/rails/active_storage/blobs/redirect/${blob.signed_id}/${encodeURIComponent(blob.filename)}`
|
2463
2463
|
}
|
2464
2464
|
|
2465
2465
|
#markdownLinkFromUrl(filename, url, contentType) {
|
@@ -1,3 +1,3 @@
|
|
1
1
|
<%= field_wrapper **field_wrapper_args, full_width: true do %>
|
2
|
-
<%= render partial: "marksmith/shared/rendered_body", locals: { body: Marksmith::Renderer.new
|
2
|
+
<%= render partial: "marksmith/shared/rendered_body", locals: { body: Marksmith::Renderer.new(body: @field.value).render } %>
|
3
3
|
<% end %>
|
@@ -139,7 +139,7 @@ export default class extends Controller {
|
|
139
139
|
}
|
140
140
|
|
141
141
|
#pathFromBlob(blob) {
|
142
|
-
return `/rails/active_storage/blobs/redirect/${blob.signed_id}/${blob.filename}`
|
142
|
+
return `/rails/active_storage/blobs/redirect/${blob.signed_id}/${encodeURIComponent(blob.filename)}`
|
143
143
|
}
|
144
144
|
|
145
145
|
#markdownLinkFromUrl(filename, url, contentType) {
|
@@ -1,8 +1,24 @@
|
|
1
|
-
require "redcarpet"
|
2
|
-
|
3
1
|
module Marksmith
|
4
2
|
class Renderer
|
5
|
-
def
|
3
|
+
def initialize(body:)
|
4
|
+
@body = body
|
5
|
+
end
|
6
|
+
|
7
|
+
def render
|
8
|
+
if Marksmith.configuration.parser == "commonmarker"
|
9
|
+
render_commonmarker
|
10
|
+
else
|
11
|
+
render_redcarpet
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def render_commonmarker
|
16
|
+
# commonmarker expects an utf-8 encoded string
|
17
|
+
body = @body.to_s.dup.force_encoding('utf-8')
|
18
|
+
Commonmarker.to_html(body)
|
19
|
+
end
|
20
|
+
|
21
|
+
def render_redcarpet
|
6
22
|
::Redcarpet::Markdown.new(
|
7
23
|
::Redcarpet::Render::HTML,
|
8
24
|
tables: true,
|
@@ -16,7 +32,7 @@ module Marksmith
|
|
16
32
|
highlight: true,
|
17
33
|
quote: true,
|
18
34
|
with_toc_data: true
|
19
|
-
)
|
35
|
+
).render(@body)
|
20
36
|
end
|
21
37
|
end
|
22
38
|
end
|
data/lib/marksmith/helper.rb
CHANGED
data/lib/marksmith/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marksmith
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Marin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: redcarpet
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
description: Marksmith is a GitHub-style markdown editor for Ruby on Rails applications.
|
42
28
|
email:
|
43
29
|
- adrian@adrianthedev.com
|