prosemirror_to_html 0.3.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 258fc1681186bbb3be3b85c5e2924233f9792ce35dacc0eacbdde9224f756d93
4
- data.tar.gz: 1b68a3cbf52aa3c0712d707ad589d291c760dc715baad0e26556c462de7bdf9a
3
+ metadata.gz: 1ca8ddaa7d71d39eb954baaa2c5e512625a4bcb604bbbfbccdeff806cd7720d7
4
+ data.tar.gz: e6322b6bba5bf370b7e7efa471ead3034d7c0661c4989b2b208f413ce37ddb9a
5
5
  SHA512:
6
- metadata.gz: 6018cc198040f13e4f9fefbb147fb4c226bfa08bf7c473c625e5a85e57caa092ca60bbf35cc0932a253fbf0c1807a6204efea6723e171f2312050971cc388274
7
- data.tar.gz: cbb61fbeec67cdce929c5f9c3f06b137e3f9ab9e617f94acd22ff0dfe320ce4f93eff3021111dde8ee681b730193c6058f363bad3d467fcc1a9426988a35c3d3
6
+ metadata.gz: f7e9088612cf95311c521aca3322cf64cf998f09e38d07de2abc1dc51c0506d2c484d9b5bc8c89d79ec45ee213cd1c02e8b23be55e039c70c0db0dbe96e5501f
7
+ data.tar.gz: b83a368520eb3cc22fa4d042d9ec7304410e26282c299dabef2d547f793ed4a78531cb88693429dcc1e0f656536c300d6495d08601b095c777707d36cb188589
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## [0.4.1] - 2026-10-24
2
+
3
+ ### Deprecated
4
+
5
+ - This gem is deprecated in favor of [prosemirror](https://github.com/etaminstudio/prosemirror), from the same maintainers: see the [migration guide](https://github.com/etaminstudio/prosemirror/blob/main/MIGRATING.md). Installing it shows a message pointing there.
6
+
7
+ ## [0.4.0] - 2026-08-12
8
+
9
+ ### Security
10
+
11
+ - Sanitize all rendered output with Loofah, stripping event-handler attributes, `javascript:` URLs, and other unsafe HTML that value escaping alone did not neutralize (attribute-name XSS)
12
+ - Clamp the heading `level` to a valid range (1-6) so a document-supplied value cannot steer the tag name (e.g. injecting a `<script>` element)
13
+
1
14
  ## [0.3.1] - 2026-02-23
2
15
 
3
16
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,15 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prosemirror_to_html (0.3.1)
4
+ prosemirror_to_html (0.4.0)
5
+ loofah
5
6
  nokogiri
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
11
+ crass (1.0.7)
10
12
  diff-lcs (1.6.2)
13
+ loofah (2.25.2)
14
+ crass (~> 1.0.2)
15
+ nokogiri (>= 1.12.0)
11
16
  mini_portile2 (2.8.9)
12
- nokogiri (1.19.1)
17
+ nokogiri (1.19.4)
13
18
  mini_portile2 (~> 2.8.2)
14
19
  racc (~> 1.4)
15
20
  racc (1.8.1)
@@ -27,7 +32,7 @@ GEM
27
32
  diff-lcs (>= 1.2.0, < 2.0)
28
33
  rspec-support (~> 3.13.0)
29
34
  rspec-support (3.13.7)
30
- yard (0.9.38)
35
+ yard (0.9.44)
31
36
 
32
37
  PLATFORMS
33
38
  ruby
data/README.md CHANGED
@@ -1,43 +1,18 @@
1
1
  # ProsemirrorToHtml
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/prosemirror_to_html`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ > [!WARNING]
4
+ > **This gem is deprecated.** Use [`prosemirror`](https://github.com/etaminstudio/prosemirror) instead, from the same maintainers. It builds the HTML with Phlex, which escapes text and attribute values as it writes them, types attributes and only allows safe URL schemes, instead of building strings and cleaning them up afterwards. It also imports HTML and Markdown, and exports Markdown and text. See the [migration guide](https://github.com/etaminstudio/prosemirror/blob/main/MIGRATING.md).
5
+ >
6
+ > This gem won't get new features.
4
7
 
5
- TODO: Delete this and the text above, and describe your gem
8
+ Takes ProseMirror compatible JSON and outputs HTML.
6
9
 
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
+ ## Usage
10
11
 
11
12
  ```ruby
12
- gem 'prosemirror_to_html'
13
+ ProsemirrorToHtml::Renderer.new.render(json)
13
14
  ```
14
15
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install prosemirror_to_html
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/prosemirror_to_html. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
-
37
16
  ## License
38
17
 
39
18
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
-
41
- ## Code of Conduct
42
-
43
- Everyone interacting in the ProsemirrorToHtml project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/prosemirror_to_html/blob/master/CODE_OF_CONDUCT.md).
@@ -6,7 +6,7 @@ module ProsemirrorToHtml
6
6
  def tag
7
7
  [
8
8
  {
9
- tag: "h#{@node[:attrs][:level]}",
9
+ tag: "h#{level}",
10
10
  attrs: tag_attrs
11
11
  }
12
12
  ]
@@ -14,6 +14,12 @@ module ProsemirrorToHtml
14
14
 
15
15
  private
16
16
 
17
+ # Coerce and clamp the level to a valid heading (1-6) so a
18
+ # document-supplied value cannot steer the tag name.
19
+ def level
20
+ @node[:attrs][:level].to_i.clamp(1, 6)
21
+ end
22
+
17
23
  def tag_attrs
18
24
  attrs_hash = @node[:attrs].to_h
19
25
  attrs_hash.slice(*attrs_hash.keys - %i[level])
@@ -1,3 +1,3 @@
1
1
  module ProsemirrorToHtml
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -25,6 +25,7 @@ require "prosemirror_to_html/nodes/table_header"
25
25
  require "prosemirror_to_html/nodes/table_row"
26
26
  require 'nokogiri'
27
27
  require 'json'
28
+ require "loofah"
28
29
 
29
30
  module ProsemirrorToHtml
30
31
  class Error < StandardError; end
@@ -94,7 +95,7 @@ module ProsemirrorToHtml
94
95
  html << render_node(node, prev_node, next_node)
95
96
  end
96
97
 
97
- html
98
+ sanitize(html)
98
99
  end
99
100
 
100
101
  def add_node(node)
@@ -143,6 +144,23 @@ module ProsemirrorToHtml
143
144
 
144
145
  private
145
146
 
147
+ # Serialize without libxml2's block-element auto-indentation (no FORMAT
148
+ # flag), so sanitizing does not reformat the renderer's compact output.
149
+ SANITIZE_SAVE_OPTIONS = Nokogiri::XML::Node::SaveOptions::AS_HTML |
150
+ Nokogiri::XML::Node::SaveOptions::NO_DECLARATION |
151
+ Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS
152
+
153
+ # Scrub the rendered HTML against Loofah's allowlist, stripping unsafe
154
+ # elements and attributes (event handlers, javascript: URLs, unknown tags)
155
+ # while keeping their text content. Mirrors Loofah::Helpers.sanitize but
156
+ # serializes compactly (see SANITIZE_SAVE_OPTIONS).
157
+ def sanitize(html)
158
+ fragment = Loofah.fragment(html)
159
+ fragment.scrub!(:strip)
160
+ fragment.xpath("./form").each(&:remove)
161
+ fragment.to_html(save_with: SANITIZE_SAVE_OPTIONS)
162
+ end
163
+
146
164
  def render_node(node, prev_node, next_node)
147
165
  html = ''
148
166
  render_klass = nil
@@ -9,10 +9,11 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Hans Lemuet", "Brian Kimball"]
10
10
  spec.email = ["hans@etamin.studio", "bvkimball@gmail.com"]
11
11
 
12
- spec.summary = %q{Takes ProseMirror compatible JSON and outputs HTML.}
13
- spec.description = %q{Takes ProseMirror compatible JSON and outputs HTML.}
12
+ spec.summary = %q{Deprecated: use the prosemirror gem. Takes ProseMirror compatible JSON and outputs HTML.}
13
+ spec.description = %q{Deprecated in favor of the prosemirror gem. Takes ProseMirror compatible JSON and outputs HTML.}
14
14
  spec.homepage = "https://github.com/etaminstudio/prosemirror_to_html"
15
15
  spec.license = "MIT"
16
+ spec.post_install_message = "prosemirror_to_html is deprecated: use the prosemirror gem instead. Migration guide: https://github.com/etaminstudio/prosemirror/blob/main/MIGRATING.md"
16
17
 
17
18
 
18
19
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
@@ -42,5 +43,6 @@ Gem::Specification.new do |spec|
42
43
  spec.add_development_dependency "rspec", "~> 3.0"
43
44
  spec.add_development_dependency "yard"
44
45
  spec.add_dependency "nokogiri"
46
+ spec.add_dependency "loofah"
45
47
 
46
48
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prosemirror_to_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hans Lemuet
8
8
  - Brian Kimball
9
+ autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 1980-01-02 00:00:00.000000000 Z
12
+ date: 2026-10-24 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -80,7 +81,22 @@ dependencies:
80
81
  - - ">="
81
82
  - !ruby/object:Gem::Version
82
83
  version: '0'
83
- description: Takes ProseMirror compatible JSON and outputs HTML.
84
+ - !ruby/object:Gem::Dependency
85
+ name: loofah
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: Deprecated in favor of the prosemirror gem. Takes ProseMirror compatible
99
+ JSON and outputs HTML.
84
100
  email:
85
101
  - hans@etamin.studio
86
102
  - bvkimball@gmail.com
@@ -134,6 +150,8 @@ homepage: https://github.com/etaminstudio/prosemirror_to_html
134
150
  licenses:
135
151
  - MIT
136
152
  metadata: {}
153
+ post_install_message: 'prosemirror_to_html is deprecated: use the prosemirror gem
154
+ instead. Migration guide: https://github.com/etaminstudio/prosemirror/blob/main/MIGRATING.md'
137
155
  rdoc_options: []
138
156
  require_paths:
139
157
  - lib
@@ -148,7 +166,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
166
  - !ruby/object:Gem::Version
149
167
  version: '0'
150
168
  requirements: []
151
- rubygems_version: 4.0.3
169
+ rubygems_version: 3.5.22
170
+ signing_key:
152
171
  specification_version: 4
153
- summary: Takes ProseMirror compatible JSON and outputs HTML.
172
+ summary: 'Deprecated: use the prosemirror gem. Takes ProseMirror compatible JSON and
173
+ outputs HTML.'
154
174
  test_files: []