Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A followup description fix and reference count fix #979

Merged
merged 8 commits into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/actions/googleDriveImport/gdocPlugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ test("Structure References", async () => {
<html>
<head></head>
<body>
<div><p>Here is some text {ref2}, {ref1}, {ref38}</p></div>
<div><p>Here is some text {ref2}{ref1}, {ref38}</p></div>
<table>
<tbody>
<tr>
Expand Down Expand Up @@ -889,7 +889,7 @@ test("Structure References", async () => {
Here is some text <a
data-type="reference" data-value="https://doi.org/10.1038/s41586-020-2983-4" data-unstructured-value="">
[1]
</a>, <a
</a><a
data-type="reference" data-value="https://doi.org/10.57844/arcadia-0zvp-xz86" data-unstructured-value="">
[2]
</a>, {ref38}
Expand Down Expand Up @@ -1225,14 +1225,14 @@ test("getDescription", async () => {
</tr>
<tr>
<td>Description</td>
<td>Seeing how <i>microbes</i> are organized ...</td>
<td><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&#x22;Arial&#x22;;line-height:1.0;text-align:left"><span>We previously released a draft genome assembly for the lone star tick, <span style="font-style:italic">A. americanum. </span><span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:&#x22;Arial&#x22;;font-style:normal">We've now predicted genes from this assembly to use for downstream functional characterization and comparative genomics efforts.</span></p></span></td>
</tr>
</table><p>Hello</p>
</body>
</html>

`;
const expectedOutputHtml = `Seeing how <i>microbes</i> are organized ...`;
const expectedOutputHtml = `We previously released a draft genome assembly for the lone star tick, <i>A. americanum. </i>We've now predicted genes from this assembly to use for downstream functional characterization and comparative genomics efforts.`;

const result = getDescription(inputHtml);

Expand Down
15 changes: 10 additions & 5 deletions core/actions/googleDriveImport/gdocPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ export const tableToObjectArray = (node: any) => {
export const getDescription = (htmlString: string): string => {
let description = "";
rehype()
.use(structureFormatting)
.use(removeVerboseFormatting)
.use(removeGoogleLinkForwards)
.use(() => (tree: Root) => {
visit(tree, "element", (node: any) => {
if (node.tagName === "table") {
Expand All @@ -165,9 +168,10 @@ export const getDescription = (htmlString: string): string => {
properties: {},
children: tableData[0].value,
};
description = rehypeFragmentToHtmlString(valueFragment)
.replace("<span>", "")
.replace("</span>", "");
description = rehypeFragmentToHtmlString(valueFragment).replace(
/<\/?(span|p)>/g,
""
);
return false;
}
}
Expand Down Expand Up @@ -707,6 +711,7 @@ export const structureAnchors = () => (tree: Root) => {
};
export const structureReferences = () => (tree: Root) => {
const allReference: any[] = [];

const doiReferenceCounts: { [key: string]: number } = {};
visit(tree, (node: any, index: any, parent: any) => {
if (node.tagName === "table") {
Expand Down Expand Up @@ -767,12 +772,12 @@ export const structureReferences = () => (tree: Root) => {
}
}
});

const referenceIds = allReference.map((ref) => ref.id);
const referenceVarOrder: string[] = [];

visit(tree, "text", (textNode: any, index: any, parent: any) => {
if (typeof textNode.value === "string") {
const regex = new RegExp(/\{([^\s\]]+)\}/g);
const regex = new RegExp(/\{([^\{\}]+?)\}/g);
let match;

while ((match = regex.exec(textNode.value)) !== null) {
Expand Down
Loading