2017-11-24 7 views
0

Alles, was ich brauche, ist kopieren Sie Text als text/html in die Zwischenablage von CLI und fügen Sie es dann in Rich Text Editor auf utf-8 Webseite. Aber es gibt Codierprobleme mit cyrillischen Zeichen - trotz Verwendung von chcp, um die Codierung zu ändern. DieseKodierungsprobleme mit Cmd oder Power Shell oder beiden

ist, wie PS1-Datei aussieht (Natürlich Datei selbst zu UTF-8-Codierung haben):

chcp 65001 
$args[0] | Set-Clipboard -AsHtml 

Run-Skript von cmd mit chcp 65001(UTF-8) und kyrillisch Parameter:

chcp 65001 
powershell C:\Users\admin\go.ps1 "КИРИЛЛИЦА IS CYRILLIC" 

Befehl Ausgang:

enter image description here

Das Problem ist hier, wenn ich in Rich-Text-Editor einfügen ich:

enter image description here

+0

Warum Sie verwenden '-AsHtml'? – TheIncorrigible1

+0

Weil ich Text als "Text/HTML" -Format kopieren und dann in Rich-Text-Box einfügen muss –

+0

Warum? Das ist die Ursache für dein Problem. – TheIncorrigible1

Antwort

0

BUG: Set-Clipboard -AsHtml puts invalid CF_HTML on clipboard with non-ASCII text

Blake Coverett ‚s Problem zu umgehen, für alle anderen von diesem gebissen:

Function StringToEntities ($aux) { 
    ## https://windowsserver.uservoice.com/users/307215574-blake-coverett 
    ($aux.ToCharArray() | ForEach-Object { 
     $codePoint = [int]$_ 
     if ($codePoint -ge 127) { 
      "&#$codePoint;" 
     } else { 
      $_ 
     } 
    }) -join '' 
} 

'buggy' 
$args[0] | Set-Clipboard -AsHtml 
Get-Clipboard -TextFormatType Html | Where-Object {$_ -match 'body'} 
'workaround' 
StringToEntities($args[0]) | Set-Clipboard -AsHtml 
Get-Clipboard -TextFormatType Html | Where-Object {$_ -match 'body'} 

Beispielausgabe (nur zum Debuggen; zeigt, dass cmd Codepage spielt keine Rolle):

==> chcp 
Active code page: 852 

==> powershell -noprofile D:\PShell\SO\47474346.ps1 "'КИРИЛЛИЦА IS CYRILLIC, ελληνικά is Greek'" 

buggy 
<html><body><!--StartFragment-->????????? IS CYRILLIC, ???????? is Greek<!--EndFragment--></body 
></html> 
workaround 
<html><body><!--StartFragment-->&#1050;&#1048;&#1056;&#1048;&#1051;&#1051;&#1048;&#1062;&#1040; 
IS CYRILLIC, &#949;&#955;&#955;&#951;&#957;&#953;&#954;&#940; is Greek<!--EndFragment--></body>< 
/html> 

==> 

bei https://html-online.com/editor/ Geprüft:

pasted HTML clipboard

Verwandte Themen