Files
archived-php-langspec/tools/toc.php
Peter Kokot be010b4435 Sync final newlines
- Redundant final newlines trimmed into one
- Missing final newlines added where can be added

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character although not
mandatory.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
2018-10-01 20:21:21 +02:00

34 lines
1007 B
PHP

<?php error_reporting(E_ALL);
require __DIR__ . '/util.php';
$dir = __DIR__ . '/../spec/';
$tocFile = $dir . '00-specification-for-php.md';
$prefix = <<<EOS
<!-- This file is autogenerated, do not edit it manually -->
<!-- Run tools/toc.php instead -->
# Specification for PHP
Facebook has dedicated all copyright to this specification to the public
domain worldwide under the CC0 Public Domain Dedication located at
<http://creativecommons.org/publicdomain/zero/1.0/>. This specification
is distributed without any warranty.
(Initially written in 2014 by Facebook, Inc., July 2014)
**Table of Contents**
EOS;
$output = "";
foreach (spec_files() as $fileName => $path) {
$contents = file_get_contents($path);
foreach (heading_info($contents) as $info) {
$title = $info['title'];
$anchor = $info['anchor'];
$indent = str_repeat(' ', $info['level']);
$output .= "$indent- [$title]($fileName#$anchor)\n";
}
}
file_put_contents($tocFile, "$prefix\n$output");