Sitecore PowerShell Script to fix HTML in Rich Text Fields


Today I am going to share a PowerShell script that can be used to fix Subscript or Superscript text in Rich Text Fields in Sitecore.

In my recent project, I got a requirement to fix the Register Trademark logo which is appearing as normal text instead of Superscript. Since the count of those items is large I prepared a PowerShell script to fix them all in one go.

You can also use this PowerShell script for different purposes like replacing any character with other, appending any tag for a specific keyword, etc.

$rootId = "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
# Get only the immediate children
$items = @((Get-ChildItem -Path "master:" -ID $rootId))
foreach ($item in $items) {
    $html = $item.Text
    $html = [System.Web.HttpUtility]::HtmlDecode($html)
    Write-Output $html
    if ([String]::IsNullOrEmpty($html))
    { continue }
    $newText = $html.Replace("®", "<sup>&reg;</sup>")
    $item.Text = $newText
}

PowerShell scripts are useful as they are development accelerators that increase productivity and also decrease the time required to deliver a solution.




References


Chirag Goel

I am a developer, likes to work on different future technologies.

Post a Comment (0)
Previous Post Next Post