File size: 2,106 Bytes
ebd182e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
$markdownPath = "C:\Users\hp\.gemini\antigravity\brain\04f3e1c4-7b81-497c-a7c5-5d0513033dfa\project_report.md"
$wordPath = "C:\Users\hp\.gemini\antigravity\brain\04f3e1c4-7b81-497c-a7c5-5d0513033dfa\VoiceVerse_AI_Project_Report.docx"
if (-not (Test-Path $markdownPath)) {
Write-Error "Markdown file not found at $markdownPath"
exit 1
}
$content = Get-Content -Path $markdownPath -Raw
# Create Word Object
try {
$word = New-Object -ComObject Word.Application
$word.Visible = $false
$doc = $word.Documents.Add()
$selection = $word.Selection
# Basic Markdown Parsing (Simplified)
$lines = $content -split "`r?`n"
foreach ($line in $lines) {
if ($line -match "^# (.*)") {
$selection.Style = "Title"
$selection.TypeText($matches[1])
$selection.TypeParagraph()
} elseif ($line -match "^## (.*)") {
$selection.Style = "Heading 1"
$selection.TypeText($matches[1])
$selection.TypeParagraph()
} elseif ($line -match "^### (.*)") {
$selection.Style = "Heading 2"
$selection.TypeText($matches[1])
$selection.TypeParagraph()
} elseif ($line -match "^---") {
# Skip horizontal rules or add a page break?
# For now just skip
} elseif ($line -match "^\|") {
# Table handling is complex, for now just TypeText
$selection.Style = "Normal"
$selection.TypeText($line)
$selection.TypeParagraph()
} else {
$selection.Style = "Normal"
# Remove bold/italic markers for cleaner look
$cleanLine = $line -replace "\*\*", "" -replace "\*", ""
$selection.TypeText($cleanLine)
$selection.TypeParagraph()
}
}
$doc.SaveAs([ref]$wordPath)
$doc.Close()
$word.Quit()
Write-Host "Word document created successfully at $wordPath"
} catch {
Write-Error "Failed to create Word document: $_"
if ($word) { $word.Quit() }
}
|