Hello,
The value of data-content needs to be a WordFragment object serialized and encoded using base64, not a string encoded using base64. This is the most simple example:
$sectionFragment = new Phpdocx\Elements\WordFragment($docx);
$sectionFragment->addWordML('<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:pPr><w:sectPr><w:pgSz w:code="9" w:h="16838" w:orient="portrait" w:w="11906"/><w:pgMar w:bottom="850" w:footer="708" w:gutter="0" w:header="708" w:left="1077" w:right="1077" w:top="850"/><w:cols w:num="1" w:space="708"/><w:docGrid w:linePitch="360"/></w:sectPr></w:pPr></w:p>');
$html = '<phpdocx_wordfragment data-content="'.base64_encode(serialize($sectionFragment)).'" />';
So your twig filter must generate a serialized WordFragment object. You could also generate WordFragments in Drupal and use them in twig.
As it's a serialized object, it can't be generated using phpdocx_wordfragment directly, it needs to be created previously.
Regards.