File: parse.php

package info (click to toggle)
node-lodash 2.4.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,024 kB
  • ctags: 1,590
  • sloc: php: 747; sh: 22; makefile: 14
file content (38 lines) | stat: -rw-r--r-- 1,121 bytes parent folder | download
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
36
37
38
<?php

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

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

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

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

  // get package version
  $version = json_decode(file_get_contents('../package.json'))->version;

  // generate Markdown
  $markdown = docdown(array(
    'path'  => '../' . $filePath,
    'title' => '<a href="http://lodash.com/">Lo-Dash</a> <span>v' . $version . '</span>',
    'toc'   => 'categories',
    'url'   => 'https://github.com/lodash/lodash/blob/master/lodash.js'
  ));

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

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