Whisk sugar, cornstarch, and salt together in a medium saucepan.
Add chocolate to sugar mixture and set aside.
Whisk milk and egg yolks in a small bowl until combined.
Gradually add milk mixture to the sugar mixture in the saucepan and whisk to combine.
Heat the saucepan over medium-low heat.
Bring to a boil, whisking constantly.
Cook pudding until thickened, making scrape the bottom and corners of the pan, about 1 minute.
Remove pan from heat.
Whisk in butter and vanilla extract.
Divide pudding between 4 ramekins. Let the pudding cool for about 10-15 minutes.
Press a piece of plastic wrap to the surface of the pudding, and chill for about 1-2 hours before serving.
Top with dollops of sweetened whipped cream and chocolate shavings, if using.
