Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want to be able to autolink short domains #186

Closed
rhiroe opened this issue Jan 20, 2022 · 2 comments · Fixed by #189
Closed

Want to be able to autolink short domains #186

rhiroe opened this issue Jan 20, 2022 · 2 comments · Fixed by #189

Comments

@rhiroe
Copy link
Contributor

rhiroe commented Jan 20, 2022

AutoHtml::Link.new.call('http://localhost:3000')
#=> "http://localhost:3000"

Want to autolink localhost, etc.
If this is not possible, it is inconvenient when checking in the development environment and testing.
Do you have the means in place to make this happen?

Currently, I am using AutoHtml::Link#call with a monkey patch in my product.

module AutoHtml
  class Link
    def call(text)
      Rinku.auto_link(text, :all, attributes, nil, Rinku::AUTOLINK_SHORT_DOMAINS)
    end
  end
end

AutoHtml::Link.new.call('http://localhost:3000')
=> "<a href=\"http://localhost:3000\">http://localhost:3000</a>"

How about incorporating this into a gem or making it available?

@dejan
Copy link
Owner

dejan commented Feb 27, 2022

Please open the PR to make the suggested change in the gem: https://github.com/dejan/auto_html/blob/master/lib/auto_html/link.rb#L16

Thanks!

@rhiroe
Copy link
Contributor Author

rhiroe commented Feb 28, 2022

@dejan
Thank you. I will make a pull request.
I will be proposing the following changes.

module AutoHtml
  class Link
    def initialize(target: nil, rel: nil, short_domains: false)
      @target = target
      @rel = rel
      @short_domains = short_domains
    end

    def call(text)
      Rinku.auto_link(text, :all, attributes, nil, flags)
    end

    private

    def flags
      @short_domains ? Rinku::AUTOLINK_SHORT_DOMAINS : 0
    end

  end
end

AutoHtml::Link.new(short_domains: true).call('http://localhost:3000')

If it is not in line with this gem philosophy, please point it out.

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 a pull request may close this issue.

2 participants