diff --git a/core/actions/googleDriveImport/gdocPlugins.test.ts b/core/actions/googleDriveImport/gdocPlugins.test.ts index 92c0e8b2b..28dbb1e05 100644 --- a/core/actions/googleDriveImport/gdocPlugins.test.ts +++ b/core/actions/googleDriveImport/gdocPlugins.test.ts @@ -841,7 +841,7 @@ test("Structure References", async () => {
-Here is some text {ref2}, {ref1}, {ref38}
Here is some text {ref2}{ref1}, {ref38}
Description | -Seeing how microbes are organized ... | +We previously released a draft genome assembly for the lone star tick, A. americanum. We've now predicted genes from this assembly to use for downstream functional characterization and comparative genomics efforts. |
Hello
`; - const expectedOutputHtml = `Seeing how microbes are organized ...`; + const expectedOutputHtml = `We previously released a draft genome assembly for the lone star tick, A. americanum. We've now predicted genes from this assembly to use for downstream functional characterization and comparative genomics efforts.`; const result = getDescription(inputHtml); diff --git a/core/actions/googleDriveImport/gdocPlugins.ts b/core/actions/googleDriveImport/gdocPlugins.ts index 6ead800e8..409bd7c64 100644 --- a/core/actions/googleDriveImport/gdocPlugins.ts +++ b/core/actions/googleDriveImport/gdocPlugins.ts @@ -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") { @@ -165,9 +168,10 @@ export const getDescription = (htmlString: string): string => { properties: {}, children: tableData[0].value, }; - description = rehypeFragmentToHtmlString(valueFragment) - .replace("", "") - .replace("", ""); + description = rehypeFragmentToHtmlString(valueFragment).replace( + /<\/?(span|p)>/g, + "" + ); return false; } } @@ -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") { @@ -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) {