Skip to content

Commit

Permalink
Merge pull request #37 from parrish/fix-tag-parsing
Browse files Browse the repository at this point in the history
Parses tags correctly
  • Loading branch information
brian-c committed May 3, 2016
2 parents d4619fb + 09812e4 commit 9032080
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
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`)
})

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) => {
const parsedTag = replaceSymbols(tag, {project, baseURI})
expect(parsedTag).to.equal(`[${tag}](/talk/search?query=${tag.slice(1, tag.length)})`)
})
Expand Down

0 comments on commit 9032080

Please sign in to comment.