Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/workflows/news-article-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,9 @@ This validation checks:
6. ✅ Index files have content (> 1KB) (blocking)
7. ⚠️ Sitemap news-URL coverage (validated at build time; missing sitemap.xml is OK — it's generated by prebuild)
8. ⚠️ Language switcher consistency across all 14 languages (warning level)
9. ⚠️ Articles have article-top-nav with back-to-news link (warning level)
10. ⚠️ Articles have back-to-news link in footer (warning level)
11. ⚠️ HTMLHint validation on news articles (warning level; auto-fix attempted)
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documented validation checklist numbering now jumps from 8 to 11, which no longer matches the actual validate-news-generation.sh checks (it has checks 9 and 10 as well). Please update this list to include the missing check numbers/descriptions or renumber so it stays consistent with the script output.

Suggested change
11. ⚠️ HTMLHint validation on news articles (warning level; auto-fix attempted)
9. ⚠️ HTMLHint validation on news articles (warning level; auto-fix attempted)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0393e7c: added the missing check 9 (article-top-nav) and check 10 (footer back-to-news link) so the list now runs 1–11 consecutively.


**CRITICAL: Analysis Quality Check**
Every generated article MUST contain real analysis, not merely a translated list of document links.
Expand Down Expand Up @@ -1165,13 +1168,20 @@ Before creating the PR, validate the quality of generated articles:

**HTML Validation:**
```bash
# Validate HTML structure
npx htmlhint news/*.html --config .htmlhintrc
# Validate HTML structure with auto-fix for common nesting errors
if ! npx htmlhint "news/*-*.html" 2>/dev/null; then
echo "⚠️ HTML validation errors found, attempting auto-fix..."
npx tsx scripts/article-quality-enhancer.ts --fix
if ! npx htmlhint "news/*-*.html"; then
echo "❌ HTML validation errors remain after auto-fix. Please fix them before creating a PR."
exit 1
fi
fi

# Check for common issues:
# - Missing alt attributes
# - Duplicate IDs
# - Invalid nesting
# - Invalid nesting (<p><ul>, <p><div>)
# - Missing required meta tags
```

Expand Down
25 changes: 24 additions & 1 deletion .github/workflows/news-committee-reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,30 @@ grep -o 'Why It Matters[^<]*' "news/$(date +%Y-%m-%d)-committee-reports-en.html"
**Note**: News index files, metadata, and sitemap are generated automatically at build time by the `prebuild` script. Do NOT run generation scripts or commit their output — only commit the article HTML files. Run `npm run prebuild` (or `npm run build`) locally if you need to preview the generated indexes, metadata, or sitemap.

### Step 6: Validate & Create PR
Validate HTML structure, then create PR:
Run validation and HTMLHint before creating PR:
```bash
bash scripts/validate-news-generation.sh
VALIDATION_EXIT=$?
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ News generation validation failed. Fix the reported issues before creating a PR."
exit "$VALIDATION_EXIT"
fi

Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VALIDATION_EXIT is captured but never used in this snippet. As written, validation errors from validate-news-generation.sh won’t stop PR creation guidance. Either remove the unused variable or add a check that exits (or otherwise clearly gates) when VALIDATION_EXIT is non-zero.

Suggested change
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ News generation validation failed. Fix the reported issues before creating a PR."
exit "$VALIDATION_EXIT"
fi

Copilot uses AI. Check for mistakes.
# HTMLHint validation with auto-fix
NEWS_FILES=$(find news -maxdepth 1 -name '*-*.html' | wc -l)
if [ "$NEWS_FILES" -gt 0 ]; then
if ! npx htmlhint "news/*-*.html" 2>/dev/null; then
echo "⚠️ HTML validation errors found, attempting auto-fix..."
npx tsx scripts/article-quality-enhancer.ts --fix
if ! npx htmlhint "news/*-*.html"; then
echo "❌ HTML validation errors remain after auto-fix. Please fix them before creating a PR."
exit 1
fi
fi
fi
```

Then create PR:
```
safeoutputs___create_pull_request
```
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/news-evening-analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -1001,9 +1001,28 @@ This validation checks:
6. ✅ Index files have content (> 1KB) (blocking)
7. ⚠️ Sitemap news-URL coverage (validated at build time; missing sitemap.xml is OK — it's generated by prebuild)
8. ⚠️ Language switcher consistency across all 14 languages (warning level)
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documented validation checklist numbering now jumps from 8 to 11, which no longer matches the actual validate-news-generation.sh checks (it has checks 9 and 10 as well). Please update this list to include the missing check numbers/descriptions or renumber so it stays consistent with the script output.

Suggested change
8. ⚠️ Language switcher consistency across all 14 languages (warning level)
8. ⚠️ Language switcher consistency across all 14 languages (warning level)
9. ⚠️ Additional non-blocking quality checks as implemented in \`validate-news-generation.sh\` (warning level)
10. ✅ Additional blocking quality checks as implemented in \`validate-news-generation.sh\` (blocking)

Copilot uses AI. Check for mistakes.
9. ⚠️ Articles have article-top-nav with back-to-news link (warning level)
10. ⚠️ Articles have back-to-news link in footer (warning level)
11. ⚠️ HTMLHint validation on news articles (warning level; auto-fix attempted)

**Exit code 0** = pass (proceed to Step 7), **exit code 1** = fail (STOP, do not create PR).

**HTMLHint Auto-Fix:**
After running `validate-news-generation.sh`, run HTMLHint with auto-fix for any remaining nesting errors:
```bash
NEWS_FILES=$(find news -maxdepth 1 -name '*-*.html' | wc -l)
if [ "$NEWS_FILES" -gt 0 ]; then
if ! npx htmlhint "news/*-*.html" 2>/dev/null; then
echo "⚠️ HTML validation errors found, attempting auto-fix..."
npx tsx scripts/article-quality-enhancer.ts --fix
if ! npx htmlhint "news/*-*.html"; then
echo "❌ HTML validation errors remain after auto-fix. Please fix them before creating a PR."
exit 1
fi
fi
fi
```

**CRITICAL: Analysis Quality Check**
Every generated article MUST contain real analysis, not merely a translated list of document links.
Verify each article includes analytical lede paragraphs, thematic grouping with commentary, policy significance analysis, and forward-looking "What to Watch" sections.
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/news-month-ahead.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,29 @@ npx tsx scripts/fix-article-navigation.ts

### Step 4: Translate, Validate & Verify Analysis Quality

Run validation and HTMLHint before creating PR:
```bash
bash scripts/validate-news-generation.sh
VALIDATION_EXIT=$?
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ News generation validation failed. Fix the reported issues before creating a PR."
exit "$VALIDATION_EXIT"
fi

Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VALIDATION_EXIT is captured but never used in this snippet. As written, validation errors from validate-news-generation.sh won’t stop PR creation guidance. Either remove the unused variable or add a check that exits (or otherwise clearly gates) when VALIDATION_EXIT is non-zero.

Suggested change
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ Validation script failed. Please fix the reported issues before proceeding to HTML validation or creating a PR."
exit "$VALIDATION_EXIT"
fi

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0393e7c: added if [ "$VALIDATION_EXIT" -ne 0 ]; then exit "$VALIDATION_EXIT"; fi after VALIDATION_EXIT=$? in all 7 workflow files where the guard was missing.

# HTMLHint validation with auto-fix for common nesting errors
NEWS_FILES=$(find news -maxdepth 1 -name '*-*.html' | wc -l)
if [ "$NEWS_FILES" -gt 0 ]; then
if ! npx htmlhint "news/*-*.html" 2>/dev/null; then
echo "⚠️ HTML validation errors found, attempting auto-fix..."
npx tsx scripts/article-quality-enhancer.ts --fix
if ! npx htmlhint "news/*-*.html"; then
echo "❌ HTML validation failed after auto-fix. Please fix remaining issues before creating PR."
exit 1
fi
fi
fi
```

**CRITICAL: Each article MUST contain real analysis, not just a list of translated event titles.**
Every generated article must include strategic outlook with political context, not merely translated calendar entries.

Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/news-monthly-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,29 @@ npx tsx scripts/fix-article-navigation.ts

### Step 4: Translate, Validate & Verify Analysis Quality

Run validation and HTMLHint before creating PR:
```bash
bash scripts/validate-news-generation.sh
VALIDATION_EXIT=$?
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ News generation validation failed. Fix the reported issues before creating a PR."
exit "$VALIDATION_EXIT"
fi

Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VALIDATION_EXIT is captured but never used in this snippet. As written, validation errors from validate-news-generation.sh won’t stop PR creation guidance. Either remove the unused variable or add a check that exits (or otherwise clearly gates) when VALIDATION_EXIT is non-zero.

Suggested change
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ News generation validation failed. Please fix the reported issues before running HTMLHint or creating a PR."
exit "$VALIDATION_EXIT"
fi

Copilot uses AI. Check for mistakes.
# HTMLHint validation with auto-fix for common nesting errors
NEWS_FILES=$(find news -maxdepth 1 -name '*-*.html' | wc -l)
if [ "$NEWS_FILES" -gt 0 ]; then
if ! npx htmlhint "news/*-*.html" 2>/dev/null; then
echo "⚠️ HTML validation errors found, attempting auto-fix..."
npx tsx scripts/article-quality-enhancer.ts --fix
if ! npx htmlhint "news/*-*.html"; then
echo "❌ HTML validation still failing after auto-fix. Please fix remaining issues manually before creating PR."
exit 1
fi
fi
fi
```

**CRITICAL: Each article MUST contain real analysis, not just a list of translated document links.**
Every generated article must include thematic analysis grouping documents by type and policy area, interpretive commentary on what the month's activity reveals about political dynamics, and key takeaways.

Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/news-motions.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,29 @@ npx tsx scripts/fix-article-navigation.ts

### Step 4: Translate, Validate & Verify Analysis Quality

Run validation and HTMLHint before creating PR:
```bash
bash scripts/validate-news-generation.sh
VALIDATION_EXIT=$?
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ News generation validation failed. Fix the reported issues before creating a PR."
exit "$VALIDATION_EXIT"
fi

Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VALIDATION_EXIT is captured but never used in this snippet. As written, validation errors from validate-news-generation.sh won’t stop PR creation guidance. Either remove the unused variable or add a check that exits (or otherwise clearly gates) when VALIDATION_EXIT is non-zero.

Suggested change
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ News generation validation failed (exit code $VALIDATION_EXIT). Please fix the reported issues before creating a PR."
exit "$VALIDATION_EXIT"
fi

Copilot uses AI. Check for mistakes.
# HTMLHint validation with auto-fix for common nesting errors
NEWS_FILES=$(find news -maxdepth 1 -name '*-*.html' | wc -l)
if [ "$NEWS_FILES" -gt 0 ]; then
if ! npx htmlhint "news/*-*.html" 2>/dev/null; then
echo "⚠️ HTML validation errors found, attempting auto-fix..."
npx tsx scripts/article-quality-enhancer.ts --fix
if ! npx htmlhint "news/*-*.html"; then
echo "❌ HTML validation errors remain after auto-fix. Please fix them before creating a PR."
exit 1
fi
fi
fi
```

**CRITICAL: Each article MUST contain real analysis, not just a list of translated links.**
Every generated article must include:
- An analytical lede paragraph about opposition strategy and political fault lines (not just a motion count)
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/news-propositions.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,29 @@ npx tsx scripts/fix-article-navigation.ts

### Step 4: Translate, Validate & Verify Analysis Quality

Run validation and HTMLHint before creating PR:
```bash
bash scripts/validate-news-generation.sh
VALIDATION_EXIT=$?
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ News generation validation failed. Fix the reported issues before creating a PR."
exit "$VALIDATION_EXIT"
fi

Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VALIDATION_EXIT is captured but never used in this snippet. As written, validation errors from validate-news-generation.sh won’t stop PR creation guidance. Either remove the unused variable or add a check that exits (or otherwise clearly gates) when VALIDATION_EXIT is non-zero.

Suggested change
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ Validation failed (scripts/validate-news-generation.sh). Please fix the reported issues before running HTMLHint or creating a PR."
exit "$VALIDATION_EXIT"
fi

Copilot uses AI. Check for mistakes.
# HTMLHint validation with auto-fix for common nesting errors
NEWS_FILES=$(find news -maxdepth 1 -name '*-*.html' | wc -l)
if [ "$NEWS_FILES" -gt 0 ]; then
if ! npx htmlhint "news/*-*.html" 2>/dev/null; then
echo "⚠️ HTML validation errors found, attempting auto-fix..."
npx tsx scripts/article-quality-enhancer.ts --fix
if ! npx htmlhint "news/*-*.html"; then
echo "❌ HTML validation failed after auto-fix. Please resolve remaining HTMLHint errors before creating a PR."
exit 1
fi
fi
fi
```

Translate all Swedish content, regenerate indexes, validate, then create PR.

**CRITICAL: Each article MUST contain real analysis, not just a list of translated links.**
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/news-realtime-monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,28 @@ This validation checks:
6. ℹ️ Index files have content (skipped — index files generated at build time)
7. ⚠️ Sitemap news-URL coverage (warning; missing sitemap.xml is OK — generated by prebuild)
8. ⚠️ Language switcher consistency across all 14 languages (warning level)
9. ⚠️ Articles have article-top-nav with back-to-news link (warning level)
10. ⚠️ Articles have back-to-news link in footer (warning level)
11. ⚠️ HTMLHint validation on news articles (warning level; auto-fix attempted)
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documented validation checklist numbering now jumps from 8 to 11, which no longer matches the actual validate-news-generation.sh checks (it has checks 9 and 10 as well). Please update this list to include the missing check numbers/descriptions or renumber so it stays consistent with the script output.

Suggested change
11. ⚠️ HTMLHint validation on news articles (warning level; auto-fix attempted)
9. ⚠️ HTMLHint validation on news articles (warning level; auto-fix attempted)

Copilot uses AI. Check for mistakes.

**Exit code 0** = all checks pass. **Exit code 1** = errors found. Both are recoverable — check elapsed time before deciding.

**HTMLHint Auto-Fix:**
After running `validate-news-generation.sh`, run HTMLHint with auto-fix for any remaining nesting errors:
```bash
NEWS_FILES=$(find news -maxdepth 1 -name '*-*.html' | wc -l)
if [ "$NEWS_FILES" -gt 0 ]; then
if ! npx htmlhint "news/*-*.html" 2>/dev/null; then
echo "⚠️ HTML validation errors found, attempting auto-fix..."
npx tsx scripts/article-quality-enhancer.ts --fix
if ! npx htmlhint "news/*-*.html"; then
echo "❌ HTML validation errors remain after auto-fix. Please fix them before creating a PR."
exit 1
fi
fi
fi
```

If validation shows errors, try to fix them. If elapsed >= 38 minutes, proceed to create PR with available articles.

### Step 6: Create PR (if articles generated)
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/news-week-ahead.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,29 @@ npx tsx scripts/fix-article-navigation.ts

### Step 4: Translate, Validate & Verify Analysis Quality

Run validation and HTMLHint before creating PR:
```bash
bash scripts/validate-news-generation.sh
VALIDATION_EXIT=$?
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ News generation validation failed. Fix the reported issues before creating a PR."
exit "$VALIDATION_EXIT"
fi

Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VALIDATION_EXIT is captured but never used in this snippet. As written, validation errors from validate-news-generation.sh won’t stop PR creation guidance. Either remove the unused variable or add a check that exits (or otherwise clearly gates) when VALIDATION_EXIT is non-zero.

Suggested change
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ Content validation failed. Please fix the issues reported by validate-news-generation.sh before creating a PR."
exit "$VALIDATION_EXIT"
fi

Copilot uses AI. Check for mistakes.
# HTMLHint validation with auto-fix for common nesting errors
NEWS_FILES=$(find news -maxdepth 1 -name '*-*.html' | wc -l)
if [ "$NEWS_FILES" -gt 0 ]; then
if ! npx htmlhint "news/*-*.html" 2>/dev/null; then
echo "⚠️ HTML validation errors found, attempting auto-fix..."
npx tsx scripts/article-quality-enhancer.ts --fix
if ! npx htmlhint "news/*-*.html"; then
echo "❌ HTML validation failed after auto-fix. Please fix remaining HTMLHint errors before creating a PR."
exit 1
fi
fi
fi
```

**CRITICAL: Each article MUST contain real analysis, not just a list of translated event titles.**
Every generated article must include:
- A "Why This Week Matters" context box with political significance analysis
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/news-weekly-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,29 @@ npx tsx scripts/fix-article-navigation.ts

### Step 4: Translate, Validate & Verify Analysis Quality

Run validation and HTMLHint before creating PR:
```bash
bash scripts/validate-news-generation.sh
VALIDATION_EXIT=$?
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VALIDATION_EXIT is captured but never used in this snippet. As written, validation errors from validate-news-generation.sh won’t stop PR creation guidance. Either remove the unused variable or add a check that exits (or otherwise clearly gates) when VALIDATION_EXIT is non-zero.

Suggested change
VALIDATION_EXIT=$?
VALIDATION_EXIT=$?
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ Validation script failed. Please fix the reported issues before creating a PR."
exit "$VALIDATION_EXIT"
fi

Copilot uses AI. Check for mistakes.
if [ "$VALIDATION_EXIT" -ne 0 ]; then
echo "❌ News generation validation failed. Fix the reported issues before creating a PR."
exit "$VALIDATION_EXIT"
fi

# HTMLHint validation with auto-fix for common nesting errors
NEWS_FILES=$(find news -maxdepth 1 -name '*-*.html' | wc -l)
if [ "$NEWS_FILES" -gt 0 ]; then
if ! npx htmlhint "news/*-*.html" 2>/dev/null; then
echo "⚠️ HTML validation errors found, attempting auto-fix..."
npx tsx scripts/article-quality-enhancer.ts --fix
if ! npx htmlhint "news/*-*.html"; then
echo "❌ HTML validation failed after auto-fix. Please fix remaining issues before creating PR."
exit 1
fi
fi
fi
```

**CRITICAL: Each article MUST contain real analysis, not just a list of translated document links.**
Every generated article must include thematic analysis grouping documents by type and policy area, interpretive commentary on what the week's activity reveals about political dynamics, and key takeaways.

Expand Down
75 changes: 75 additions & 0 deletions scripts/article-quality-enhancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,81 @@ export async function batchEnhanceQuality(
return results;
}

/**
* Fix common HTML nesting errors in article content.
*
* Corrects invalid block-level nesting patterns:
* - `<p><ul>` → removes the enclosing `<p>` so the `<ul>` list is not nested inside a `<p>` paragraph
* - `<p><ol>` → removes the enclosing `<p>` so the `<ol>` list is not nested inside a `<p>` paragraph
* - `<p><div>` → removes the enclosing `<p>` so the block-level `<div>` is not nested inside a `<p>` paragraph
* - Orphaned `</p>` immediately after `</ul>` → removed
* - Orphaned `</p>` immediately after `</ol>` → removed
* - Orphaned `</p>` immediately after `</div>` (when wrapped by `<p>`) → removed
*
* @param content - Raw HTML content
* @returns Fixed HTML content
*/
export function fixArticleHtmlNesting(content: string): string {
let fixed = content;

Comment on lines +426 to +442
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a fixHtmlNesting() helper in scripts/article-template/helpers.ts (currently used during article generation). Introducing a second fixHtmlNesting() with different behavior in article-quality-enhancer.ts risks divergence/confusion over which one to use. Consider reusing a shared implementation or renaming this function to make its scope explicit (e.g., enhancer-specific).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0393e7c: renamed fixHtmlNesting in article-quality-enhancer.ts to fixArticleHtmlNesting to make its scope explicit and avoid confusion with the simpler fixHtmlNesting in article-template/helpers.ts.

// Fix <p><ul>: remove the enclosing <p> so the list is not nested inside a paragraph
fixed = fixed.replace(/<p([^>]*)>\s*(<ul[\s>])/g, '$2');

// Fix <p><ol>: remove the enclosing <p> so the ordered list is not nested inside a paragraph
fixed = fixed.replace(/<p([^>]*)>\s*(<ol[\s>])/g, '$2');

// Fix <p><div>: remove enclosing <p> around block-level div
fixed = fixed.replace(/<p([^>]*)>\s*(<div[\s>])/g, '$2');

// Fix orphaned </p> immediately after </ul>
fixed = fixed.replace(/<\/ul>\s*<\/p>/g, '</ul>');

// Fix orphaned </p> immediately after </ol>
fixed = fixed.replace(/<\/ol>\s*<\/p>/g, '</ol>');

// Fix orphaned </p> immediately after </div> that was wrapped in <p>
fixed = fixed.replace(/<\/div>\s*<\/p>/g, '</div>');
Comment on lines +426 to +459
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring lists <p><ul>, <p><div>, and orphaned </p> after </ul>, but the implementation also fixes <p><ol> and orphaned </p> after </ol>/</div>. Please update the comment so it accurately reflects the transformations performed.

Copilot uses AI. Check for mistakes.

return fixed;
}

/**
* Fix HTML nesting errors in a file in-place.
*
* @param filePath - Path to the HTML file to fix
* @returns True if the file was modified
*/
export function fixHtmlNestingInFile(filePath: string): boolean {
if (!fs.existsSync(filePath)) {
return false;
}
const original = fs.readFileSync(filePath, 'utf-8');
const fixed = fixArticleHtmlNesting(original);
if (fixed !== original) {
fs.writeFileSync(filePath, fixed, 'utf-8');
return true;
}
return false;
}

// CLI entry point: support --fix flag to fix HTML nesting in news/*-*.html article files
if (import.meta.url === `file://${process.argv[1]}`) {
if (process.argv.includes('--fix')) {
const globPattern = process.argv[process.argv.indexOf('--fix') + 1];
const targetGlob = (globPattern && !globPattern.startsWith('-')) ? globPattern : 'news/*-*.html';
const { globSync } = await import('glob');
const files: string[] = globSync(targetGlob);
let fixedCount = 0;
for (const file of files) {
if (fixHtmlNestingInFile(file)) {
console.log(`Fixed HTML nesting in: ${file}`);
fixedCount++;
}
}
console.log(`Fixed ${fixedCount} of ${files.length} files.`);
}
}

// Export individual assessment functions for testing
export {
assessAnalyticalDepth,
Expand Down
Loading
Loading