Hi everyone,
I’m having an issue with code blocks in Obsidian not copying correctly to other applications (PowerShell ISE, cmd). When I copy PowerShell code from a fenced block (using ```powershell)
Example:
Original in notepad:
$desktopPath = [Environment]::GetFolderPath('Desktop')
$currentDate = Get-Date -Format "yyyy-MM-dd"
$outputPath = Join-Path -Path $desktopPath -ChildPath "g_$currentDate.csv"
Get-ChildItem -Path "F:\" -Recurse -File |
Select-Object @{Name="FullPath"; Expression={$_.FullName}},
@{Name="Drive"; Expression={$_.FullName.Split('\')[0]}},
@{Name="Directory"; Expression={$_.DirectoryName}},
@{Name="ParentFolder"; Expression={Split-Path $_.DirectoryName -Leaf}},
@{Name="FileName"; Expression={$_.Name}},
Length,
@{Name="SizeMB"; Expression={[math]::Round($_.Length / 1MB, 2)}} |
Export-Csv -Path $outputPath -NoTypeInformation -Encoding UTF8 -Delimiter "`t" -UseQuotes AsNeeded -Force
Write-Host "File saved: $outputPath" -ForegroundColor Green
Example:
Original in Obsidian:
```powershell
$desktopPath = [Environment]::GetFolderPath('Desktop')
$currentDate = Get-Date -Format "yyyy-MM-dd"
$outputPath = Join-Path -Path $desktopPath -ChildPath "g_$currentDate.csv"
Get-ChildItem -Path "F:\" -Recurse -File |
Select-Object @{Name="FullPath"; Expression={$_.FullName}},
@{Name="Drive"; Expression={$_.FullName.Split('\')[0]}},
@{Name="Directory"; Expression={$_.DirectoryName}},
@{Name="ParentFolder"; Expression={Split-Path $_.DirectoryName -Leaf}},
@{Name="FileName"; Expression={$_.Name}},
Length,
@{Name="SizeMB"; Expression={[math]::Round($_.Length / 1MB, 2)}} |
Export-Csv -Path $outputPath -NoTypeInformation -Encoding UTF8 -Delimiter "`t" -UseQuotes AsNeeded -Force
Write-Host "File saved: $outputPath" -ForegroundColor Green
```
Pasted result (in notepad):
$desktopPath = [Environment]::GetFolderPath('Desktop')
$currentDate = Get-Date -Format "yyyy-MM-dd"
$outputPath = Join-Path -Path $desktopPath -ChildPath "g_$currentDate.csv"
Get-ChildItem -Path "F:\" -Recurse -File |
Select-Object @{Name="FullPath"; Expression={$_.FullName}},
@{Name="Drive"; Expression={$_.FullName.Split('\')[0]}},
@{Name="Directory"; Expression={$_.DirectoryName}},
@{Name="ParentFolder"; Expression={Split-Path $_.DirectoryName -Leaf}},
@{Name="FileName"; Expression={$_.Name}},
Length,
@{Name="SizeMB"; Expression={[math]::Round($_.Length / 1MB, 2)}} |
Export-Csv -Path $outputPath -NoTypeInformation -Encoding UTF8 -Delimiter "`t" -UseQuotes AsNeeded -Force
Write-Host "File saved: $outputPath" -ForegroundColor Green
Has anyone encountered this? Are there plugin settings or workarounds that preserve exact formatting during copy/paste?