aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/vendor/benchmark/doc/parse.php
blob: 565b78fbba2e3fd79aceac128d5dc3a34d896e94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

  // cleanup requested filepath
  $file = isset($_GET['f']) ? $_GET['f'] : 'benchmark';
  $file = preg_replace('#(\.*[\/])+#', '', $file);
  $file .= preg_match('/\.[a-z]+$/', $file) ? '' : '.js';

  // output filename
  if (isset($_GET['o'])) {
    $output = $_GET['o'];
  } else if (isset($_SERVER['argv'][1])) {
    $output = $_SERVER['argv'][1];
  } else {
    $output = basename($file);
  }

  /*--------------------------------------------------------------------------*/

  require('../vendor/docdown/docdown.php');

  // generate Markdown
  $markdown = docdown(array(
    'path' => '../' . $file,
    'title' => 'Benchmark.js <sup>v1.0.0</sup>',
    'url'  => 'https://github.com/bestiejs/benchmark.js/blob/master/benchmark.js'
  ));

  // save to a .md file
  file_put_contents($output . '.md', $markdown);

  // print
  header('Content-Type: text/plain;charset=utf-8');
  echo $markdown . PHP_EOL;

?>