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
cd1cc5c5
Unverified
Commit
cd1cc5c5
authored
Jan 08, 2020
by
Lyza Gardner
Committed by
GitHub
Jan 08, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1652 from hypothesis/is-highlight-util
Add `isHighlight` util function to `annotation-metadata`
parents
34d63c81
e6aadd79
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
1 deletion
+91
-1
annotation-fixtures.js
src/sidebar/test/annotation-fixtures.js
+1
-1
annotation-metadata.js
src/sidebar/util/annotation-metadata.js
+38
-0
annotation-metadata-test.js
src/sidebar/util/test/annotation-metadata-test.js
+52
-0
No files found.
src/sidebar/test/annotation-fixtures.js
View file @
cd1cc5c5
...
...
@@ -113,7 +113,7 @@ function oldHighlight() {
return
{
id
:
'annotation_id'
,
$highlight
:
undefined
,
target
:
[
'foo'
,
'bar'
],
target
:
[
{
source
:
'source'
,
selector
:
[]
}
],
references
:
[],
text
:
''
,
tags
:
[],
...
...
src/sidebar/util/annotation-metadata.js
View file @
cd1cc5c5
...
...
@@ -149,6 +149,43 @@ function isWaitingToAnchor(annotation) {
);
}
/**
* Is this annotation a highlight?
*
* Highlights are generally identifiable by having no text content AND no tags,
* but there is some nuance.
*
* @param {Object} annotation
* @return {boolean}
*/
function
isHighlight
(
annotation
)
{
// `$highlight` is an ephemeral attribute set by the `annotator` on new
// annotation objects (created by clicking the "highlight" button).
// It is not persisted and cannot be relied upon, but if it IS present,
// this is definitely a highlight (one which is not yet saved).
if
(
annotation
.
$highlight
)
{
return
true
;
}
if
(
isNew
(
annotation
))
{
// For new (unsaved-to-service) annotations, unless they have a truthy
// `$highlight` attribute, we don't know yet if they are a highlight.
return
false
;
}
// Note that it is possible to end up with an empty (no `text`) annotation
// that is not a highlight by adding at least one tag—thus, it is necessary
// to check for the existence of tags as well as text content.
return
(
!
isPageNote
(
annotation
)
&&
!
isReply
(
annotation
)
&&
!
annotation
.
hidden
&&
// A hidden annotation has some form of objectionable content
!
annotation
.
text
&&
!
(
annotation
.
tags
&&
annotation
.
tags
.
length
)
);
}
/** Return `true` if the given annotation is an orphan. */
function
isOrphan
(
annotation
)
{
return
hasSelector
(
annotation
)
&&
annotation
.
$orphan
;
...
...
@@ -220,6 +257,7 @@ module.exports = {
domainAndTitle
:
domainAndTitle
,
flagCount
:
flagCount
,
isAnnotation
:
isAnnotation
,
isHighlight
:
isHighlight
,
isNew
:
isNew
,
isOrphan
:
isOrphan
,
isPageNote
:
isPageNote
,
...
...
src/sidebar/util/test/annotation-metadata-test.js
View file @
cd1cc5c5
...
...
@@ -234,6 +234,58 @@ describe('annotation-metadata', function() {
});
});
describe
(
'.isHighlight'
,
()
=>
{
[
{
annotation
:
fixtures
.
newEmptyAnnotation
(),
expect
:
false
,
desc
:
'new, empty annotation'
,
},
{
annotation
:
fixtures
.
newReply
(),
expect
:
false
,
desc
:
'new, reply annotation'
,
},
{
annotation
:
fixtures
.
newAnnotation
(),
expect
:
false
,
desc
:
'new, with some text'
,
},
{
annotation
:
fixtures
.
newHighlight
(),
expect
:
true
,
desc
:
'new, marked as $highlight'
,
},
{
annotation
:
fixtures
.
oldAnnotation
(),
expect
:
false
,
desc
:
'pre-existing annotation'
,
},
{
annotation
:
fixtures
.
oldHighlight
(),
expect
:
true
,
desc
:
'pre-existing higlight'
,
},
{
annotation
:
fixtures
.
oldPageNote
(),
expect
:
false
,
desc
:
'pre-existing page note'
,
},
{
annotation
:
fixtures
.
oldReply
(),
expect
:
false
,
desc
:
'pre-existing reply'
,
},
].
forEach
(
testcase
=>
{
it
(
`returns
${
testcase
.
expect
}
for isHighlight when annotation is:
${
testcase
.
desc
}
`
,
()
=>
{
assert
.
equal
(
annotationMetadata
.
isHighlight
(
testcase
.
annotation
),
testcase
.
expect
);
});
});
});
describe
(
'.isPageNote'
,
function
()
{
it
(
'returns true for an annotation with an empty target'
,
function
()
{
assert
.
isTrue
(
...
...
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