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 the ability to parse a line with a link and a description #13

Merged
merged 6 commits into from
Feb 19, 2019
Merged

Add the ability to parse a line with a link and a description #13

merged 6 commits into from
Feb 19, 2019

Conversation

jletey
Copy link
Contributor

@jletey jletey commented Feb 19, 2019

Here's a rough draft ... tell me what you think

@nikitavoloboev
Copy link
Owner

I tried it with:

func TestParseLinkWithDescription(t *testing.T) {
	assert := assert.New(t)
	v := "- [Effective Go](https://golang.org/doc/effective_go.html)"
	result := ParseLinkWithDescription(v)
	assert.Equal(result["Title"], "Effective Go", "Check to see if the title is correct")
	assert.Equal(result["Link"], "https://golang.org/doc/effective_go.html", "Check to see if the link is correct")
	assert.Equal(result["Description"], "", "Check to see if the description is correct")
}

And go test failed. Can we test what happens if there is no description too?

@jletey
Copy link
Contributor Author

jletey commented Feb 19, 2019

Sure ... working on it

@nikitavoloboev
Copy link
Owner

Speaking of using this PR to solve nikitavoloboev/alfred-learn-anything#9, are you on mac or windows. And if on mac, do you have Alfred? :)

@jletey
Copy link
Contributor Author

jletey commented Feb 19, 2019

I'm on Mac ... but I don't have Alfred

@jletey
Copy link
Contributor Author

jletey commented Feb 19, 2019

Also, can you take a look at nikitavoloboev/license-up#28

@jletey
Copy link
Contributor Author

jletey commented Feb 19, 2019

When we don't have a description, the regex completely changes ... how exactly do you want to go about checking if there is a description.

Regex for link without description: (?m)^- \[([^]]+)\]\(([^)]+)\)$
Regex for link with description: (?m)^- \[([^]]+)\]\(([^)]+)\) - (.+)$

@nikitavoloboev
Copy link
Owner

It has to be all encompassing.

The use case if to parse a file like this:

https://github.com/learn-anything/books

And extract all the links (books + # Other) inside the file to some data structure.

@nikitavoloboev
Copy link
Owner

If there is no description, it should only return the title and URL (those are bound to be there).

@nikitavoloboev
Copy link
Owner

nikitavoloboev commented Feb 19, 2019

but I don't have Alfred

That's a shame. It's a pretty amazing tool. Would definitely recommend. 🚀

There's lots of workflows for it too https://github.com/learn-anything/alfred-workflows#readme

@jletey
Copy link
Contributor Author

jletey commented Feb 19, 2019

That's a shame. It's a pretty amazing tool. Would definitely recommend. 🚀

I know it's an amazing tool ... but the problem is that they charge for workflows

@nikitavoloboev
Copy link
Owner

but the problem is that they charge for workflows

Can send your PayPal, I can sponsor a license for you. 🙂

@jletey
Copy link
Contributor Author

jletey commented Feb 19, 2019

Can send your PayPal, I can sponsor a license for you. 🙂

I don't have a PayPal account ... thank you though, that's very kind of you!

@jletey
Copy link
Contributor Author

jletey commented Feb 19, 2019

Should we change the function name from ParseLinkWithDescription to just ParseLink?

@nikitavoloboev
Copy link
Owner

ParseLinkWithDescription to just ParseLink

yes

@nikitavoloboev
Copy link
Owner

from ParseLinkWithDescription to just ParseLink

And do the error handling there in case there is no description. I believe there is none currently.

@jletey
Copy link
Contributor Author

jletey commented Feb 19, 2019

And do the error handling there in case there is no description. I believe there is none currently.

There should be a test case called TestParseLinkWithoutDescription

@nikitavoloboev
Copy link
Owner

nikitavoloboev commented Feb 19, 2019

There should be a test case called TestParseLinkWithoutDescription

Or maybe just TestParseLink and inside it test a link with description and one without and check for outputs. As well as some other text like blargh to check if handles this case properly too.

@jletey
Copy link
Contributor Author

jletey commented Feb 19, 2019

Doing that now

@jletey
Copy link
Contributor Author

jletey commented Feb 19, 2019

@nikitavoloboev How does it look now?

@nikitavoloboev
Copy link
Owner

Works great. Awesome!

@nikitavoloboev nikitavoloboev merged commit d96f7fa into nikitavoloboev:master Feb 19, 2019
@jletey
Copy link
Contributor Author

jletey commented Feb 19, 2019

Great! So is it now usable for your knowledge and other projects?

@nikitavoloboev
Copy link
Owner

Will have to check. Will need few minutes/hours. 😅

@jletey
Copy link
Contributor Author

jletey commented Feb 19, 2019

Got it

@nikitavoloboev
Copy link
Owner

So is it now usable for your knowledge and other projects?

Actually for nikitavoloboev/knowledge#25 it won't work as Imgur link embeds are of different format. Will have to write code specifically for parsing image embeds.

![](https://i.imgur.com/ZVPjkzh.png)

^ Is image embed.

@jletey
Copy link
Contributor Author

jletey commented Feb 19, 2019

I see ... you can probably just copy and paste the code for ParseLink into ParseImgurLink and then change up the regex

I can try to do this if you'd like

@nikitavoloboev
Copy link
Owner

nikitavoloboev commented Feb 19, 2019

Opened #15

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

2 participants