Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
af3cd696
Commit
af3cd696
authored
Jun 29, 2016
by
Alice Wyan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove no longer needed helper file
parent
3dcf1b27
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
105 deletions
+0
-105
document-title.js
h/static/scripts/filter/document-title.js
+0
-30
document-title-test.js
h/static/scripts/filter/test/document-title-test.js
+0
-75
No files found.
h/static/scripts/filter/document-title.js
deleted
100644 → 0
View file @
3dcf1b27
'use strict'
;
var
escapeHtml
=
require
(
'escape-html'
);
/**
* Return a nice displayable string representation of a document's title.
*
* @returns {String} The document's title preceded on "on " and hyperlinked
* to the document's URI. If the document has no http(s) URI then don't
* hyperlink the title. If the document has no title then return ''.
*
*/
module
.
exports
=
function
documentTitle
(
document
)
{
var
title
=
escapeHtml
(
document
.
title
||
''
);
var
uri
=
escapeHtml
(
document
.
uri
||
''
);
if
(
uri
&&
!
(
uri
.
indexOf
(
'http://'
)
===
0
||
uri
.
indexOf
(
'https://'
)
===
0
))
{
// We only link to http(s) URLs.
uri
=
null
;
}
if
(
title
&&
uri
)
{
return
(
'on “<a target="_blank" href="'
+
uri
+
'">'
+
title
+
'</a>”'
);
}
else
if
(
title
)
{
return
'on “'
+
title
+
'”'
;
}
else
{
return
''
;
}
};
h/static/scripts/filter/test/document-title-test.js
deleted
100644 → 0
View file @
3dcf1b27
'use strict'
;
var
documentTitle
=
require
(
'../document-title'
);
describe
(
'documentTitle'
,
function
()
{
it
(
'returns the title linked if the document has title and uri'
,
function
()
{
var
title
=
documentTitle
({
title
:
'title'
,
uri
:
'http://example.com/example.html'
});
assert
(
title
===
'on “<a target="_blank" '
+
'href="http://example.com/example.html">'
+
'title</a>”'
);
});
it
(
'returns the title linked if the document has an https uri'
,
function
()
{
var
title
=
documentTitle
({
title
:
'title'
,
uri
:
'https://example.com/example.html'
});
assert
(
title
===
'on “<a target="_blank" '
+
'href="https://example.com/example.html">'
+
'title</a>”'
);
});
it
(
'returns the title unlinked if doc has title but no uri'
,
function
()
{
var
title
=
documentTitle
({
title
:
'title'
,
});
assert
(
title
===
'on “title”'
);
});
it
(
'returns the title unlinked if doc has non-http uri'
,
function
()
{
var
title
=
documentTitle
({
title
:
'title'
,
uri
:
'file:///home/bob/Documents/example.pdf'
});
assert
(
title
===
'on “title”'
);
});
it
(
'returns an empty string if the document has no title'
,
function
()
{
var
title
=
documentTitle
({
uri
:
'http://example.com/example.html'
});
assert
(
title
===
''
);
});
it
(
'escapes HTML in the document title'
,
function
()
{
var
spamLink
=
'<a href="http://example.com/rubies">Buy rubies!!!</a>'
;
var
title
=
documentTitle
({
title
:
'</a>'
+
spamLink
,
uri
:
'http://example.com/example.html'
});
assert
(
title
.
indexOf
(
spamLink
)
===
-
1
);
});
it
(
'escapes HTML in the document URI'
,
function
()
{
var
spamLink
=
'<a href="http://example.com/rubies">Buy rubies!!!</a>'
;
var
title
=
documentTitle
({
uri
:
'http://</a>'
+
spamLink
,
title
:
'title'
});
assert
(
title
.
indexOf
(
spamLink
)
===
-
1
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment