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
90cab72d
Commit
90cab72d
authored
Jan 04, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Jan 04, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add page number to every annotation when exported as text
parent
311a02d2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
35 deletions
+26
-35
trim-and-dedent-test.js
src/shared/test/trim-and-dedent-test.js
+3
-2
trim-and-dedent.ts
src/shared/trim-and-dedent.ts
+3
-26
annotations-exporter.ts
src/sidebar/services/annotations-exporter.ts
+7
-5
annotations-exporter-test.js
src/sidebar/services/test/annotations-exporter-test.js
+13
-2
No files found.
src/shared/test/trim-and-dedent-test.js
View file @
90cab72d
...
...
@@ -17,11 +17,13 @@ describe('trimAndDedent', () => {
Hello, Jane!
Indented line
Goodbye, John!
`
,
`Hello, Jane!
Indented line
Goodbye, John!`
,
],
[
...
...
@@ -50,8 +52,7 @@ Goodbye, John!
multiple
lines
with no indentation
`
,
with no indentation`
,
],
[
()
=>
{
...
...
src/shared/trim-and-dedent.ts
View file @
90cab72d
function
trimLeadingEmptyLines
(
str
:
string
):
string
{
return
str
.
replace
(
/^
\s
*
\n
/g
,
''
);
}
function
trimTrailingEmptyLines
(
str
:
string
):
string
{
return
str
.
replace
(
/
\n\s
*$/g
,
''
);
function
trimLeadingAndTrailingEmptyLines
(
str
:
string
):
string
{
return
str
.
replace
(
/^
\s
*
\n
|
\n\s
*$/g
,
''
);
}
/**
...
...
@@ -71,24 +67,5 @@ export function trimAndDedent(
strings
:
TemplateStringsArray
,
...
params
:
any
[]
):
string
{
if
(
strings
.
length
<
2
)
{
// Trim leading and trailing empty lines from first (and only) string
const
trimmedLines
=
[
trimLeadingEmptyLines
(
trimTrailingEmptyLines
(
strings
[
0
])),
];
return
dedent
(
trimmedLines
,
...
params
);
}
const
firstString
=
strings
[
0
];
const
lastString
=
strings
[
strings
.
length
-
1
];
const
middle
=
strings
.
slice
(
1
,
strings
.
length
-
1
);
// Trim empty leading lines from first string, and empty trailing lines from last one
const
trimmedLines
=
[
trimLeadingEmptyLines
(
firstString
),
...
middle
,
trimTrailingEmptyLines
(
lastString
),
];
return
dedent
(
trimmedLines
,
...
params
);
return
trimLeadingAndTrailingEmptyLines
(
dedent
([...
strings
],
...
params
));
}
src/sidebar/services/annotations-exporter.ts
View file @
90cab72d
...
...
@@ -3,6 +3,7 @@ import type { APIAnnotationData } from '../../types/api';
import
{
documentMetadata
,
isReply
,
pageLabel
,
quote
,
}
from
'../helpers/annotation-metadata'
;
import
{
annotationDisplayName
}
from
'../helpers/annotation-user'
;
...
...
@@ -80,16 +81,17 @@ export class AnnotationsExporter {
];
const
annotationsText
=
annotations
.
map
(
(
annotation
,
index
)
=>
trimAndDedent
`
.
map
(
(
annotation
,
index
)
=>
{
const
page
=
pageLabel
(
annotation
);
return
trimAndDedent
`
Annotation
${
index
+
1
}
:
${
annotation
.
created
}
${
annotation
.
text
}
${
extractUsername
(
annotation
)}
"
${
quote
(
annotation
)}
"
Tags:
${
annotation
.
tags
.
join
(
', '
)}
`
,
)
Tags:
${
annotation
.
tags
.
join
(
', '
)}
${
page
?
`Page:
${
page
}
`
:
''
}
`
;
})
.
join
(
'
\
n
\
n'
);
return
trimAndDedent
`
...
...
src/sidebar/services/test/annotations-exporter-test.js
View file @
90cab72d
...
...
@@ -58,7 +58,7 @@ describe('AnnotationsExporter', () => {
it
(
'throws error when empty list of annotations is provided'
,
()
=>
{
assert
.
throws
(
()
=>
exporter
.
buildTextExportContent
([]
,
{}
),
()
=>
exporter
.
buildTextExportContent
([]),
'No annotations to export'
,
);
});
...
...
@@ -76,6 +76,16 @@ describe('AnnotationsExporter', () => {
{
...
baseAnnotation
,
...
newReply
(),
target
:
[
{
selector
:
[
{
type
:
'PageSelector'
,
label
:
'23'
,
},
],
},
],
},
];
const
groupName
=
'My group'
;
...
...
@@ -122,7 +132,8 @@ ${isoDate}
Annotation text
bill
"null"
Tags: tag_1, tag_2`
,
Tags: tag_1, tag_2
Page: 23`
,
);
});
...
...
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