- <#*,:
- @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>
- #>
- $re1 = [regex]'(?s)(?<o><div class="lg-row">)(?<body>(?><!--.*?-->|(?<o><div[^>]*>)|(?<-o></div>)|.)*?)(?<-o></div>)(?(o)(?!))'
- $re2 = [regex]'(?s)(?<o><div class="lg">)(?<body>(?><!--.*?-->|(?<o><div[^>]*>)|(?<-o></div>)|.)*?)(?<-o></div>)(?(o)(?!))'
- $re3 = [regex]'(?s)(?<o><div class="calibre3">)(?<body>(?><!--.*?-->|(?<o><div[^>]*>)|(?<-o></div>)|.)*?)(?<-o></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)(?<o><div id="body" class="calibre3">)(?>\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>)|.)*?)(?<-o></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>'
-
- 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)
- # $text = $text -replace '<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>', @'
- # <p class="lg-cell">${1}${2}</span></p>
- # <p class="tras">${3}</p>
- # '@
- $text = $re1.Replace($text, '${body}')
- $text = $re2.Replace($text, '${body}')
- $text = $re3.Replace($text, '${body}')
- $text = $re4.Replace($text, @'
- <p class="lg-cell">${1}${2}</span></p>
- <p class="tras">${3}</p>
- '@)
- $text = $re5.Replace($text, @'
- <p class="juan">${1}${2}</span></p>
- <p class="tras">${3}</p>
- ${body}
- '@)
- $text = $re6.Replace($text, '</span></p><p class="tras">${1}</p>')
- $text = $re7.Replace($text, '</p><p class="tras">${1}</p>')
- [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 {}
- }
复制代码
|