yii\apidoc\helpers\ApiMarkdown::process PHP Method

process() public static method

Converts markdown into HTML
public static process ( string $content, yii\apidoc\models\TypeDoc $context = null, boolean $paragraph = false ) : string
$content string
$context yii\apidoc\models\TypeDoc
$paragraph boolean
return string
    public static function process($content, $context = null, $paragraph = false)
    {
        if (!isset(Markdown::$flavors['api'])) {
            Markdown::$flavors['api'] = new static();
        }
        if (is_string($context)) {
            $context = static::$renderer->apiContext->getType($context);
        }
        Markdown::$flavors['api']->renderingContext = $context;
        if ($paragraph) {
            return Markdown::processParagraph($content, 'api');
        } else {
            return Markdown::process($content, 'api');
        }
    }

Usage Example

Example #1
0
 /**
  * Renders a given [[Context]].
  *
  * @param Controller $controller the apidoc controller instance. Can be used to control output.
  */
 public function render($files, $targetDir)
 {
     $this->_targetDir = $targetDir;
     $fileCount = count($files) + 1;
     if ($this->controller !== null) {
         Console::startProgress(0, $fileCount, 'Rendering markdown files: ', false);
     }
     $done = 0;
     $fileData = [];
     $headlines = [];
     foreach ($files as $file) {
         $fileData[$file] = file_get_contents($file);
         if (basename($file) == 'index.md') {
             continue;
             // to not add index file to nav
         }
         if (preg_match("/^(.*)\n=+/", $fileData[$file], $matches)) {
             $headlines[$file] = $matches[1];
         } else {
             $headlines[$file] = basename($file);
         }
     }
     foreach ($fileData as $file => $content) {
         $output = ApiMarkdown::process($content);
         // TODO generate links to yiiframework.com by default
         $output = $this->fixMarkdownLinks($output);
         if ($this->layout !== false) {
             $params = ['headlines' => $headlines, 'currentFile' => $file, 'content' => $output];
             $output = $this->getView()->renderFile($this->layout, $params, $this);
         }
         $fileName = $this->generateGuideFileName($file);
         file_put_contents($targetDir . '/' . $fileName, $output);
         if ($this->controller !== null) {
             Console::updateProgress(++$done, $fileCount);
         }
     }
     if ($this->controller !== null) {
         Console::updateProgress(++$done, $fileCount);
         Console::endProgress(true);
         $this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
     }
 }
All Usage Examples Of yii\apidoc\helpers\ApiMarkdown::process