# Code Blocks 01

Code Blocks 01 on Evotec with practical examples, usage guidance, and reusable project workflows.

Project

PSWriteHTML

Generate HTML reports, dashboards, and emails from PowerShell without writing HTML, CSS, or JavaScript.

[View on GitHub](https://github.com/EvotecIT/PSWriteHTML) [Visit Website](#) [Releases](https://github.com/EvotecIT/PSWriteHTML/releases/tag/v1.41.0) [Changelog](#) [Get package](https://www.powershellgallery.com/packages/PSWriteHTML)

Stars**1025**

Forks**115**

Open issues**0**

PowerShell Gallery downloads**7576901**

Release**v1.45.0**

Language: PowerShell Updated: 2026-11-19

Curated Examples

An example script from the PSWriteHTML repository.

- Source repository: [https://github.com/EvotecIT/PSWriteHTML](https://github.com/EvotecIT/PSWriteHTML)
- Example group: `Example06-CodeBlocks`

```powershell
Import-Module .\PSWriteHTML.psd1 -Force

$CodeBlock = @"
New-HTML {
    New-HTMLTable -DataTable `$Test
} -ShowHTML
"@
$CodeBlockJS = @"
// Takes a data URI and returns the Data URI corresponding to the resized image at the wanted size.
function resizedataURL(datas, wantedWidth, wantedHeight) {
    // We create an image to receive the Data URI
    var img = document.createElement("img");

    // When the event "onload" is triggered we can resize the image.
    img.onload = function () {
        // We create a canvas and get its context.
        var canvas = document.createElement("canvas");
        var ctx = canvas.getContext("2d");

        // We set the dimensions at the wanted size.
        canvas.width = wantedWidth;
        canvas.height = wantedHeight;

        // We resize the image with the canvas method drawImage();
        ctx.drawImage(this, 0, 0, wantedWidth, wantedHeight);

        var dataURI = canvas.toDataURL();

        /////////////////////////////////////////
        // Use and treat your Data URI here !! //
        /////////////////////////////////////////
    };

    // We put the Data URI in the image's src attribute
    img.src = datas;
}
// Use it like that : resizedataURL('yourDataURIHere', 50, 50);
"@

$CodeBlocksXML = @'
<!--?xml version="1.0" encoding="UTF-8"?-->
<building name="GlobalDynamics Main Building"
    core:id="0xFA8A91C6617DFA1B" core:uid="0898213-123123123-1230898123" xmlns:core="http://www.xmlnamespace.tld">
  <core:group core:level="2">
    <room number="123">Conference Room A</room>
    <room number="124">Conference Room B</room>
    <room number="125">Conference Room C</room>
    <room number="126">Conference Room D</room>
  </core:group>
  <core:group core:level="2">
    <room number="17">John's Office</room>
            <room number="19">Eric's Office</room>
  </core:group>
  <core:group core:level="1">
    <room number="091">Mainframe Housing A</room>
    <room number="092">Mainframe Housing B</room>
    <room number="090">Mainframe Power Supply Station</room>
    <room number="089">Mainframe Backup Power Supply Station</room>
  </core:group>
  <core:group core:level="8">
    <room number="1717" role="cto">CTO Office</room>
    <room number="1819" role="ceo">CEO Office</room>
    <room number="1820" role="cfo">
      <x_room label="k89121">Lab01</x_room>
    </room>
  </core:group>
</building>
'@

New-HTML -Online -FilePath "$PSScriptRoot\CodeBlocks02.html" -ShowHTML {
    New-HTMLTab -TabName 'Coding' {
        New-HTMLSection -HeaderText 'This shows PowerShell Language' {
            New-HTMLCodeBlock -Code $CodeBlock -Style 'PowerShell' -Group 'Test123' -Title 'PowerShell Code 1' -Theme godzilla -Highlight '2-5, 13'
            New-HTMLCodeBlock -Code $CodeBlock -Style 'PowerShell' -Group 'Test123' -Title 'PowerShell Code 2'
        }
        New-HTMLSection -HeaderText 'This shows PowerShell Language' {
            New-HTMLCodeBlock -Code $CodeBlockJS -Style 'JavaScript' -Theme enlighter -Highlight '2, 5'
        }
        New-HTMLSection -HeaderText 'XML Language' {
            New-HTMLCodeBlock -Code $CodeBlocksXML -Style 'xml' -Highlight '12, 19'
        }
        New-HTMLSection -HeaderText 'XML Language' {
            New-HTMLCodeBlock -Code $CodeBlocksXML -Style raw -Highlight '12, 19'
        }
    }
}
```

<!-- PowerForge markdown artifact sha256:AA1509C61066C1F07619AF0345CA9FE58EE82EF96E7E7EF711695F4929A74157 -->
