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

Parses tags correctly #37

Merged
merged 2 commits into from
May 3, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "markdownz",
"version": "4.1.1",
"version": "4.1.2",
"description": "Markdown viewer and editor for the Zooniverse",
"main": "src/index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/default-transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export default function(input, {project, baseURI}) {

return input
// hashtags #tagname
.replace(/(?!\B.*\/+\b)\B#(\b[\w+-\/]+\b)/g, function(fullTag, tagName) {
.replace(/(?:^|\s)\#([-\w\d]{3,40})/g, function(fullTag, tagName) {
if (owner && name) {
return `[${fullTag}](${baseURI}/projects/${owner}/${name}/talk/tags/${tagName})`
return `[#${tagName}](${baseURI}/projects/${owner}/${name}/talk/tags/${tagName})`
}
else {
return `[${fullTag}](${baseURI}/talk/search?query=${tagName})`
return `[#${tagName}](${baseURI}/talk/search?query=${tagName})`
}
})

Expand Down
6 changes: 3 additions & 3 deletions test/lib/default-transformer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ describe('default-transformer', () => {
});

it('works in a sentence with multiple tags & a URL', () => {
const sentence = `#test sentenc #tag and url: http://docs.panoptes.apiary.io/#reference/user/users-collection/list-all-users`
const sentence = `#test sentence #tag and url: http://docs.panoptes.apiary.io/#reference/user/users-collection/list-all-users`

const htmlSentence = replaceSymbols(sentence, {project, baseURI})
expect(htmlSentence).to.equal(`#test sentenc #tag and url: http://docs.panoptes.apiary.io/#reference/user/users-collection/list-all-users`)
expect(htmlSentence).to.equal(`[#test](/talk/search?query=test) sentence[#tag](/talk/search?query=tag) and url: http://docs.panoptes.apiary.io/#reference/user/users-collection/list-all-users`)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know how this could've passed before, it was expecting the tags to not be parsed at all

})

it('ignores links with hashes', () => {
Expand All @@ -33,7 +33,7 @@ describe('default-transformer', () => {
})

it('allows delimiters in hashtags', () => {
['#test-tag', '#test_tag', '#test.tag'].forEach((tag) => {
['#test-tag', '#test_tag'].forEach((tag) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

test.tag isn't a valid tag.

const parsedTag = replaceSymbols(tag, {project, baseURI})
expect(parsedTag).to.equal(`[${tag}](/talk/search?query=${tag.slice(1, tag.length)})`)
})
Expand Down