Skip to content

Commit

Permalink
Update subject mention syntax prefix
Browse files Browse the repository at this point in the history
- Adds a prefix 'S' character for subject mentions
- closes #11
  • Loading branch information
aweiksnar committed Aug 20, 2015
1 parent bb787f3 commit ad6611f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/lib/default-transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export default function(input, {project, baseURI}) {

// subjects in a specific project : @owner-slug/project-slug^subject_id
// \b[\w-]+\b is hyphen boundary for slugs
.replace(/@(\b[\w-]+\b)\/(\b[\w-]+\b)\^([0-9]+)/g, `<a href="${baseURI}/projects/$1/$2/talk/subjects/$3">$1/$2 - Subject $3</a>`)
.replace(/@(\b[\w-]+\b)\/(\b[\w-]+\b)\^S([0-9]+)/g, `<a href="${baseURI}/projects/$1/$2/talk/subjects/$3">$1/$2 - Subject $3</a>`)

.replace(/\^([0-9]+)/g, function(_, subjectID) {
.replace(/\^S([0-9]+)/g, function(_, subjectID) {
if (owner && name) {
return `<a href="${baseURI}/projects/${owner}/${name}/talk/subjects/${subjectID}">${owner}/${name} - Subject ${subjectID}</a>`;
}
Expand Down
10 changes: 5 additions & 5 deletions test/lib/default-transformer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ describe('default-transformer', () => {
expect(htmlTagLink).to.equal(`<p><a href="#/talk/search?query=good">#good</a> \n https://www.zooniverse.org/#/talk/17/1403?page=1&comment=3063</p>`);
});

it('replaces ^subject mentions with subject links', () =>{
it('replaces ^S<subject_id> mentions with subject links', () =>{
project = { slug: "test/project" };
var subjectLink = replaceSymbols('^123456', {project, baseURI});;
var subjectLink = replaceSymbols('^S123456', {project, baseURI});;
expect(subjectLink).to.equal('<a href="#/projects/test/project/talk/subjects/123456">test/project - Subject 123456</a>');
});

it('does not format subject Ids when not in a routed context', () =>{
var subjectLink = replaceSymbols('^123456', {project, baseURI});
var subjectLink = replaceSymbols('^S123456', {project, baseURI});
expect(subjectLink).to.equal("123456");
});

it('replaces @ownerslug/project-slug^subject_id mentions with links', () => {
var projectSubjectLink = replaceSymbols('@owner/project-d^123456', {project, baseURI});
it('replaces @ownerslug/project-slug^S<subject_id> mentions with links', () => {
var projectSubjectLink = replaceSymbols('@owner/project-d^S123456', {project, baseURI});

expect(projectSubjectLink).to.equal('<a href="#/projects/owner/project-d/talk/subjects/123456">owner/project-d - Subject 123456</a>');
});
Expand Down

0 comments on commit ad6611f

Please sign in to comment.