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
e72f2bbd
Commit
e72f2bbd
authored
Nov 16, 2023
by
Drini Cami
Committed by
Robert Knight
Nov 21, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Feedback from code review
parent
637757fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
4 deletions
+5
-4
highlighter.ts
src/annotator/highlighter.ts
+3
-2
highlighter-test.js
src/annotator/test/highlighter-test.js
+2
-2
No files found.
src/annotator/highlighter.ts
View file @
e72f2bbd
...
@@ -237,9 +237,10 @@ export function highlightRange(
...
@@ -237,9 +237,10 @@ export function highlightRange(
textNodeSpans
=
textNodeSpans
.
filter
(
span
=>
{
textNodeSpans
=
textNodeSpans
.
filter
(
span
=>
{
const
parentElement
=
span
[
0
].
parentElement
;
const
parentElement
=
span
[
0
].
parentElement
;
return
(
return
(
// Whitespace <span>s should be highlighted since they affect layout
// Whitespace <span>s should be highlighted since they affect layout in
// some code editors
(
parentElement
?.
childNodes
.
length
===
1
&&
(
parentElement
?.
childNodes
.
length
===
1
&&
parentElement
?.
tagName
.
match
(
/^SPAN$/i
)
)
||
parentElement
?.
tagName
===
'SPAN'
)
||
// Otherwise ignore white-space only Text node spans
// Otherwise ignore white-space only Text node spans
span
.
some
(
node
=>
!
whitespace
.
test
(
node
.
data
))
span
.
some
(
node
=>
!
whitespace
.
test
(
node
.
data
))
);
);
...
...
src/annotator/test/highlighter-test.js
View file @
e72f2bbd
...
@@ -235,7 +235,7 @@ describe('annotator/highlighter', () => {
...
@@ -235,7 +235,7 @@ describe('annotator/highlighter', () => {
assert
.
equal
(
result
[
0
].
textContent
,
'one two'
);
assert
.
equal
(
result
[
0
].
textContent
,
'one two'
);
});
});
it
(
'skips
non-<span> text node spans which consist only of space
s'
,
()
=>
{
it
(
'skips
whitespace-only text node spans, except inside <span>
s'
,
()
=>
{
const
el
=
document
.
createElement
(
'div'
);
const
el
=
document
.
createElement
(
'div'
);
el
.
appendChild
(
document
.
createTextNode
(
' '
));
el
.
appendChild
(
document
.
createTextNode
(
' '
));
el
.
appendChild
(
document
.
createTextNode
(
''
));
el
.
appendChild
(
document
.
createTextNode
(
''
));
...
@@ -249,7 +249,7 @@ describe('annotator/highlighter', () => {
...
@@ -249,7 +249,7 @@ describe('annotator/highlighter', () => {
assert
.
equal
(
result
.
length
,
0
);
assert
.
equal
(
result
.
length
,
0
);
});
});
it
(
'
includes whitespace elements
if <span> parent'
,
()
=>
{
it
(
'
wraps whitespace-only text
if <span> parent'
,
()
=>
{
// Real-world examples:
// Real-world examples:
// - Codeblocks on https://h.readthedocs.io/en/latest/developing/install
// - Codeblocks on https://h.readthedocs.io/en/latest/developing/install
// - Text layer on https://archive.org/details/goodytwoshoes00newyiala
// - Text layer on https://archive.org/details/goodytwoshoes00newyiala
...
...
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