marksmith 0.1.2 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5018de3478a97ddcec156c4245851720d0ea86d36a2002ab82ba9a145f6739cc
4
- data.tar.gz: 7fb9f7f2a8f702abad17476695f14bf65669af942609c2dffe1531bb71137f30
3
+ metadata.gz: bd1c156bdd01e593e1ed5a364b646b028e736a7e0d67763110cce1e08ccb4d08
4
+ data.tar.gz: 12cdfb76d754cd011892b76790784cc122f5500213ab5f18318e353fdd531013
5
5
  SHA512:
6
- metadata.gz: 813d6e4f66ac1a41c20afc5d1d6815d8695163badf4cb45ddbf49a1da394eb3c9436677610a61bf00bbf67e961abab9a6e5b89b1ccf61f203d82650d36f97292
7
- data.tar.gz: 10b74b2a3af7f5ee6ecea2d76d54efe3d91d9784c4f3bd38ba807a828f36a79ae722deaab0285c8b9027660b452380f35df2b84af945971b85ed7199a4bd3a91
6
+ metadata.gz: c5908c41dc5a0b241a3db237ad8c6bf08e8868cb57517ff621bafb47564fd328ab7cb24b225c638b252d24e0c44852ea285af5aa95709b0fc0ab9e12aaf4ffe1
7
+ data.tar.gz: 5437ee09dccfd514e25d2fcd4874acb7cf126fe5ae26d4839ae6061daedcbdeabdb259a6dba550fdfa87b9d44d3a3f769046d17a50539a2d545390ac958ce57b
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Marksmith
2
2
 
3
+ [![CI](https://github.com/avo-hq/marksmith/actions/workflows/ci.yml/badge.svg)](https://github.com/avo-hq/marksmith/actions/workflows/ci.yml)
4
+
3
5
  Marksmith is a GitHub-style markdown editor for Rails apps.
4
6
 
5
- It supports Active Storage attachments and comes with a built-in mardown preview renderer.
7
+ It supports Active Storage attachments and comes with a built-in markdown preview renderer.
6
8
 
7
9
  ![Marksmith logo](./marksmith.png)
8
10
 
@@ -152,8 +154,8 @@ end
152
154
 
153
155
  ## Built-in preview renderer
154
156
 
155
- The renderer is powered by [`Redcarpet`](https://github.com/vmg/redcarpet).
156
- It supports basic styles for headings, `strong`, `italic` and others.
157
+ 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.
158
+ It supports basic styles like headings, `strong`, `italic` and others.
157
159
 
158
160
  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.
159
161
 
@@ -170,6 +172,35 @@ In your `show.html.erb` view or the place where you want to render the compiled
170
172
  > sanitize(body, tags: %w(table th tr td span) + ActionView::Helpers::SanitizeHelper.sanitizer_vendor.safe_list_sanitizer.allowed_tags.to_a)
171
173
  > ```
172
174
 
175
+ ## Customize the renderer
176
+
177
+ Marksmith comes with a default renderer that uses `Commonmarker` by default but it can be changed to `Redcarpet` in the configuration.
178
+
179
+ ```ruby
180
+ # config/initializers/marksmith.rb
181
+ Marksmith.configure do |config|
182
+ config.parser = "redcarpet"
183
+ end
184
+ ```
185
+
186
+ ### Add your own renderer
187
+
188
+ You can completely customize the renderer by overriding the `Marksmith::Renderer` model.
189
+
190
+ ```ruby
191
+ # app/models/marksmith/renderer.rb
192
+ module Marksmith
193
+ class Renderer
194
+ def initialize(body:)
195
+ @body = body
196
+ end
197
+
198
+ def render
199
+ # Your custom renderer logic here
200
+ end
201
+ end
202
+ end
203
+ ```
173
204
 
174
205
  ## Active Storage
175
206
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Marksmith 0.1.2
2
+ Marksmith 0.2.0
3
3
  */
4
4
  var ListContinuationController = (function () {
5
5
  'use strict';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Marksmith 0.1.2
2
+ Marksmith 0.2.0
3
3
  */
4
4
  var ListContinuationController = (function (stimulus) {
5
5
  'use strict';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Marksmith 0.1.2
2
+ Marksmith 0.2.0
3
3
  */
4
4
  var MarksmithController = (function () {
5
5
  'use strict';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Marksmith 0.1.2
2
+ Marksmith 0.2.0
3
3
  */
4
4
  var MarksmithController = (function (stimulus) {
5
5
  'use strict';
@@ -829,8 +829,8 @@
829
829
  .ms\:cursor-pointer {
830
830
  cursor: pointer;
831
831
  }
832
- .ms\:resize-y {
833
- resize: vertical;
832
+ .ms\:resize-none {
833
+ resize: none;
834
834
  }
835
835
  .ms\:flex-col {
836
836
  flex-direction: column;
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
-
3
- class Marksmith::MarkdownField::EditComponent < Avo::Fields::EditComponent
4
- def unique_id
5
- [@field.type, @resource&.singular_route_key, @field.id].compact.join("_")
2
+ if defined?(Avo)
3
+ class Marksmith::MarkdownField::EditComponent < Avo::Fields::EditComponent
4
+ def unique_id
5
+ [@field.type, @resource&.singular_route_key, @field.id].compact.join("_")
6
+ end
6
7
  end
7
8
  end
@@ -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.renderer.render(@field.value) } %>
2
+ <%= render partial: "marksmith/shared/rendered_body", locals: { body: Marksmith::Renderer.new(body: @field.value).render } %>
3
3
  <% end %>
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
-
3
- class Marksmith::MarkdownField::ShowComponent < Avo::Fields::ShowComponent
2
+ if defined?(Avo)
3
+ class Marksmith::MarkdownField::ShowComponent < Avo::Fields::ShowComponent
4
+ end
4
5
  end
@@ -1,7 +1,7 @@
1
1
  module Marksmith
2
2
  class MarkdownPreviewsController < ApplicationController
3
3
  def create
4
- @body = Marksmith::Renderer.new.renderer.render(params[:body])
4
+ @body = Marksmith::Renderer.new(body: params[:body]).render
5
5
  end
6
6
  end
7
7
  end
@@ -1,8 +1,24 @@
1
- require "redcarpet"
2
-
3
1
  module Marksmith
4
2
  class Renderer
5
- def renderer
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
@@ -84,7 +84,7 @@
84
84
  <%= content_tag :div, class: "ms:flex ms:flex-1 ms:flex-col ms:size-full", data: { marksmith_target: "fieldContainer" } do %>
85
85
  <%= text_area_tag field_name, value,
86
86
  id: name,
87
- class: class_names("ms:flex ms:flex-1 ms:rounded ms:border-none ms:resize-y ms:focus:outline-none ms:font-mono ms:focus:ring-0 ms:leading-normal ms:p-2 ms:text-sm", classes),
87
+ class: class_names("ms:flex ms:flex-1 ms:rounded ms:border-none ms:resize-none ms:focus:outline-none ms:font-mono ms:focus:ring-0 ms:leading-normal ms:p-2 ms:text-sm", classes),
88
88
  rows: rows,
89
89
  data: {
90
90
  action: "drop->marksmith#dropUpload paste->marksmith#pasteUpload",
@@ -4,6 +4,7 @@ module Marksmith
4
4
 
5
5
  config_accessor(:automatically_mount_engine) { true }
6
6
  config_accessor(:mount_path) { "/marksmith" }
7
+ config_accessor(:parser) { "commonmarker" }
7
8
  end
8
9
 
9
10
  def self.configuration
@@ -53,6 +53,11 @@ module Marksmith
53
53
  Avo.asset_manager.register_stimulus_controller "marksmith", "MarksmithController"
54
54
  Avo.asset_manager.register_stimulus_controller "list-continuation", "ListContinuationController"
55
55
  end
56
+ else
57
+ # Ignore the markdown_field components if Avo is not defined
58
+ app.autoloaders.main.ignore(
59
+ root.join("app", "components", "marksmith", "markdown_field"),
60
+ )
56
61
  end
57
62
  end
58
63
  end
@@ -1,7 +1,7 @@
1
1
  module Marksmith
2
2
  module Helper
3
3
  def marksmithed(body)
4
- Marksmith::Renderer.new.renderer.render(body)
4
+ Marksmith::Renderer.new(body:).render
5
5
  end
6
6
 
7
7
  def marksmith_tag(name, **kwargs, &block)
@@ -1,3 +1,3 @@
1
1
  module Marksmith
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
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.2
4
+ version: 0.2.0
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-03 00:00:00.000000000 Z
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
@@ -84,9 +70,6 @@ files:
84
70
  - app/frontend/entrypoints/javascript/controllers/index.js
85
71
  - app/frontend/entrypoints/javascript/controllers/list_continuation_controller.js
86
72
  - app/frontend/entrypoints/javascript/controllers/marksmith_controller.js
87
- - app/helpers/marksmith/application_helper.rb
88
- - app/jobs/marksmith/application_job.rb
89
- - app/mailers/marksmith/application_mailer.rb
90
73
  - app/models/marksmith/application_record.rb
91
74
  - app/models/marksmith/renderer.rb
92
75
  - app/views/layouts/marksmith/application.html.erb
@@ -127,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
110
  - !ruby/object:Gem::Version
128
111
  version: '0'
129
112
  requirements: []
130
- rubygems_version: 3.5.22
113
+ rubygems_version: 3.5.9
131
114
  signing_key:
132
115
  specification_version: 4
133
116
  summary: Marksmith is a GitHub-style markdown editor for Ruby on Rails applications.
@@ -1,4 +0,0 @@
1
- module Marksmith
2
- module ApplicationHelper
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module Marksmith
2
- class ApplicationJob < ActiveJob::Base
3
- end
4
- end
@@ -1,6 +0,0 @@
1
- module Marksmith
2
- class ApplicationMailer < ActionMailer::Base
3
- default from: "from@example.com"
4
- layout "mailer"
5
- end
6
- end