1<?php 2 3namespace ComboStrap; 4 5use Doku_Handler; 6 7class Parser 8{ 9 10 11 /** 12 * @param $markup - the markup 13 * @return Doku_Handler - the handler 14 */ 15 public static function parseMarkupToHandler($markup): Doku_Handler 16 { 17 global $ID; 18 $keep = $ID; 19 global $ACT; 20 $keepAct = $ACT; 21 if ($ID === null) { 22 $ID = ExecutionContext::getActualOrCreateFromEnv()->getConfig()->getDefaultContextPath()->getWikiId(); 23 } 24 try { 25 /** 26 * Fragment 27 */ 28 $ACT = ExecutionContext::PREVIEW_ACTION; 29 $modes = p_get_parsermodes(); 30 $handler = new Doku_Handler(); 31 $parser = new \dokuwiki\Parsing\Parser($handler); 32 33 //add modes to parser 34 foreach ($modes as $mode) { 35 $parser->addMode($mode['mode'], $mode['obj']); 36 } 37 $parser->parse($markup); 38 return $handler; 39 } finally { 40 $ID = $keep; 41 $ACT = $keepAct; 42 } 43 } 44} 45