Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkonecn committed Feb 17, 2025
1 parent 55dea90 commit 3bf146a
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 9 deletions.
75 changes: 74 additions & 1 deletion scripts/generate-news-sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,89 @@ 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 '<div className="table-responsive">\n<table className="table">';
};

md.renderer.rules.table_close = function () {
return '</table>\n</div>';
};

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') {
Expand Down Expand Up @@ -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, '');
}
}
Expand Down Expand Up @@ -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 (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<>
Expand Down Expand Up @@ -38,8 +43,14 @@ export default function NewsContent01302025() {
<tbody>
<tr>
<td>2</td>
<td>ERBB2</td>
<td>Oncogenic Mutations</td>
<td>{getAlternativeGenePageLinks('ERBB2')}</td>
<td>
<AlterationPageLink
href="placeholder"
hugoSymbol="ERBB2"
alteration="Oncogenic Mutations"
></AlterationPageLink>
</td>
<td>Cervical Cancer</td>
<td>Neratinib</td>
<td>
Expand Down Expand Up @@ -71,8 +82,14 @@ export default function NewsContent01302025() {
</thead>
<tbody>
<tr>
<td>KRAS</td>
<td>G12C</td>
<td>{getAlternativeGenePageLinks('KRAS')}</td>
<td>
<AlterationPageLink
href="placeholder"
hugoSymbol="KRAS"
alteration="G12C"
></AlterationPageLink>
</td>
<td>Small Bowel Cancer</td>
<td>
<em>Drug(s) promoted in OncoKB™:</em> Adagrasib (Level 2,
Expand Down Expand Up @@ -119,8 +136,14 @@ export default function NewsContent01302025() {
<tbody>
<tr>
<td>1</td>
<td>ALK</td>
<td>Fusions</td>
<td>{getAlternativeGenePageLinks('ALK')}</td>
<td>
<AlterationPageLink
href="placeholder"
hugoSymbol="ALK"
alteration="Fusions"
></AlterationPageLink>
</td>
<td>Non-Small Cell Lung Cancer</td>
<td>
Alectinib, Brigatinib, Certinib, Crizotinib, Lorlatinib (Level
Expand All @@ -137,8 +160,14 @@ export default function NewsContent01302025() {
</tr>
<tr>
<td>1</td>
<td>KRAS</td>
<td>G12C</td>
<td>{getAlternativeGenePageLinks('KRAS')}</td>
<td>
<AlterationPageLink
href="placeholder"
hugoSymbol="KRAS"
alteration="G12C"
></AlterationPageLink>
</td>
<td>Colorectal Cancer</td>
<td>
Sensitivity Adagrasib + Cetuximab (Level 1) Adagrasib +
Expand Down

0 comments on commit 3bf146a

Please sign in to comment.