@@ -19,40 +19,57 @@ const legend =`
1919- Entries in the effective column marked with an * are stable right now but turn to effective documents in the near future
2020- Entries in the effective column marked with a † will turn deprecated in the near future` ;
2121
22+ // This one component will be copied to all files containing tables we want colored.
23+ // These tables may differ from file to file, and the following snippet can work with all of them,
24+ // even those that might not be present in the file in question.
25+ // We trade this tiny bit of redundancy off for keeping this file simple.
2226const reactHighlightTableCellBackground = `
2327import { useEffect } from 'react';
28+
2429export const TableCellStyleApplier = () => {
2530 // apply background color based on cell index
26- const colorMapping = {
27- 3: '#FBFDE2', // draft
28- 4: '#E2EAFD', // effective
29- 5: '#FDE2E2' // deprecated
31+ const colorMappingOverview = {
32+ 3: '#FBFDE2', // draft
33+ 4: '#E2EAFD', // effective
34+ 5: '#FDE2E2' // deprecated
35+ };
36+
37+ const colorMappingTrackOverview = {
38+ 2: '#FBFDE2', // draft
39+ 3: '#E2EAFD', // effective
40+ 4: '#FDE2E2' // deprecated
3041 };
31-
3242
3343 useEffect(() => {
34- const divElement = document.querySelector('#color-table-cells');
35- if (divElement) {
36- // the next sibling of that element should be our table
37- const tableElement = divElement.nextElementSibling;
38- if (tableElement && tableElement.tagName.toLowerCase() === 'table') {
39- tableElement.querySelectorAll('tbody tr').forEach((row) => {
40- row.querySelectorAll('td').forEach((cell, index) => {
41- // apply background for all cells that have more content than '-'
42- if (colorMapping[index] && cell.textContent.trim() !== '-') {
43- cell.style.backgroundColor = colorMapping[index];
44+ const applyColorToTable = (tableId, colorMapping) => {
45+ const divElement = document.querySelector('#' + tableId);
46+ if (divElement) {
47+ // The next sibling of that element should be our table
48+ const tableElement = divElement.nextElementSibling;
49+ if (tableElement && tableElement.tagName.toLowerCase() === 'table') {
50+ tableElement.querySelectorAll('tbody tr').forEach((row) => {
51+ row.querySelectorAll('td').forEach((cell, index) => {
52+ // Apply background for all cells that have more content than '-'
53+ if (colorMapping[index] && cell.textContent.trim() !== '-') {
54+ cell.style.backgroundColor = colorMapping[index];
55+ }
56+ });
57+ });
4458 }
45- });
46- });
47- }
48- }
49- }, []);
50-
59+ }
60+ };
61+
62+ // Apply colors to various tables (whatever tables are present)
63+ applyColorToTable('color-table-cells-overview', colorMappingOverview);
64+ applyColorToTable('color-table-cells-track-overview', colorMappingTrackOverview);
65+ }, []);
66+
5167 return null;
52- };
68+ };
5369
54- <TableCellStyleApplier />
55- `
70+ <TableCellStyleApplier />
71+
72+ ` ;
5673
5774var filenames = fs
5875 . readdirSync ( 'standards/' )
@@ -122,7 +139,7 @@ if (!lines.length) lines.push(`${intro}
122139${ legend }
123140${ reactHighlightTableCellBackground }
124141` )
125- lines . push ( '<div id="color-table-cells" />' ) // used to find the sibling table for color encoded background
142+ lines . push ( '<div id="color-table-cells-overview " />' ) // used to find the sibling table for color- encoded background
126143lines . push ( '| Standard | Track | Description | Draft | Effective | Deprecated* |' )
127144lines . push ( '| --------- | ------ | ------------ | ----- | --------- | ----------- |' )
128145Object . entries ( tracks ) . forEach ( ( trackEntry ) => {
@@ -146,8 +163,10 @@ Object.entries(tracks).forEach((trackEntry) => {
146163${ trackIntros [ track ] }
147164
148165${ legend }
166+ ${ reactHighlightTableCellBackground }
149167` )
150168 }
169+ tlines . push ( '<div id="color-table-cells-track-overview" />' ) // used to find the sibling table for color-encoded background
151170 tlines . push ( '| Standard | Description | Draft | Effective | Deprecated* |' )
152171 tlines . push ( '| --------- | ------------ | ----- | --------- | ----------- |' )
153172 Object . entries ( trackEntry [ 1 ] ) . forEach ( ( standardEntry ) => {
0 commit comments