codigo0/node_modules/micromark-extension-gfm-table/dev/lib/infer.js
planetazuzu 5d7a6500fe refactor: Fase 1 - Clean Architecture, refactorización modular y eliminación de duplicidades
-  Ticket 1.1: Estructura Clean Architecture en backend
-  Ticket 1.2: Schemas Zod compartidos
-  Ticket 1.3: Refactorización drugs.ts (1362 → 8 archivos modulares)
-  Ticket 1.4: Refactorización procedures.ts (3583 → 6 archivos modulares)
-  Ticket 1.5: Eliminación de duplicidades (~50 líneas)

Cambios principales:
- Creada estructura Clean Architecture en backend/src/
- Schemas Zod compartidos en backend/src/shared/schemas/
- Refactorización modular de drugs y procedures
- Utilidades genéricas en src/utils/ (filter, validation)
- Eliminados scripts obsoletos y documentación antigua
- Corregidos errores: QueryClient, import test-error-handling
- Build verificado y funcionando correctamente
2026-01-25 21:09:47 +01:00

65 lines
1.6 KiB
JavaScript

/**
* @import {Event} from 'micromark-util-types'
*/
/**
* @typedef {'center' | 'left' | 'none' | 'right'} Align
*/
import {ok as assert} from 'devlop'
/**
* Figure out the alignment of a GFM table.
*
* @param {Readonly<Array<Event>>} events
* List of events.
* @param {number} index
* Table enter event.
* @returns {Array<Align>}
* List of aligns.
*/
export function gfmTableAlign(events, index) {
assert(events[index][1].type === 'table', 'expected table')
let inDelimiterRow = false
/** @type {Array<Align>} */
const align = []
while (index < events.length) {
const event = events[index]
if (inDelimiterRow) {
if (event[0] === 'enter') {
// Start of alignment value: set a new column.
// To do: `markdown-rs` uses `tableDelimiterCellValue`.
if (event[1].type === 'tableContent') {
align.push(
events[index + 1][1].type === 'tableDelimiterMarker'
? 'left'
: 'none'
)
}
}
// Exits:
// End of alignment value: change the column.
// To do: `markdown-rs` uses `tableDelimiterCellValue`.
else if (event[1].type === 'tableContent') {
if (events[index - 1][1].type === 'tableDelimiterMarker') {
const alignIndex = align.length - 1
align[alignIndex] = align[alignIndex] === 'left' ? 'center' : 'right'
}
}
// Done!
else if (event[1].type === 'tableDelimiterRow') {
break
}
} else if (event[0] === 'enter' && event[1].type === 'tableDelimiterRow') {
inDelimiterRow = true
}
index += 1
}
return align
}