aboutsummaryrefslogtreecommitdiffstats
path: root/library/markdownify/markdownify_cli.php
blob: b3fffbd5cb71c7ab3abd2723be1b32c7fa8f077d (plain) (blame)
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
#!/usr/bin/php
<?php
require dirname(__FILE__) .'/markdownify_extra.php';

function param($name, $default = false) {
  if (!in_array('--'.$name, $_SERVER['argv']))
    return $default;
  reset($_SERVER['argv']);
  while (each($_SERVER['argv'])) {
    if (current($_SERVER['argv']) == '--'.$name)
      break;
  }
  $value = next($_SERVER['argv']);
  if ($value === false || substr($value, 0, 2) == '--')
    return true;
  else
    return $value;
}


$input = stream_get_contents(STDIN);

$linksAfterEachParagraph = param('links');
$bodyWidth = param('width');
$keepHTML = param('html', true);

if (param('no_extra')) {
  $parser = new Markdownify($linksAfterEachParagraph, $bodyWidth, $keepHTML);
} else {
  $parser = new Markdownify_Extra($linksAfterEachParagraph, $bodyWidth, $keepHTML);
}

echo $parser->parseString($input) ."\n";