Currently, diagrams are drawn with the heap and the stack separately. The heap needs two and <style> HTML elements, and the stack needs one.
The easiest fix here might be to do a pass over the final diagram, and use the randomly-generated IDs from the first set of and <style> elements for the entire combined diagram.