Alembic/buildtools/buildreadme.php

42 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2021-07-14 14:42:46 +02:00
<?php
2021-07-14 15:14:07 +02:00
$source=file_get_contents("Alembic.tex");
2021-07-14 14:42:46 +02:00
$matches=[];
preg_match_all('/
(?| # two alternatives whose group numbers both begin at 1
\\\\chapter # match the command
(?|\{([^}]*)\}|\[([^]]*)\])
# and a parameter in group 1
| # OR
\G # anchor the match to the end of the last match
(?|\{([^}]*)\}|\[([^]]*)\])
# and match a parameter in group 1
)
/x',
$source,
$matches
);
$poems=$matches[1];
$endB="";
2021-07-14 15:14:07 +02:00
$f=file("README.md");
2021-07-14 14:42:46 +02:00
$writeStuff=true;
2021-08-11 11:46:28 +02:00
2021-07-14 14:42:46 +02:00
foreach($f as $line){
if(trim($line)=="<!-- BEGIN POEMLIST -->"){
$writeStuff=false;
$endB.=$line;
2021-08-11 11:46:28 +02:00
$i=1;
foreach($poems as $p){
$endB.="* ".$i." ".$p."\n";
$i++;
}
2021-07-14 14:42:46 +02:00
}
if($writeStuff) $endB.=$line;
if(trim($line)=="<!-- END POEMLIST -->"){
$endB.=$line;
$writeStuff=true;
}
}
2021-07-14 15:15:48 +02:00
file_put_contents("README.md",$endB);
2021-07-14 14:42:46 +02:00