ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/ontology/actions/lib/mdlite.ts

actions/lib/mdlite.ts

12 líneas, 527 B.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // The two pieces of markdown tables the generators read: the separator row and the cells of a row.
  2. /** `|---|:--:|` */
  3. export const SEP = /^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;
  4. /** The cells of a table row; a literal pipe inside a cell is written `\|`. */
  5. export function cells(line: string): string[] {
  6. let s = line.trim();
  7. if (s.startsWith('|')) s = s.slice(1);
  8. if (s.endsWith('|') && !s.endsWith('\\|')) s = s.slice(0, -1);
  9. return s.split(/(?<!\\)\|/).map((c) => c.trim().replaceAll('\\|', '|'));
  10. }