Skip to content

Commit 46e50e3

Browse files
nperez0111claude
andcommitted
fix: resolve lint errors in custom markdown parser/serializer
Add curly braces to single-line if/while statements and convert inner function declaration to arrow function to fix no-inner-declarations error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 20027ec commit 46e50e3

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

packages/core/src/api/exporters/markdown/htmlToMarkdown.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function serializeBlockquote(el: HTMLElement, ctx: SerializeContext): string {
143143

144144
function serializeCodeBlock(el: HTMLElement, ctx: SerializeContext): string {
145145
const codeEl = el.querySelector("code");
146-
if (!codeEl) return "";
146+
if (!codeEl) {return "";}
147147

148148
const language =
149149
codeEl.getAttribute("data-language") ||
@@ -283,7 +283,7 @@ function serializeListItem(
283283
if (details) {
284284
const summary = details.querySelector("summary");
285285
for (const child of Array.from(details.children)) {
286-
if (child === summary) continue;
286+
if (child === summary) {continue;}
287287
const childTag = child.tagName.toLowerCase();
288288
if (childTag === "p") {
289289
const content = serializeInlineContent(child as HTMLElement);
@@ -299,8 +299,8 @@ function serializeListItem(
299299
const childTag = child.tagName.toLowerCase();
300300

301301
// Skip the first content element and checkbox
302-
if (child === firstContentEl || (child as HTMLElement) === checkbox) continue;
303-
if (childTag === "input") continue;
302+
if (child === firstContentEl || (child as HTMLElement) === checkbox) {continue;}
303+
if (childTag === "input") {continue;}
304304

305305
// Nested lists and other block content
306306
if (childTag === "ul" || childTag === "ol") {
@@ -322,10 +322,10 @@ function getFirstContentElement(
322322
checkbox: HTMLInputElement | null
323323
): HTMLElement | null {
324324
for (const child of Array.from(li.children)) {
325-
if (child === checkbox) continue;
326-
if (child.tagName.toLowerCase() === "input") continue;
325+
if (child === checkbox) {continue;}
326+
if (child.tagName.toLowerCase() === "input") {continue;}
327327
const tag = child.tagName.toLowerCase();
328-
if (tag === "p" || tag === "span") return child as HTMLElement;
328+
if (tag === "p" || tag === "span") {return child as HTMLElement;}
329329
}
330330
return null;
331331
}
@@ -350,13 +350,13 @@ function serializeTable(el: HTMLElement, ctx: SerializeContext): string {
350350
const grid: (string | null)[][] = [];
351351

352352
trElements.forEach((tr, rowIdx) => {
353-
if (!grid[rowIdx]) grid[rowIdx] = [];
353+
if (!grid[rowIdx]) {grid[rowIdx] = [];}
354354
const cellElements = tr.querySelectorAll("th, td");
355355
let gridCol = 0;
356356

357357
cellElements.forEach((cell) => {
358358
// Find next empty column in this row
359-
while (grid[rowIdx][gridCol] !== undefined) gridCol++;
359+
while (grid[rowIdx][gridCol] !== undefined) {gridCol++;}
360360

361361
if (rowIdx === 0 && cell.tagName.toLowerCase() === "th") {
362362
hasHeader = true;
@@ -370,7 +370,7 @@ function serializeTable(el: HTMLElement, ctx: SerializeContext): string {
370370
for (let r = 0; r < rowspan; r++) {
371371
for (let c = 0; c < colspan; c++) {
372372
const ri = rowIdx + r;
373-
if (!grid[ri]) grid[ri] = [];
373+
if (!grid[ri]) {grid[ri] = [];}
374374
grid[ri][gridCol + c] = r === 0 && c === 0 ? content : "";
375375
}
376376
}
@@ -393,7 +393,7 @@ function serializeTable(el: HTMLElement, ctx: SerializeContext): string {
393393
rows.push(row);
394394
}
395395

396-
if (rows.length === 0) return "";
396+
if (rows.length === 0) {return "";}
397397

398398
// Determine column widths
399399
const colWidths: number[] = [];
@@ -475,7 +475,7 @@ function serializeVideo(el: HTMLElement, ctx: SerializeContext): string {
475475

476476
function serializeAudio(el: HTMLElement, ctx: SerializeContext): string {
477477
const src = el.getAttribute("src") || "";
478-
if (!src) return "";
478+
if (!src) {return "";}
479479
// Audio has no visible representation in markdown; output as link with empty text
480480
return ctx.indent + `[](${src})\n\n`;
481481
}
@@ -521,14 +521,14 @@ function serializeFigure(el: HTMLElement, ctx: SerializeContext): string {
521521
function serializeBlockLink(el: HTMLElement, ctx: SerializeContext): string {
522522
const href = el.getAttribute("href") || "";
523523
const text = el.textContent?.trim() || "";
524-
if (!href) return ctx.indent + text + "\n\n";
524+
if (!href) {return ctx.indent + text + "\n\n";}
525525
return ctx.indent + `[${text}](${href})\n\n`;
526526
}
527527

528528
function serializeDetails(el: HTMLElement, ctx: SerializeContext): string {
529529
// Toggle heading or toggle list item
530530
const summary = el.querySelector("summary");
531-
if (!summary) return serializeChildren(el, ctx);
531+
if (!summary) {return serializeChildren(el, ctx);}
532532

533533
// Check if summary contains a heading
534534
const heading = summary.querySelector("h1, h2, h3, h4, h5, h6");

packages/core/src/api/parsers/markdown/markdownToHtml.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,13 @@ function parseImage(
208208
// ![alt](url) or ![alt](url "title")
209209
const altStart = start + 2; // after ![
210210
const altEnd = text.indexOf("]", altStart);
211-
if (altEnd === -1) return null;
211+
if (altEnd === -1) {return null;}
212212

213-
if (text[altEnd + 1] !== "(") return null;
213+
if (text[altEnd + 1] !== "(") {return null;}
214214

215215
const urlStart = altEnd + 2;
216216
const parenEnd = findClosingParen(text, urlStart - 1);
217-
if (parenEnd === -1) return null;
217+
if (parenEnd === -1) {return null;}
218218

219219
const alt = text.substring(altStart, altEnd);
220220
let urlContent = text.substring(urlStart, parenEnd).trim();
@@ -250,13 +250,13 @@ function parseLink(
250250
// [text](url)
251251
const textStart = start + 1;
252252
const textEnd = findClosingBracket(text, start);
253-
if (textEnd === -1) return null;
253+
if (textEnd === -1) {return null;}
254254

255-
if (text[textEnd + 1] !== "(") return null;
255+
if (text[textEnd + 1] !== "(") {return null;}
256256

257257
const urlStart = textEnd + 2;
258258
const parenEnd = findClosingParen(text, textEnd + 1);
259-
if (parenEnd === -1) return null;
259+
if (parenEnd === -1) {return null;}
260260

261261
const linkText = text.substring(textStart, textEnd);
262262
const url = text.substring(urlStart, parenEnd).trim();
@@ -274,10 +274,10 @@ function findClosingBracket(text: string, openPos: number): number {
274274
i++; // skip escaped
275275
continue;
276276
}
277-
if (text[i] === "[") depth++;
277+
if (text[i] === "[") {depth++;}
278278
if (text[i] === "]") {
279279
depth--;
280-
if (depth === 0) return i;
280+
if (depth === 0) {return i;}
281281
}
282282
}
283283
return -1;
@@ -290,10 +290,10 @@ function findClosingParen(text: string, openPos: number): number {
290290
i++;
291291
continue;
292292
}
293-
if (text[i] === "(") depth++;
293+
if (text[i] === "(") {depth++;}
294294
if (text[i] === ")") {
295295
depth--;
296-
if (depth === 0) return i;
296+
if (depth === 0) {return i;}
297297
}
298298
}
299299
return -1;
@@ -309,10 +309,10 @@ function parseDelimited(
309309
const len = delimiter.length;
310310
const afterOpen = start + len;
311311

312-
if (afterOpen >= text.length) return null;
312+
if (afterOpen >= text.length) {return null;}
313313

314314
// Opening delimiter must not be followed by whitespace
315-
if (text[afterOpen] === " " || text[afterOpen] === "\t") return null;
315+
if (text[afterOpen] === " " || text[afterOpen] === "\t") {return null;}
316316

317317
// Find closing delimiter
318318
let j = afterOpen;
@@ -580,11 +580,11 @@ function tokenize(markdown: string): Token[] {
580580
const minChildIndent = indent + 1;
581581

582582
// Helper to check if a line belongs to this list item
583-
function belongsToItem(lineStr: string): boolean {
584-
if (lineStr.trim() === "") return true; // blank lines checked separately
583+
const belongsToItem = (lineStr: string): boolean => {
584+
if (lineStr.trim() === "") {return true;} // blank lines checked separately
585585
const lineInd = lineStr.match(/^\s*/)![0].length;
586586
// Lines at contentIndent are continuation text
587-
if (lineInd >= contentIndent) return true;
587+
if (lineInd >= contentIndent) {return true;}
588588
// Lines between marker and content column that start a sub-list
589589
if (
590590
lineInd >= minChildIndent &&
@@ -615,7 +615,7 @@ function tokenize(markdown: string): Token[] {
615615
break;
616616
}
617617

618-
if (!belongsToItem(cur)) break;
618+
if (!belongsToItem(cur)) {break;}
619619

620620
// Strip indent: for lines at contentIndent+, strip contentIndent chars;
621621
// for sub-list lines between minChildIndent and contentIndent, strip minChildIndent
@@ -652,14 +652,14 @@ function tokenize(markdown: string): Token[] {
652652
while (i < lines.length) {
653653
const nextLine = lines[i];
654654
// Stop paragraph on blank line
655-
if (nextLine.trim() === "") break;
655+
if (nextLine.trim() === "") {break;}
656656
// Stop on block-level element
657-
if (/^(#{1,6})\s/.test(nextLine)) break;
658-
if (/^(`{3,}|~{3,})/.test(nextLine)) break;
659-
if (/^\s{0,3}>/.test(nextLine)) break;
660-
if (/^(\s{0,3})([-*_])\s*(\2\s*){2,}$/.test(nextLine)) break;
661-
if (/^\s*([-*+]|\d+[.)])\s+/.test(nextLine)) break;
662-
if (/^\s*\|(.+\|)+\s*$/.test(nextLine)) break;
657+
if (/^(#{1,6})\s/.test(nextLine)) {break;}
658+
if (/^(`{3,}|~{3,})/.test(nextLine)) {break;}
659+
if (/^\s{0,3}>/.test(nextLine)) {break;}
660+
if (/^(\s{0,3})([-*_])\s*(\2\s*){2,}$/.test(nextLine)) {break;}
661+
if (/^\s*([-*+]|\d+[.)])\s+/.test(nextLine)) {break;}
662+
if (/^\s*\|(.+\|)+\s*$/.test(nextLine)) {break;}
663663
// Check if next-next line is setext marker
664664
if (
665665
i + 1 < lines.length &&
@@ -686,16 +686,16 @@ function tryParseTable(
686686
start: number
687687
): { token: TableToken; nextLine: number } | null {
688688
// A table needs at least a header row and a separator row
689-
if (start + 1 >= lines.length) return null;
689+
if (start + 1 >= lines.length) {return null;}
690690

691691
const headerLine = lines[start];
692692
const separatorLine = lines[start + 1];
693693

694694
// Check separator line format: | --- | --- | or | :--- | ---: |
695-
if (!/^\s*\|(\s*:?-+:?\s*\|)+\s*$/.test(separatorLine)) return null;
695+
if (!/^\s*\|(\s*:?-+:?\s*\|)+\s*$/.test(separatorLine)) {return null;}
696696

697697
// Check header line format: | ... | ... |
698-
if (!/^\s*\|(.+\|)+\s*$/.test(headerLine)) return null;
698+
if (!/^\s*\|(.+\|)+\s*$/.test(headerLine)) {return null;}
699699

700700
const headers = parsePipeCells(headerLine);
701701
const alignments = parseAlignments(separatorLine);
@@ -704,7 +704,7 @@ function tryParseTable(
704704
let i = start + 2;
705705
while (i < lines.length) {
706706
const line = lines[i];
707-
if (!/^\s*\|(.+\|)+\s*$/.test(line)) break;
707+
if (!/^\s*\|(.+\|)+\s*$/.test(line)) {break;}
708708
rows.push(parsePipeCells(line));
709709
i++;
710710
}
@@ -757,9 +757,9 @@ function parseAlignments(
757757
const trimmed = cell.trim();
758758
const left = trimmed.startsWith(":");
759759
const right = trimmed.endsWith(":");
760-
if (left && right) return "center";
761-
if (right) return "right";
762-
if (left) return "left";
760+
if (left && right) {return "center";}
761+
if (right) {return "right";}
762+
if (left) {return "left";}
763763
return null;
764764
});
765765
}

0 commit comments

Comments
 (0)