Display WordPress the_content() via data attributes

All you have to do is to escape it correctly.

In your code you escape the excerpt using esc_html, but you put it in the attribute – so it isn’t secure and it can break your site.

You should use esc_attr to escape attributes. Then you can put content too:

data-content="<?php echo esc_attr( get_the_content() ); ?>"