From 3bf146ad4ee73f0f8ec5153c8937919ab6271f7c Mon Sep 17 00:00:00 2001 From: John Konecny <24961694+jfkonecn@users.noreply.github.com> Date: Mon, 17 Feb 2025 18:29:06 -0500 Subject: [PATCH] a --- scripts/generate-news-sections.js | 75 ++++++++++++++++++- .../code-generated/NewsContent01302025.tsx | 45 +++++++++-- 2 files changed, 111 insertions(+), 9 deletions(-) diff --git a/scripts/generate-news-sections.js b/scripts/generate-news-sections.js index f023ba1b0..91d896572 100644 --- a/scripts/generate-news-sections.js +++ b/scripts/generate-news-sections.js @@ -9,10 +9,18 @@ const oncokbBaseUrls = [ 'http://www.oncokb.org', ]; +const autoLinkColumns = [ + { + name: 'Gene', + }, +]; + const md = new MarkdownIt({ html: true, linkify: true, }).use(md => { + // https://markdown-it.github.io/markdown-it + // https://github.com/markdown-it/markdown-it/blob/master/docs/examples/renderer_rules.md md.renderer.rules.table_open = function () { return '
\n'; }; @@ -20,6 +28,70 @@ const md = new MarkdownIt({ md.renderer.rules.table_close = function () { return '
\n
'; }; + + md.core.ruler.push('add-auto-table-links', state => { + let inTh = false; + let inTd = false; + let columnIdx = 0; + let geneIdx = -1; + let mutationIdx = -1; + let currentGene = ''; + const columnIndexes = new Array(autoLinkColumns.length).fill(-1); + for (const token of state.tokens) { + if (token.type === 'table_open') { + for (let i = 0; i < columnIndexes.length; i++) { + columnIndexes[i] = -1; + } + } else if (token.type === 'th_open') { + inTh = true; + } else if (token.type === 'th_close') { + inTh = false; + columnIdx++; + } else if (token.type === 'td_open') { + inTd = true; + } else if (token.type === 'td_close') { + inTd = false; + columnIdx++; + } else if (token.type === 'tr_open') { + columnIdx = 0; + currentGene = ''; + } else if (inTd && columnIdx === geneIdx && token.type === 'inline') { + const child = token.children[0]; + // getAlternativeGenePageLinks(); + //const children = md.parse( + //`[${child.content}](https://oncokb.org/gene/${child.content})`, + //{} + //)[1].children; + currentGene = child.content; + child.content = `{getAlternativeGenePageLinks('${child.content}')}`; + + //token.children = children; + } else if (inTd && columnIdx === mutationIdx && token.type === 'inline') { + const child = token.children[0]; + if (currentGene === '') { + throw new Error( + `No gene for this row and mutation "${child.content}"` + ); + } + // can't figure out how to make a token on my own so I'm forcing + // markdown-it to make me one + const alterationPageLinkTags = md + .parse('[placeholder](placeholder)', {})[1] + .children.filter(x => x.type !== 'text'); + alterationPageLinkTags[0].type = 'para'; + alterationPageLinkTags[0].tag = 'AlterationPageLink'; + alterationPageLinkTags[0].attrSet('hugoSymbol', currentGene); + alterationPageLinkTags[0].attrSet('alteration', child.content); + alterationPageLinkTags[1].tag = 'AlterationPageLink'; + token.children = alterationPageLinkTags; + } else if (inTh && token.content === 'Gene') { + geneIdx = columnIdx; + } else if (inTh && token.content === 'Mutation') { + mutationIdx = columnIdx; + } + } + }); + md.core.ruler.push('fix-links', state => { for (const token of state.tokens) { if (token.type === 'inline') { @@ -49,7 +121,6 @@ const md = new MarkdownIt({ child.tag = 'Link'; const attr = child.attrs[hrefIndex]; attr[0] = 'to'; - console.log(currentUrl); attr[1] = currentUrl.replace(replaceUrlString, ''); } } @@ -119,6 +190,8 @@ files.forEach(file => { const tsxContent = `import React from 'react'; import { Link } from 'react-router-dom'; +import { AlterationPageLink, getAlternativeGenePageLinks } from 'app/shared/utils/UrlUtils'; + export default function ${componentName}() { return ( <> diff --git a/src/main/webapp/app/pages/newsPage/code-generated/NewsContent01302025.tsx b/src/main/webapp/app/pages/newsPage/code-generated/NewsContent01302025.tsx index 45e4af80d..68c4b81c8 100644 --- a/src/main/webapp/app/pages/newsPage/code-generated/NewsContent01302025.tsx +++ b/src/main/webapp/app/pages/newsPage/code-generated/NewsContent01302025.tsx @@ -1,5 +1,10 @@ import React from 'react'; import { Link } from 'react-router-dom'; +import { + AlterationPageLink, + getAlternativeGenePageLinks, +} from 'app/shared/utils/UrlUtils'; + export default function NewsContent01302025() { return ( <> @@ -38,8 +43,14 @@ export default function NewsContent01302025() { 2 - ERBB2 - Oncogenic Mutations + {getAlternativeGenePageLinks('ERBB2')} + + + Cervical Cancer Neratinib @@ -71,8 +82,14 @@ export default function NewsContent01302025() { - KRAS - G12C + {getAlternativeGenePageLinks('KRAS')} + + + Small Bowel Cancer Drug(s) promoted in OncoKB™: Adagrasib (Level 2, @@ -119,8 +136,14 @@ export default function NewsContent01302025() { 1 - ALK - Fusions + {getAlternativeGenePageLinks('ALK')} + + + Non-Small Cell Lung Cancer Alectinib, Brigatinib, Certinib, Crizotinib, Lorlatinib (Level @@ -137,8 +160,14 @@ export default function NewsContent01302025() { 1 - KRAS - G12C + {getAlternativeGenePageLinks('KRAS')} + + + Colorectal Cancer Sensitivity Adagrasib + Cetuximab (Level 1) Adagrasib +