MCPcopy Create free account
hub / github.com/github/awesome-copilot / formatTableCell

Function formatTableCell

eng/update-readme.mjs:250–270  ·  view source on GitHub ↗

* Format arbitrary multiline text for safe rendering inside a markdown table cell. * - Preserves line breaks by converting to * - Escapes pipe characters (|) to avoid breaking table columns * - Trims leading/trailing whitespace on each line * - Collapses multiple consecutive blank lines

(text)

Source from the content-addressed store, hash-verified

248 * @returns {string} table-safe content
249 */
250function formatTableCell(text) {
251 if (text === null || text === undefined) return "";
252 let s = String(text);
253 // Normalize line endings
254 s = s.replace(/\r\n/g, "\n");
255 // Split lines, trim, drop empty groups while preserving intentional breaks
256 const lines = s
257 .split("\n")
258 .map((l) => l.trim())
259 .filter((_, idx, arr) => {
260 // Keep single blank lines, drop consecutive blanks
261 if (arr[idx] !== "") return true;
262 return arr[idx - 1] !== ""; // allow one blank, remove duplicates
263 });
264 s = lines.join("\n");
265 // Escape table pipes
266 s = s.replace(/\|/g, "|");
267 // Convert remaining newlines to <br /> for a single-cell rendering
268 s = s.replace(/\n/g, "<br />");
269 return s.trim();
270}
271
272function makeBadges(link, type, linkIntent = "source") {
273 const aka = AKA_INSTALL_URLS[type] || AKA_INSTALL_URLS.instructions;

Callers 7

generateHooksSectionFunction · 0.85
generateWorkflowsSectionFunction · 0.85
generateSkillsSectionFunction · 0.85
generatePluginsSectionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected