Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Extract rst formatted documentation blocks from clarion inc/clw files and process using Sphinx
if ($args[0])
# NOTE: Make sure you have the PowerShell Community Extensions installed
Import-Module pscx
function ProcessFile($pSourceFile, $pOutputFile) {
Write-Host "Processing" $pSourceFile
[bool]$foundDocStart = $false
foreach ($line in Get-Content $pSourceFile) {
if ($line.Contains("Omit('!!!Docs!!!')")) {
$foundDocStart = $true
continue # Skip this line though, we will get the next one
elseif ($line.Contains("!!!Docs!!!")) {
$foundDocStart = $false
if ($foundDocStart -eq $false) {
Add-Content $pOutputFile $line
Write-Host "Completed " $pOutputfile
# We assume we are going to process each inc/clw file in the current directory
$srcPath = (join-path -Path $(Get-Location) -ChildPath "_classes")
$dstPath = (join-path -Path $(Get-Location) -ChildPath "_docs\source")
get-childItem $srcPath -Include @("*.inc") -r | foreach-object {
$dstName = [io.path]::GetFileNameWithoutExtension($_.Name)
$dstFile = (Join-Path -Path $dstPath -ChildPath $($dstName + ".rst"))
Remove-Item $dstFile
# -ErrorAction SilentlyContinue
get-childItem $srcPath -Include @("*.inc", "*.clw") -r | Sort -Descending | foreach-object {
Write-Host "Source = " $_.FullName
$dstName = [io.path]::GetFileNameWithoutExtension($_.Name)
$dstFile = (Join-Path -Path $dstPath -ChildPath $($dstName + ".rst"))
Write-Host "Destination = " $dstFile
#Write-Host "Name = " $dstName
ProcessFile $_.FullName $dstFile
$originalPath = Get-Location
cd (join-path -Path $originalPath -ChildPath "_docs")
Invoke-BatchFile make html
cd $originalPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment