kdybyste chtěli vidět kapitoly markdownu v Notepad++ panelu Functions, tak tady jsem si dovolil z vlastní zahrádky .cmd skript (je pak potřeba Windows logout/login):
@@ setlocal
@@ set PS_WRAPPER_PATH=%~f0
@@ set PS_WRAPPER_ARGS=%*
@@ if defined PS_WRAPPER_ARGS set PS_WRAPPER_ARGS=%PS_WRAPPER_ARGS:"="%
@@ PowerShell -sta -NoProfile -Command Invoke-Expression $('$args=@(^&{$args} %PS_WRAPPER_ARGS%);'+[String]::Join([Environment]::NewLine,$((Get-Content '%PS_WRAPPER_PATH%' -Encoding UTF8) -notmatch '^^@@^|^^:'))) & endlocal & exit /b
$ErrorActionPreference = "Stop"
# Explicit assembly loading
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
function Show-Error {
param([string]$Message)
[void][System.Windows.Forms.MessageBox]::Show(
$Message,
"Notepad++ Markdown Function List - Error",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Error
)
}
function Show-Info {
param([string]$Message)
[void][System.Windows.Forms.MessageBox]::Show(
$Message,
"Notepad++ Markdown Function List",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Information
)
}
function Find-NotepadPlusPlus {
# Try registry first (default value on the Notepad++ key holds the install path)
$regPaths = @(
"HKLM:\SOFTWARE\Notepad++",
"HKLM:\SOFTWARE\WOW6432Node\Notepad++",
"HKCU:\SOFTWARE\Notepad++"
)
foreach ($regPath in $regPaths) {
if (Test-Path $regPath) {
try {
$key = Get-Item -Path $regPath -ErrorAction Stop
$installPath = $key.GetValue("")
if ($installPath -and (Test-Path (Join-Path $installPath "notepad++.exe"))) {
return $installPath
}
} catch {}
}
}
# Fall back to common install locations
$commonPaths = @(
"$env:ProgramFiles\Notepad++",
"${env:ProgramFiles(x86)}\Notepad++",
"$env:LOCALAPPDATA\Programs\Notepad++"
)
foreach ($path in $commonPaths) {
if ($path -and (Test-Path (Join-Path $path "notepad++.exe"))) {
return $path
}
}
return $null
}
function Test-NppRunning {
try {
$proc = Get-Process -Name "notepad++" -ErrorAction SilentlyContinue
return ($null -ne $proc)
} catch {
return $false
}
}
try {
# ---- 1. Locate Notepad++ installation ----
$nppPath = Find-NotepadPlusPlus
if (-not $nppPath) {
Show-Error ("Notepad++ installation was not found.`n`n" +
"Checked:`n" +
" - Registry (HKLM/HKCU\SOFTWARE\Notepad++)`n" +
" - $env:ProgramFiles\Notepad++`n" +
" - ${env:ProgramFiles(x86)}\Notepad++`n" +
" - $env:LOCALAPPDATA\Programs\Notepad++`n`n" +
"Please install Notepad++ first, then re-run this script.")
exit 1
}
# ---- 2. Ensure user config folder exists ----
$userConfigPath = Join-Path $env:APPDATA "Notepad++"
if (-not (Test-Path $userConfigPath)) {
Show-Error ("Notepad++ user config folder not found:`n ${userConfigPath}`n`n" +
"Please launch Notepad++ at least once so it creates its config folder, " +
"then re-run this script.")
exit 1
}
$functionListPath = Join-Path $userConfigPath "functionList"
if (-not (Test-Path $functionListPath)) {
[void](New-Item -Path $functionListPath -ItemType Directory -Force)
}
# ---- 3. Write the parser file (udl_markdown.xml) ----
$parserXmlPath = Join-Path $functionListPath "udl_markdown.xml"
$parserXml = @'
<?xml version="1.0" encoding="UTF-8"?>
<NotepadPlus>
<functionList>
<parser id="udl_markdown.xml" displayName="Markdown (preinstalled)" ext="md" commentExpr="(?ms)^\h*\x60{3,}.*?^\h*\x60{3,}">
<function mainExpr="(?-s)^[ \t]*(#{1,6}[ \t].+)$">
<functionName>
<nameExpr expr="(#{1,6}[ \t].+)"/>
</functionName>
</function>
</parser>
</functionList>
</NotepadPlus>
'@
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
[System.IO.File]::WriteAllText($parserXmlPath, $parserXml, $utf8NoBom)
# ---- 4. Create or merge overrideMap.xml ----
$overrideMapPath = Join-Path $functionListPath "overrideMap.xml"
$udlNames = @("Markdown (preinstalled)", "Markdown (preinstalled dark mode)")
$backupPath = $null
$overrideMapHandled = $false
if (Test-Path $overrideMapPath) {
# Back up whatever is there before touching it
$backupPath = "$overrideMapPath.bak"
Copy-Item -Path $overrideMapPath -Destination $backupPath -Force
try {
[xml]$overrideXml = [System.IO.File]::ReadAllText($overrideMapPath)
$npp = $overrideXml.SelectSingleNode("/NotepadPlus")
if ($null -ne $npp) {
$funcList = $npp.SelectSingleNode("functionList")
if ($null -eq $funcList) {
$funcList = $overrideXml.CreateElement("functionList")
[void]$npp.AppendChild($funcList)
}
$assocMap = $funcList.SelectSingleNode("associationMap")
if ($null -eq $assocMap) {
$assocMap = $overrideXml.CreateElement("associationMap")
[void]$funcList.AppendChild($assocMap)
}
foreach ($udlName in $udlNames) {
$existing = $assocMap.SelectSingleNode("association[@userDefinedLangName='$udlName']")
if ($null -ne $existing) {
$existing.SetAttribute("id", "udl_markdown.xml")
} else {
$newAssoc = $overrideXml.CreateElement("association")
$newAssoc.SetAttribute("id", "udl_markdown.xml")
$newAssoc.SetAttribute("userDefinedLangName", $udlName)
[void]$assocMap.AppendChild($newAssoc)
}
}
$overrideXml.Save($overrideMapPath)
$overrideMapHandled = $true
}
} catch {
# Malformed XML - fall through to write a fresh file (backup preserved)
}
}
if (-not $overrideMapHandled) {
$overrideContent = @'
<?xml version="1.0" encoding="UTF-8" ?>
<NotepadPlus>
<functionList>
<associationMap>
<association id="udl_markdown.xml" userDefinedLangName="Markdown (preinstalled)" />
<association id="udl_markdown.xml" userDefinedLangName="Markdown (preinstalled dark mode)" />
</associationMap>
</functionList>
</NotepadPlus>
'@
[System.IO.File]::WriteAllText($overrideMapPath, $overrideContent, $utf8NoBom)
}
# ---- 5. Build confirmation message ----
$nppRunning = Test-NppRunning
$runningMsg = if ($nppRunning) {
"`n`nWARNING: Notepad++ is currently running. Close and restart it for changes to take effect."
} else {
"`n`nStart Notepad++, open a .md file, then: View > Function List"
}
$backupMsg = if ($backupPath) {
"`n`nExisting overrideMap.xml backed up to:`n $backupPath"
} else {
""
}
Show-Info ("Setup complete.`n`n" +
"Notepad++ install: $nppPath`n`n" +
"Files written:`n" +
" - $parserXmlPath`n" +
" - $overrideMapPath" +
$backupMsg +
$runningMsg)
} catch {
Show-Error ("An unexpected error occurred:`n`n" +
"$($_.Exception.Message)`n`n" +
"At: $($_.InvocationInfo.PositionMessage)")
exit 1
}