Hey @Rich Matheisen (or anyone :) )
Other things side tracked my for a while (like some marriage type thing) but I finally managed to sit back down today to re-look at this.
Interestingly, I manged to get something working by doing as I did in the video, i.e. reading in a dummy HTML first, then re-reading in the real HTML file. I can loop though the NBSP characters within the give tags and replace them, however the result is just not quite what I intended :(
The problem we are having with the NBSP characters is that the break certain browser views. These NBSP specifically are inside a <CODE>
tag as mentioned, and those tags are with a <PRE>
tag. What I was trying to do was replace the NBSP with a completely normal space - i.e. " ".
$HTML.all.tags('pre') | ForEach-Object{$_.outerHTML = $_.outerHTML -replace ' ', ' '}
Unfortunately, whist ALL NBSP characters are replaced, they are replace with nothing, so effectively removed.
This is what we start with:
<div style="mc-code-lang: Python;" class="codeSnippetBody" data-mc-continue="False" data-mc-line-number-start="1" data-mc-use-line-numbers="False"><pre><code>{<br />  {% <span style="color: #a71d5d; ">if</span> service_config %}<br />    <span style="color: #df5000; ">"action"</span> : <span style="color: #df5000; ">"continue"</span>,<br />    <span style="color: #df5000; ">"result"</span> : {{service_config|pex_to_json}}<br />  {% <span style="color: #a71d5d; ">else</span> %}<br />     <span style="color: #df5000; ">"action"</span> : <span style="color: #df5000; ">"reject"</span>,<br />     <span style="color: #df5000; ">"result"</span> : {}<br />  {% endif %}<br />}</code></pre>
</div>
And after reading in, this is what we get in the outerHTML
property:
outerHTML : <CODE>{<BR> {% <SPAN style="COLOR: #a71d5d">if</SPAN> service_config %}<BR> <SPAN style="COLOR: #df5000">"action"</SPAN> : <SPAN style="COLOR:
#df5000">"continue"</SPAN>,<BR> <SPAN style="COLOR: #df5000">"result"</SPAN> : {{service_config|pex_to_json}}<BR> {% <SPAN style="COLOR: #a71d5d">else</SPAN>
%}<BR> <SPAN style="COLOR: #df5000">"action"</SPAN> : <SPAN style="COLOR: #df5000">"reject"</SPAN>,<BR> <SPAN style="COLOR:
#df5000">"result"</SPAN> : {}<BR> {% endif %}<BR>}</CODE>
OK so far. But after parsing and writing back out to HTML, we end up with:
<DIV class=codeSnippetBody style="mc-code-lang: Python" data-mc-use-line-numbers="False" data-mc-line-number-start="1" data-mc-continue="False"><PRE><CODE>{<BR>{% <SPAN style="COLOR: #a71d5d">if</SPAN> service_config %}<BR><SPAN style="COLOR: #df5000">"action"</SPAN> : <SPAN style="COLOR: #df5000">"continue"</SPAN>,<BR><SPAN style="COLOR: #df5000">"result"</SPAN> : {{service_config|pex_to_json}}<BR>{% <SPAN style="COLOR: #a71d5d">else</SPAN> %}<BR><SPAN style="COLOR: #df5000">"action"</SPAN> : <SPAN style="COLOR: #df5000">"reject"</SPAN>,<BR><SPAN style="COLOR: #df5000">"result"</SPAN> : {}<BR>{% endif %}<BR>}</CODE></PRE></DIV>
This doesn't work as all text is left justified
However, If the HTML file is manually edited, so that simple spaces are inserted where the NBSP characters used to be, everything works as it should do. No browser view are broken and all is good.
<DIV class=codeSnippetBody style="mc-code-lang: Python" data-mc-use-line-numbers="False" data-mc-line-number-start="1" data-mc-continue="False"><PRE><CODE>{<BR> {% <SPAN style="COLOR: #a71d5d">if</SPAN> service_config %}<BR> <SPAN style="COLOR: #df5000">"action"</SPAN> : <SPAN style="COLOR: #df5000">"continue"</SPAN>,<BR> <SPAN style="COLOR: #df5000">"result"</SPAN> : {{service_config|pex_to_json}}<BR> {% <SPAN style="COLOR: #a71d5d">else</SPAN> %}<BR> <SPAN style="COLOR: #df5000">"action"</SPAN> : <SPAN style="COLOR: #df5000">"reject"</SPAN>,<BR> <SPAN style="COLOR: #df5000">"result"</SPAN> : {}<BR> {% endif %}<BR>}</CODE></PRE></DIV>
So, whilst over the oddity in the way HTML ComObject works, I can get my read around simply replacing NBSP with ' '.