{annotations.map((annotation, index) => {
const page = pageLabel(annotation);
const annotationQuote = quote(annotation);
const annotationDescription = description(annotation);
const renderedComment = renderMathAndMarkdown(annotation.text);
// When the result of rendering the text's markdown is just a
// single paragraph, we fall back to the annotation text, to
// avoid extra margins added by some editors, like Google Docs
const comment =
renderedComment === `
${annotation.text}
`
? annotation.text
: renderedComment;
return (
Annotation {index + 1}:
Created at:
Author:
{extractUsername(annotation)}
{page && (
Page:
{page}
)}
Type:
{annotationRole(annotation, this._settings)}
{annotationQuote && (
Quote:
{annotationQuote}
)}
{annotationDescription && (
Description:
{annotationDescription}
)}
Comment:
{annotation.tags.length > 0 && (
Tags:
{annotation.tags.join(', ')}
)}
);
})}
,
{},
{ pretty: true },
// `renderToString` indents lines with tabs when using `pretty: true`.
// Replacing them with double spaces we avoid side effects when pasting
// the result in a web app.
).replace(/\t/g, ' ');
}
private _exportCommon(
annotations: APIAnnotationData[],
{
displayNamesEnabled,
defaultAuthority,
}: Required>,
) {
const [firstAnnotation] = annotations;
if (!firstAnnotation) {
throw new Error('No annotations to export');
}
const extractUsername = (annotation: APIAnnotationData) =>
annotationDisplayName(annotation, defaultAuthority, displayNamesEnabled);
const { uri, title } = documentMetadata(firstAnnotation);
const uniqueUsers = [
...new Set(
annotations.map(anno => extractUsername(anno)).filter(Boolean),
),
];
const replies = annotations.filter(anno => isReply(anno));
return { uri, title, uniqueUsers, replies, extractUsername };
}
}