scripts

ConvertTo-SafeEntities.ps1

SYNOPSIS

Encode text as XML/HTML, escaping all characters outside 7-bit ASCII.

SYNTAX

ConvertTo-SafeEntities.ps1 [-InputObject] <String> [-IncludeMarkupChars] [-ProgressAction <ActionPreference>]
 [<CommonParameters>]

DESCRIPTION

EXAMPLES

EXAMPLE 1

"$([char]0xD83D)$([char]0xDCA1) File $([char]0x2192) Save" |ConvertTo-SafeEntities.ps1

💡 File → Save

This shows a UTF-16 surrogate pair, used internally by .NET strings, which is combined into a single entity reference.

EXAMPLE 2

"ETA: $([char]0xBD) hour" |ConvertTo-SafeEntities.ps1

ETA: ½ hour

PARAMETERS

-InputObject

An HTML or XML string that may include emoji or other Unicode characters outside the 7-bit ASCII range.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-IncludeMarkupChars

Indicates that markdown characters should also be escaped.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

System.String of HTML or XML data to encode.

OUTPUTS

System.String of HTML or XML data, encoded.

NOTES

https://docs.microsoft.com/dotnet/api/system.char.issurrogatepair

https://docs.microsoft.com/dotnet/api/system.char.converttoutf32