本帖最后由 flashercs 于 2024-11-4 21:58 编辑
- <#*,:
- @echo off
- cd /d "%~dp0"
- set "batchfile=%~f0"
- Powershell -ExecutionPolicy Bypass -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create([IO.File]::ReadAllText($env:batchfile,[Text.Encoding]::GetEncoding(0) )) )"
- pause
- exit /b
- #>
- # <p><span class="text_1">..............</span></p>如果行首算起大于624个字符,段落后</span></p>改为★</span></p>
- $re = [regex]'(?s)(<p(?>[^>]*)>)(.*?)(</p>)'
- $evaluator = [System.Text.RegularExpressions.MatchEvaluator] {
- param([System.Text.RegularExpressions.Match]$m)
- if (($m.Groups[2].Value -replace '<[^>]*>').Length -gt 600) {
- # 除了代码,纯粹汉字和标点符号是超过600个。
- $m.Groups[1].Value + $m.Groups[2].Value + '★' + $m.Groups[3].Value
- } else {
- $m.Value
- }
- }
- Get-ChildItem -Path '.\*\OEBPS\Text\*.xhtml' | Where-Object { $_ -is [IO.FileInfo] } | ForEach-Object {
- $_ | Resolve-Path -Relative
- $text = [IO.File]::ReadAllText($_.FullName)
- $text = $re.Replace($text, $evaluator)
- [IO.File]::WriteAllText($_.FullName, $text)
- }
复制代码
|