Get markup for post without loading into the template

I couldn’t figure out a WordPress way to do this and looking at the WP source, it looks like this probably will never really be possible. However, I was able to get a solution using vanilla PHP by redirecting standard output into a buffer and loading the buffer into a variable.

$listings = new WP_Query(...);
ob_start();
while ( have_posts() ) {
    get_template_part('content', $post->post_type);
}
$markup = ob_get_contents();
ob_end_clean();
return $markup

tech