Example #1
0
 /**
  * It highlights the given code using the given programming language syntax
  * and decorates the result with the Twig template associated with the
  * code fragments.
  *
  * @param string $code     The source code to highlight and decorate
  * @param string $language The programming language associated with the code
  * @param Application $app The application object needed to highlight and decorate
  *
  * @return string The resulting code after the highlight and rendering process
  */
 public function highlightAndDecorateCode($code, $language, Application $app)
 {
     if ($app->edition('highlight_code')) {
         // highlight code if the edition wants to
         $code = $app->highlight($code, $language);
     } else {
         // escape code to show it instead of interpreting it
         // yaml-style comments could be interpreted as Markdown headings
         // replace any starting # character by its HTML entity (#)
         $code = '<pre>' . preg_replace('/^# (.*)/', "&#35; \$1", htmlspecialchars($code)) . '</pre>';
     }
     $code = $app->render('code.twig', array('item' => array('content' => $code, 'language' => $language, 'number' => '', 'slug' => '')));
     return $code;
 }