本帖最后由 flashercs 于 2025-1-10 22:28 编辑
- <#*,:
- @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
- #>
- # 修改xhtml颜色
- <#
- <div class="lg-cell1"> <p class="lg-cell1">
- <div class="lg-cell"> <p class="lg-cell">
- <div class="lg-cell2"> <p class="lg-cell2">
- <div class="lg-row">
- <div class="lg">
- <!-- end of lg-row -->
- <!-- end of lg -->
- <div class="calibre3">
- </div>
- <p class="lg-cell"><span class="text_" default-translate="no">直接替换为<p class="lg-cell">
- #>
- $re1 = [regex]'(?s)<div(?=[^>]* class="lg-row")[^>]*>(?<body>(?><!--.*?-->|(?<o><div[^>]*>)|(?<-o></div>)|.)*?)</div>(?(o)(?!))'
- $re2 = [regex]'(?s)<div(?=[^>]* class="lg")[^>]*>(?<body>(?><!--.*?-->|(?<o><div[^>]*>)|(?<-o></div>)|.)*?)</div>(?(o)(?!))'
- $re3 = [regex]'(?s)<div(?=[^>]* class="calibre3")[^>]*>(?<body>(?><!--.*?-->|(?<o><div[^>]*>)|(?<-o></div>)|.)*?)</div>(?(o)(?!))'
- $re4 = [regex]'<div(?=[^>]* class="lg-cell[^"]*")[^>]*>(<span(?>[^>]*)>)((?>[^<>]*))<span data-immersive-translate-translation-element-mark="1" lang="zh-CN"><br class="calibre3"/><span class="notranslate3" data-immersive-translate-translation-element-mark="1"><span class="notranslate4" data-immersive-translate-translation-element-mark="1">((?>[^<>]*))</span></span></span></span></div>'
- $re5 = [regex]'(?s)<div(?=[^>]* class="calibre3")(?=[^>]* id="body")[^>]*>(?>\s*)(<span(?>[^>]*)>)((?>[^<>]*))<span data-immersive-translate-translation-element-mark="1" lang="zh-CN"><br class="calibre3"/><span class="notranslate3" data-immersive-translate-translation-element-mark="1"><span class="notranslate4" data-immersive-translate-translation-element-mark="1">((?>[^<>]*))</span></span></span></span>(?<body>(?><!--.*?-->|(?<o><div[^>]*>)|(?<-o></div>)|.)*?)</div>(?(o)(?!))'
- $re6 = [regex]'<span data-immersive-translate-translation-element-mark="1" lang="zh-CN"><br class="calibre3"/><span class="notranslate3" data-immersive-translate-translation-element-mark="1"><span class="notranslate4" data-immersive-translate-translation-element-mark="1">((?>[^<>]*))</span></span></span></span></p>'
- $re7 = [regex]'<span data-immersive-translate-translation-element-mark="1" lang="zh-CN"><br class="calibre3"/><span class="notranslate3" data-immersive-translate-translation-element-mark="1"><span class="notranslate4" data-immersive-translate-translation-element-mark="1">((?>[^<>]*))</span></span></span></p>'
- $re8 = [regex]'(?s)(<p(?=[^>]* class="lg-cell")[^>]*>)(?<body>(?><!--.*?-->|(?<o><p[^>]*>)|(?<-o></p>)|<(?!/?p)[^>]*>|[^<>]+)*)(?(o)(?!))(</p>)'
-
- $evaluator1 = [System.Text.RegularExpressions.MatchEvaluator] {
- param($m)
- $m.Groups[1].Value + ($m.Groups['body'].Value -replace '<[^>]*>') + $m.Groups[2].Value
- }
- Get-ChildItem -Path '.\epub解包后\*' -Filter *.xhtml -Recurse | Where-Object { $_ -is [IO.FileInfo] -and $_.BaseName -match '\d+' } | ForEach-Object {
- try {
- $_ | Resolve-Path -Relative
- $text = [IO.File]::ReadAllText($_.FullName)
- # remove lg-cell
- $text = $re4.Replace($text, @'
- <p class="lg-cell">${1}${2}</span></p>
- <p class="tras">${3}</p>
- '@)
- # remove lg-row
- $text = $re1.Replace($text, '${body}')
- # remove lg
- $text = $re2.Replace($text, '${body}')
- # remove id="body" class="calibre3"
- $text = $re5.Replace($text, @'
- <p class="juan">${1}${2}</span></p>
- <p class="tras">${3}</p>
- ${body}
- '@)
- # remove calibre3
- $text = $re3.Replace($text, '${body}')
- $text = $re6.Replace($text, '</span></p><p class="tras">${1}</p>')
- $text = $re7.Replace($text, '</p><p class="tras">${1}</p>')
- $text = $text.Replace('<!-- end of lg-row -->', '').Replace('<!-- end of lg -->', '')
- $text = $re8.Replace($text, $evaluator1)
- [IO.File]::WriteAllText($_.FullName, $text)
- } finally {
-
- }
- trap {}
- }
-
- Get-ChildItem -Path '.\epub解包后\*' -Filter stylesheet.css -Recurse | Where-Object { $_ -is [IO.FileInfo] } | ForEach-Object {
- try {
- $_ | Resolve-Path -Relative
- $text = [IO.File]::ReadAllText($_.FullName)
- $text = $text -replace '\.(?>lg(-\w*)?)(?>\s*)\{[^}]*\}'
- $text = @"
- $text
- .tras {
- color: #008000;
- display: block;
- margin: 1em 0;
- font-weight: bold;
- }
- .lg-cell {
- color: #0000aa;
- display: block;
- margin: 1em 0
- }
- .lg-cell1 {
- color: #0000aa;
- display: block;
- margin: 1em 0
- }
- "@
- [IO.File]::WriteAllText($_.FullName, $text)
-
- } finally {
-
- }
- trap {}
- }
复制代码
|