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

Add linkify module, wraps uri as html links #19

Closed
wants to merge 5 commits into from

Conversation

ipwnponies
Copy link

Detects uri in strings and wrap them in html anchors. Returns markup safe string for display in web page.

@asottile
Copy link
Contributor

I'm not sure this fits with the rest of the utilities in yelp-uri which generally deal with plain text. We have an internal module yelp-html which I would imagine this fits into better? shrugs

@ipwnponies
Copy link
Author

I rebased this onto #20 since the same merge conflicts/fixes are needed. Not sure if this pull request needs to be edited to reflect this.

@bukzor
Copy link
Contributor

bukzor commented Sep 15, 2016

@asottile It was my idea to add this. Most of the code here is meant to help implement this function, but it's not entirely trivial add you can see. While I agree it's not the most natural fit ever, it's also not a bad fit.

I'd like to merge this.

@asottile
Copy link
Contributor

Would this not fit better in yelp-html?

@bukzor
Copy link
Contributor

bukzor commented Sep 21, 2016

re yelp-html: probably! I didn't know it existed.

It must be internal-only: https://github.com/Yelp/yelp_html
Does it currently depend on yelp-uri?

@asottile
Copy link
Contributor

No it doesn't currently, but easy to add :) It does however use yelp-markupsafe (also internal) already.

Copy link
Contributor

@bukzor bukzor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider putting this in yelp-html as asottile suggests.

path_query_fragment = uri_match.group('path_query_fragment')
line_number = ''
if path_query_fragment is not None:
_, line_number = re.match(r'^(.+?)((?::\d+)*)$', path_query_fragment).groups('')
Copy link
Contributor

@bukzor bukzor Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.groups('') is weird. I haven't seen that before.

Are you sure that return match().groups() isn't the same behavior?

I think ((?::\d+)*) would be simpler as (:[:0-9]+).

It's slightly better to make the regex object a global constant and reuse it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.groups('') is weird. I haven't seen that before.
Are you sure that return match().groups() isn't the same behavior?

This sets the default value if no matching group. The default is None, docs.

I think ((?::\d+)*) would be simpler as (:[:0-9]+).

I wanted to match multiple groups, such as line number + column (for example, file.txt:100:12). And I didn't want to capture the individual groups, just everything as a whole in a single group. I'll read the docs again though, maybe I'm not doing capturing groups correctly.

It's slightly better to make the regex object a global constant and reuse it.

Gotcha, will fix.

# Strip trailing line numbers
url = uri_match.group()[:-len(line_number)]

return url, line_number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this can be done in one or two lines rather than eleven.

@ipwnponies
Copy link
Author

Closing this PR and moving the linkify functions to yelp-html, as suggested. I've opened pull request #23 that cherry picks the general improvements we made along the way.

@ipwnponies ipwnponies closed this Sep 23, 2016
@ipwnponies ipwnponies deleted the linkify branch September 24, 2016 00:06
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.

None yet

3 participants