You are here

public function GeshiController::ajax in GeSHi Filter for syntax highlighting 8

Same name and namespace in other branches
  1. 8.2 codesnippetgeshi/src/Controller/GeshiController.php \Drupal\codesnippetgeshi\Controller\GeshiController::ajax()

Process the ajax request to hightlight code.

Parameters

Symfony\Component\HttpFoundation\Request $request: The request from ckeditor plugin.

Return value

Symfony\Component\HttpFoundation\Response The code with hightlight.

1 string reference to 'GeshiController::ajax'
codesnippetgeshi.routing.yml in codesnippetgeshi/codesnippetgeshi.routing.yml
codesnippetgeshi/codesnippetgeshi.routing.yml

File

codesnippetgeshi/src/Controller/GeshiController.php, line 23

Class

GeshiController
Class GeshiController.

Namespace

Drupal\codesnippetgeshi\Controller

Code

public function ajax(Request $request) {
  $params = [];
  $content = $request
    ->getContent();
  if (!empty($content)) {

    // 2nd param to get as array.
    $params = json_decode($content, TRUE);
  }
  $geshi = new \GeSHi($params['html'], $params['lang']);
  $response = new Response();
  $response
    ->setContent($geshi
    ->parse_code());
  return $response;
}