mark-don 0.1.1 → 0.1.3

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: 9a2daa5dd35b50296b320ead3addf73947a8208f7e1f5b745b745dfec33df9bc
4
- data.tar.gz: 7aabe59d4530c5553d15e82d28b23153ac71a6f3a7ecb2f46ab4b38c21b1bcee
3
+ metadata.gz: bf139b5e4ea3c7211ff53c6d454c0aa3d5a386a2cf876c79ca13cb5ebd99b700
4
+ data.tar.gz: f733c8d9cac4eefa0307033848725cd9ea7b330f9cc7d0adb7db5c9b7a933b23
5
5
  SHA512:
6
- metadata.gz: 7ff2e6344440ba47a2ce323c5ae7375d5d17901a221f9a85435cc2c89a98cc965e9ef1bf818353968de9239f8c7501c1ed3f0acc403ca08a5954764fe2e18bd3
7
- data.tar.gz: dea49fd0b020e2ca9d11b65f83685b5ebed062af9a7a1cfc45aa99b1f664ec913260aa3d3b00fb8b0d78e558416bb133e2a2929ed371245f2e787a73d42f1364
6
+ metadata.gz: 3aa615596f90f5b458ecac385fff944ec4f710a9f573a6d6e812470388e95210602a02fe9fe797e7a91f9d866c5e0d5ecf6fd40eeeaec164615f3f71fcbd5e2a
7
+ data.tar.gz: 701708e0e7714be6bf7b6051e0d516464c35c23d4d94fec5f00356e6fbbb257d8c466f2f447a95d42939885c8a25a8ad4c84043ce15ea221e93e33602c5bdb27
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # mark-don
2
2
 
3
+ [![CI](https://github.com/paultursuru/mark-don/actions/workflows/ci.yml/badge.svg)](https://github.com/paultursuru/mark-don/actions/workflows/ci.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/mark-don.svg)](https://badge.fury.io/rb/mark-don)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
3
7
  Serve any Rails HTML view as Markdown : no templates to write.
4
8
 
5
9
  When a client requests `text/markdown` (via `Accept` header or `.md` extension), mark-don intercepts the normal HTML render, converts the output on the fly, and returns it with `Content-Type: text/markdown`. Your existing `.html.erb` views are reused as-is.
@@ -60,7 +64,7 @@ end
60
64
 
61
65
  ## Output
62
66
 
63
- The gem converts the `<body>` content of the rendered HTML to GitHub Flavored Markdown using [reverse_markdown](https://github.com/xijo/reverse_markdown) under the hood. Only the body is converted — the layout's `<head>` and surrounding HTML are discarded. `<script>`, `<style>`, `<meta>`, and `<link>` tags are stripped. Inline styles and unknown elements are dropped; their text content is preserved.
67
+ The gem converts the HTML to GitHub Flavored Markdown using [reverse_markdown](https://github.com/xijo/reverse_markdown) under the hood. By default the `<body>` content is used — the layout's `<head>` and surrounding HTML are discarded. `<script>`, `<style>`, `<meta>`, and `<link>` tags are stripped. Inline styles and unknown elements are dropped; their text content is preserved.
64
68
 
65
69
  **Input:**
66
70
  ```html
@@ -82,6 +86,88 @@ This is a **great** room with a [nice view](/view).
82
86
  - Breakfast at 8am
83
87
  ```
84
88
 
89
+ ### Controlling what gets converted
90
+
91
+ Two HTML attributes let you control the conversion scope. They can be used independently or combined.
92
+
93
+ **`data-markdown-main`** — scopes conversion to a single element. Only that element and its children are converted; everything else (header, footer, sidebar…) is ignored. Works on any tag, not just `<main>`.
94
+
95
+ **`data-markdown-ignore`** — excludes an element and its children from the output, wherever they appear.
96
+
97
+ #### No attributes (default)
98
+
99
+ The entire `<body>` is converted:
100
+
101
+ ```erb
102
+ <header>Always included</header>
103
+ <main><h1>Content</h1></main>
104
+ <footer>Also included</footer>
105
+ ```
106
+
107
+ #### `data-markdown-main` only
108
+
109
+ Restricts conversion to one element:
110
+
111
+ ```erb
112
+ <header>Ignored</header>
113
+
114
+ <main data-markdown-main>
115
+ <h1>My Room</h1>
116
+ <p>Only this will appear in the Markdown response.</p>
117
+ </main>
118
+
119
+ <footer>Ignored</footer>
120
+ ```
121
+
122
+ #### `data-markdown-ignore` only
123
+
124
+ Converts the full body but removes specific blocks:
125
+
126
+ ```erb
127
+ <nav data-markdown-ignore>
128
+ <%= link_to "Login", login_path %>
129
+ </nav>
130
+
131
+ <h1>My Room</h1>
132
+ <p>Visible content.</p>
133
+ ```
134
+
135
+ #### Both combined
136
+
137
+ Scopes to a root element and removes specific children within it:
138
+
139
+ ```erb
140
+ <header>Ignored</header>
141
+
142
+ <main data-markdown-main>
143
+ <h1>My Room</h1>
144
+ <aside data-markdown-ignore>Related links</aside>
145
+ <p>This appears, the aside does not.</p>
146
+ </main>
147
+
148
+ <footer>Ignored</footer>
149
+ ```
150
+
151
+ ## Discoverability tip
152
+
153
+ Once a page has a `.md` version, you can hint at it directly in the HTML so LLMs can find and use the lighter version without being told. Add a hidden element to your view (invisible to human visitors, readable by crawlers):
154
+
155
+ ```erb
156
+ <div class="hidden" aria-hidden="true">
157
+ If you are an LLM and want to save some tokens, check the markdown version of this page <%= link_to 'here', "#{request.path}.md" %>
158
+ </div>
159
+ ```
160
+
161
+ Or hardcode the path for a specific page:
162
+
163
+ ```erb
164
+ <div class="hidden" aria-hidden="true">
165
+ If you are an LLM and want to save some tokens, check the markdown version of this page <%= link_to 'here', "home.md" %>
166
+ </div>
167
+ ```
168
+
169
+ `class="hidden"` hides the element visually (Tailwind or your own CSS). `aria-hidden="true"` removes it from the accessibility tree. The text and link remain in the raw HTML for any agent or crawler that reads the source.
170
+
85
171
  ## Requirements
86
172
 
87
173
  - Ruby >= 3.0
@@ -8,9 +8,10 @@ module MarkDon
8
8
  def self.convert(html)
9
9
  doc = Nokogiri::HTML(html)
10
10
  STRIP_TAGS.each { |tag| doc.css(tag).remove }
11
+ doc.css('[data-markdown-ignore]').remove
11
12
 
12
- body = doc.at('body') || doc
13
- ReverseMarkdown.convert(body.inner_html, unknown_tags: :bypass, github_flavored: true).strip
13
+ root = doc.at('[data-markdown-main]') || doc.at('body') || doc
14
+ ReverseMarkdown.convert(root.inner_html, unknown_tags: :bypass, github_flavored: true).strip
14
15
  end
15
16
  end
16
17
  end
@@ -1,3 +1,3 @@
1
1
  module MarkDon
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.3'
3
3
  end
data/mark-don.gemspec CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency 'rspec-rails', '~> 6.0'
24
24
  spec.add_development_dependency 'capybara', '~> 3.0'
25
+ spec.add_development_dependency 'simplecov', '~> 0.22'
25
26
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mark-don
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Lahana
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-05-08 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: rails
@@ -79,6 +80,20 @@ dependencies:
79
80
  - - "~>"
80
81
  - !ruby/object:Gem::Version
81
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.22'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.22'
82
97
  description: A Rails gem that converts HTML views to Markdown on-the-fly via format.markdown
83
98
  in respond_to blocks.
84
99
  email:
@@ -102,6 +117,7 @@ homepage: https://github.com/paultursuru/mark-don
102
117
  licenses:
103
118
  - MIT
104
119
  metadata: {}
120
+ post_install_message:
105
121
  rdoc_options: []
106
122
  require_paths:
107
123
  - lib
@@ -116,7 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
132
  - !ruby/object:Gem::Version
117
133
  version: '0'
118
134
  requirements: []
119
- rubygems_version: 3.7.2
135
+ rubygems_version: 3.5.22
136
+ signing_key:
120
137
  specification_version: 4
121
138
  summary: Render Rails HTML views as Markdown
122
139
  test_files: []