Skip to content

Commit

Permalink
feat: Parse URLs from policyRef
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Nov 7, 2023
1 parent 799ce44 commit 089de6d
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 19 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@types/geojson": "^7946.0.12",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"cheerio": "1.0.0-rc.12",
"copyfiles": "^2.4.1",
"docx": "^8.2.4",
"eslint": "^8.51.0",
Expand All @@ -67,10 +68,10 @@
"lodash.omit": "^4.5.0",
"lodash.set": "^4.3.2",
"lodash.startcase": "^4.4.0",
"marked": "^9.1.5",
"prettier": "^3.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"striptags": "^3.2.0",
"type-fest": "^4.4.0",
"uuid": "^9.0.1",
"zod": "^3.22.4"
Expand All @@ -89,12 +90,12 @@
"@types/lodash.set": "^4.3.7",
"@types/lodash.startcase": "^4.4.8",
"@types/node": "^18.16.19",
"@types/react": "^18.2.17",
"@types/react-dom": "^18.2.14",
"@types/uuid": "^9.0.6",
"esbuild": "^0.19.5",
"@types/react": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.8.0",
"esbuild": "^0.19.5",
"esbuild-jest": "^0.5.0",
"eslint": "^8.46.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
Expand Down
122 changes: 115 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions src/export/bops/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { load } from "cheerio";
import isEmpty from "lodash.isempty";
import isNil from "lodash.isnil";
import striptags from "striptags";
import { marked } from "marked";

import { Passport } from "../../models/passport";
import { getResultData } from "../../models/result";
Expand Down Expand Up @@ -264,10 +265,7 @@ export function formatProposalDetails({
}
if (crumb.autoAnswered) metadata.auto_answered = true;
if (node.data?.policyRef) {
metadata.policy_refs = [
// remove html tags
{ text: striptags(node.data?.policyRef as string) },
];
metadata.policy_refs = parsePolicyRefs(node.data.policyRefs as string);
}
return metadata;
})();
Expand All @@ -286,6 +284,17 @@ export function formatProposalDetails({
};
}

export const parsePolicyRefs = (markdownOrHTML: string) => {
const htmlString = marked.parse(markdownOrHTML);
const $ = load(htmlString);
const policyRefs = $("a").map((_index, el) => ({
text: $(el).prop("textContent")?.trim() ?? undefined,
url: $(el).attr("href"),
}));

return policyRefs.toArray();
};

export function computeBOPSParams({
sessionId,
flow,
Expand Down
Loading

0 comments on commit 089de6d

Please sign in to comment.