Skip to content

feat: add wrap_links option to render links as plain "text: href"#40

Merged
mscrivo merged 4 commits into
soundasleep:masterfrom
gusrub:gusrub/optional-link-wrapping
Jul 8, 2026
Merged

feat: add wrap_links option to render links as plain "text: href"#40
mscrivo merged 4 commits into
soundasleep:masterfrom
gusrub:gusrub/optional-link-wrapping

Conversation

@gusrub

@gusrub gusrub commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Hi!

I'm not sure if you accept patches but I came across a specific need to have the links not wrapped and did some changes to the code.

Basically the gem turns links like this:

<a href="https://example.com">This is a link!</a>

Into this:

[This is a link!](https://example.com)

We need to have a fully text-only version of certain html that we add for descriptions for calendar ICS integration and the markdown-like syntax kinda seems broken/off into said descriptions.

I added an optional wrap_links argument that defaults to true so the existing implementation does not break for anyone but if you pass false to the initializer or the convert method then you would get something like this instead:

This is a link!: https://example.com

Which suits or needs and probably others.

Also updated the SPEC's to include a test case for this.

gusrub and others added 4 commits February 24, 2026 12:58
Review fixes on top of the original contribution:

- simplify the redundant `!output.empty?` check (already guaranteed by
  the surrounding if-branch)
- drop the write-only `attr_writer :wrap_links`; the value is consumed
  once during convert and `doc` only has a reader
- revert the version bump — versioning happens at release time, and a
  new option is a minor bump, not a patch
- add a CHANGELOG entry documenting the option and its scope (only
  `<a href>` links; images and named anchors keep their brackets)
- move the spec out of the top of html2text_spec.rb's scope into its
  own spec/wrap_links_spec.rb, and cover the default format, the
  initializer path, linked images, empty link text, and href-equals-
  text/mailto cases alongside the original example

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mscrivo mscrivo changed the title Optional link wrapping feat: add wrap_links option to render links as plain "text: href" Jul 8, 2026
@mscrivo mscrivo merged commit a860299 into soundasleep:master Jul 8, 2026
6 checks passed
@mscrivo

mscrivo commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

sorry @gusrub I just saw this today. Made some minor changes and committed, I'll release this as part of 0.5.0

@gusrub

gusrub commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

sorry @gusrub I just saw this today. Made some minor changes and committed, I'll release this as part of 0.5.0

@mscrivo No worries! Glad it'll be merged. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants