mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-10 21:06:15 -08:00
feat: add build:test script and improve documentation code blocks
- Added a new script `build:test` to generate test cases from documentation code examples. - Enhanced documentation files by ensuring proper code block formatting and adding missing closing backticks. - Updated various markdown files to include new code blocks and fixed formatting issues.
This commit is contained in:
1 parent
5cc8d14454
commit
7bfee6c6dc
17 files changed
+4857
-19
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { glob } from 'glob'
|
||||
|
||||
const docsDir = path.resolve('packages/artplayer-vitepress/docs')
|
||||
|
||||
function fixMarkdownFile(filePath) {
|
||||
const content = fs.readFileSync(filePath, 'utf-8')
|
||||
const lines = content.split('\n')
|
||||
const fixedLines = []
|
||||
let inCodeBlock = false
|
||||
let fixes = 0
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i]
|
||||
|
||||
// Check if entering a code block
|
||||
if (line.startsWith('```') && !inCodeBlock) {
|
||||
inCodeBlock = true
|
||||
fixedLines.push(line)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if properly exiting a code block
|
||||
if (line.startsWith('```') && inCodeBlock) {
|
||||
inCodeBlock = false
|
||||
fixedLines.push(line)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if we hit a heading while still in a code block (missing ```)
|
||||
if (inCodeBlock && line.startsWith('## ')) {
|
||||
// Add the missing closing ```
|
||||
fixedLines.push('```')
|
||||
fixedLines.push('')
|
||||
inCodeBlock = false
|
||||
fixes++
|
||||
}
|
||||
|
||||
// Check if we hit ::: (admonition) while still in a code block
|
||||
if (inCodeBlock && line.startsWith(':::')) {
|
||||
fixedLines.push('```')
|
||||
fixedLines.push('')
|
||||
inCodeBlock = false
|
||||
fixes++
|
||||
}
|
||||
|
||||
fixedLines.push(line)
|
||||
}
|
||||
|
||||
// If file ended while still in code block
|
||||
if (inCodeBlock) {
|
||||
fixedLines.push('```')
|
||||
fixes++
|
||||
}
|
||||
|
||||
if (fixes > 0) {
|
||||
fs.writeFileSync(filePath, fixedLines.join('\n'))
|
||||
console.log(`✅ Fixed ${fixes} code blocks in ${path.relative(docsDir, filePath)}`)
|
||||
}
|
||||
|
||||
return fixes
|
||||
}
|
||||
|
||||
// Find all markdown files
|
||||
const files = glob.sync('**/*.md', { cwd: docsDir, absolute: true })
|
||||
|
||||
let totalFixes = 0
|
||||
for (const file of files) {
|
||||
totalFixes += fixMarkdownFile(file)
|
||||
}
|
||||
|
||||
console.log(`\n✨ Total: Fixed ${totalFixes} code blocks in ${files.length} files`)
|
||||
Reference in new issue
Block a user