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', () => {
...
@@ -17,11 +17,13 @@ describe('trimAndDedent', () => {
Hello, Jane!
Hello, Jane!
Indented line
Indented line
Goodbye, John!
Goodbye, John!
`
,
`
,
`Hello, Jane!
`Hello, Jane!
Indented line
Indented line
Goodbye, John!`
,
Goodbye, John!`
,
],
],
[
[
...
@@ -50,8 +52,7 @@ Goodbye, John!
...
@@ -50,8 +52,7 @@ Goodbye, John!
multiple
multiple
lines
lines
with no indentation
with no indentation`
,
`
,
],
],
[
[
()
=>
{
()
=>
{
...
...
src/shared/trim-and-dedent.ts
View file @
90cab72d
function
trimLeadingEmptyLines
(
str
:
string
):
string
{
function
trimLeadingAndTrailingEmptyLines
(
str
:
string
):
string
{
return
str
.
replace
(
/^
\s
*
\n
/g
,
''
);
return
str
.
replace
(
/^
\s
*
\n
|
\n\s
*$/g
,
''
);
}
function
trimTrailingEmptyLines
(
str
:
string
):
string
{
return
str
.
replace
(
/
\n\s
*$/g
,
''
);
}
}
/**
/**
...
@@ -71,24 +67,5 @@ export function trimAndDedent(
...
@@ -71,24 +67,5 @@ export function trimAndDedent(
strings
:
TemplateStringsArray
,
strings
:
TemplateStringsArray
,
...
params
:
any
[]
...
params
:
any
[]
):
string
{
):
string
{
if
(
strings
.
length
<
2
)
{
return
trimLeadingAndTrailingEmptyLines
(
dedent
([...
strings
],
...
params
));
// 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
);
}
}
src/sidebar/services/annotations-exporter.ts
View file @
90cab72d
...
@@ -3,6 +3,7 @@ import type { APIAnnotationData } from '../../types/api';
...
@@ -3,6 +3,7 @@ import type { APIAnnotationData } from '../../types/api';
import
{
import
{
documentMetadata
,
documentMetadata
,
isReply
,
isReply
,
pageLabel
,
quote
,
quote
,
}
from
'../helpers/annotation-metadata'
;
}
from
'../helpers/annotation-metadata'
;
import
{
annotationDisplayName
}
from
'../helpers/annotation-user'
;
import
{
annotationDisplayName
}
from
'../helpers/annotation-user'
;
...
@@ -80,16 +81,17 @@ export class AnnotationsExporter {
...
@@ -80,16 +81,17 @@ export class AnnotationsExporter {
];
];
const
annotationsText
=
annotations
const
annotationsText
=
annotations
.
map
(
.
map
(
(
annotation
,
index
)
=>
{
(
annotation
,
index
)
=>
const
page
=
pageLabel
(
annotation
);
trimAndDedent
`
return
trimAndDedent
`
Annotation
${
index
+
1
}
:
Annotation
${
index
+
1
}
:
${
annotation
.
created
}
${
annotation
.
created
}
${
annotation
.
text
}
${
annotation
.
text
}
${
extractUsername
(
annotation
)}
${
extractUsername
(
annotation
)}
"
${
quote
(
annotation
)}
"
"
${
quote
(
annotation
)}
"
Tags:
${
annotation
.
tags
.
join
(
', '
)}
`
,
Tags:
${
annotation
.
tags
.
join
(
', '
)}
)
${
page
?
`Page:
${
page
}
`
:
''
}
`
;
})
.
join
(
'
\
n
\
n'
);
.
join
(
'
\
n
\
n'
);
return
trimAndDedent
`
return
trimAndDedent
`
...
...
src/sidebar/services/test/annotations-exporter-test.js
View file @
90cab72d
...
@@ -58,7 +58,7 @@ describe('AnnotationsExporter', () => {
...
@@ -58,7 +58,7 @@ describe('AnnotationsExporter', () => {
it
(
'throws error when empty list of annotations is provided'
,
()
=>
{
it
(
'throws error when empty list of annotations is provided'
,
()
=>
{
assert
.
throws
(
assert
.
throws
(
()
=>
exporter
.
buildTextExportContent
([]
,
{}
),
()
=>
exporter
.
buildTextExportContent
([]),
'No annotations to export'
,
'No annotations to export'
,
);
);
});
});
...
@@ -76,6 +76,16 @@ describe('AnnotationsExporter', () => {
...
@@ -76,6 +76,16 @@ describe('AnnotationsExporter', () => {
{
{
...
baseAnnotation
,
...
baseAnnotation
,
...
newReply
(),
...
newReply
(),
target
:
[
{
selector
:
[
{
type
:
'PageSelector'
,
label
:
'23'
,
},
],
},
],
},
},
];
];
const
groupName
=
'My group'
;
const
groupName
=
'My group'
;
...
@@ -122,7 +132,8 @@ ${isoDate}
...
@@ -122,7 +132,8 @@ ${isoDate}
Annotation text
Annotation text
bill
bill
"null"
"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