Since: 2.0
Author: Carsten Brandt (mail@cebe.cc)
Inheritance: extends cebe\markdown\latex\GithubMarkdown, use trait yii\apidoc\helpers\ApiMarkdownTrait
示例#1
0
 /**
  * @inheritDoc
  */
 public function render($files, $targetDir)
 {
     //        $types = array_merge($this->apiContext->classes, $this->apiContext->interfaces, $this->apiContext->traits);
     //
     //        $extTypes = [];
     //        foreach ($this->extensions as $k => $ext) {
     //            $extType = $this->filterTypes($types, $ext);
     //            if (empty($extType)) {
     //                unset($this->extensions[$k]);
     //                continue;
     //            }
     //            $extTypes[$ext] = $extType;
     //        }
     $fileCount = count($files) + 1;
     if ($this->controller !== null) {
         Console::startProgress(0, $fileCount, 'Rendering markdown files: ', false);
     }
     $done = 0;
     $fileData = [];
     $chapters = $this->loadGuideStructure($files);
     foreach ($files as $file) {
         $fileData[basename($file)] = file_get_contents($file);
         //            if (preg_match("/^(.*)\n=+/", $fileData[$file], $matches)) {
         //                $headlines[$file] = $matches[1];
         //            } else {
         //                $headlines[$file] = basename($file);
         //            }
     }
     $md = new ApiMarkdownLaTeX();
     $output = '';
     foreach ($chapters as $chapter) {
         if (isset($chapter['headline'])) {
             $output .= '\\chapter{' . $chapter['headline'] . "}\n";
         }
         foreach ($chapter['content'] as $content) {
             if (isset($fileData[$content['file']])) {
                 $md->labelPrefix = $content['file'] . '#';
                 $output .= '\\label{' . $content['file'] . '}';
                 $output .= $md->parse($fileData[$content['file']]) . "\n\n";
             } else {
                 $output .= '\\newpage';
                 $output .= '\\label{' . $content['file'] . '}';
                 $output .= '\\textbf{Error: not existing file: ' . $content['file'] . '}\\newpage' . "\n";
             }
             if ($this->controller !== null) {
                 Console::updateProgress(++$done, $fileCount);
             }
         }
     }
     file_put_contents($targetDir . '/guide.tex', $output);
     copy(__DIR__ . '/main.tex', $targetDir . '/main.tex');
     copy(__DIR__ . '/title.tex', $targetDir . '/title.tex');
     copy(__DIR__ . '/Makefile', $targetDir . '/Makefile');
     if ($this->controller !== null) {
         Console::updateProgress(++$done, $fileCount);
         Console::endProgress(true);
         $this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
     }
     echo "\nnow run `make` in {$targetDir} (you need pdflatex to compile pdf file)\n\n";
 }
 public function init()
 {
     ApiMarkdown::$renderer = $this;
     ApiMarkdownLaTeX::$renderer = $this;
 }