I believe the problem is with your use of sanitize_text_field
(line 668 in your pastebin), which will strip markup. Proof of concept:
$str="<p>Howdy Ho!</p>";
echo $str;
echo sanitize_text_field($str);
You will need to use some other function to clean the data… possibly wp_kses