Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.1.2] - 2026-05-08

### Added
- `data-markdown-ignore` boolean attribute to exclude any HTML element (and its children) from Markdown output

## [0.1.1] - 2026-04-30

### Fixed
Expand All @@ -21,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for `Accept: text/markdown` header and `.md` URL suffix
- Rails 6.1+ and Ruby 3.0+ compatibility

[Unreleased]: https://github.com/paultursuru/mark-don/compare/v0.1.1...HEAD
[Unreleased]: https://github.com/paultursuru/mark-don/compare/v0.1.2...HEAD
[0.1.2]: https://github.com/paultursuru/mark-don/compare/v0.1.1...v0.1.2
[0.1.1]: https://github.com/paultursuru/mark-don/compare/v0.1.0...v0.1.1
[0.1.0]: https://github.com/paultursuru/mark-don/releases/tag/v0.1.0
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
mark-don (0.1.1)
mark-don (0.1.2)
nokogiri (>= 1.13)
rails (>= 6.1)
reverse_markdown (~> 2.1)
Expand Down Expand Up @@ -290,7 +290,7 @@ CHECKSUMS
loofah (2.25.1) sha256=d436c73dbd0c1147b16c4a41db097942d217303e1f7728704b37e4df9f6d2e04
mail (2.9.0) sha256=6fa6673ecd71c60c2d996260f9ee3dd387d4673b8169b502134659ece6d34941
marcel (1.1.0) sha256=fdcfcfa33cc52e93c4308d40e4090a5d4ea279e160a7f6af988260fa970e0bee
mark-don (0.1.1)
mark-don (0.1.2)
matrix (0.4.3) sha256=a0d5ab7ddcc1973ff690ab361b67f359acbb16958d1dc072b8b956a286564c5b
mini_mime (1.1.5) sha256=8681b7e2e4215f2a159f9400b5816d85e9d8c6c6b491e96a12797e798f8bccef
minitest (6.0.6) sha256=153ea36d1d987a62942382b61075745042a2b3123b1cd48f4c3675af9cc7d6f1
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ This is a **great** room with a [nice view](/view).
- Breakfast at 8am
```

### Excluding elements

Add `data-markdown-ignore` to any HTML element to exclude it and its children from the Markdown output:

```erb
<nav data-markdown-ignore>
<%= link_to "Login", login_path %>
<%= link_to "Sign up", signup_path %>
</nav>

<h1>My Room</h1>
<p>Visible content.</p>
```

The `<nav>` block is removed before conversion — only the visible content remains in the Markdown response.

## Discoverability tip

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):
Expand Down
1 change: 1 addition & 0 deletions lib/mark_don/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Converter
def self.convert(html)
doc = Nokogiri::HTML(html)
STRIP_TAGS.each { |tag| doc.css(tag).remove }
doc.css('[data-markdown-ignore]').remove

body = doc.at('body') || doc
ReverseMarkdown.convert(body.inner_html, unknown_tags: :bypass, github_flavored: true).strip
Expand Down
2 changes: 1 addition & 1 deletion lib/mark_don/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MarkDon
VERSION = '0.1.1'
VERSION = '0.1.2'
end
14 changes: 14 additions & 0 deletions spec/mark_don/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@
expect(result).not_to include('<script>')
end

it 'ignores elements with data-markdown-ignore attribute' do
html = '<p>Visible</p><nav data-markdown-ignore><a href="/login">Login</a></nav>'
result = described_class.convert(html)
expect(result).to eq('Visible')
expect(result).not_to include('Login')
end

it 'ignores nested content inside data-markdown-ignore' do
html = '<h1>Title</h1><div data-markdown-ignore><p>Hidden</p><ul><li>Also hidden</li></ul></div>'
result = described_class.convert(html)
expect(result).to eq('# Title')
expect(result).not_to include('Hidden')
end

it 'strips style tags and their content' do
html = '<style>body { color: red; }</style><p>Hello</p>'
result = described_class.convert(html)
Expand Down
Loading