mandatory = true; $componentOption->shorthelp = "The name of the component."; $params->registerOption( $componentOption ); $targetOption = new ezcConsoleOption( 't', 'target', ezcConsoleInput::TYPE_STRING ); $targetOption->mandatory = true; $targetOption->shorthelp = "The directory to where the generated documentation should be written."; $params->registerOption( $targetOption ); $versionOption = new ezcConsoleOption( 'v', 'version', ezcConsoleInput::TYPE_STRING ); $versionOption->mandatory = true; $versionOption->shorthelp = "The version of the component that should be read. E.g. trunk, 1.0rc1, etc."; $params->registerOption( $versionOption ); $outputFilenameOption = new ezcConsoleOption( 'o', 'outputfilename', ezcConsoleInput::TYPE_STRING ); $outputFilenameOption->shorthelp = "The name of the file to render to."; $params->registerOption( $outputFilenameOption ); $filenameOption = new ezcConsoleOption( 'f', 'filename', ezcConsoleInput::TYPE_STRING ); $filenameOption->mandatory = true; $filenameOption->shorthelp = "The name of the file to render."; $params->registerOption( $filenameOption ); // Process console parameters try { $params->process(); } catch ( ezcConsoleOptionException $e ) { print( $e->getMessage(). "\n" ); print( "\n" ); echo $params->getSynopsis() . "\n"; foreach ( $params->getOptions() as $option ) { echo "-{$option->short}, --{$option->long}\t {$option->shorthelp}\n"; } echo "\n"; exit(); } $component = $params->getOption( 'component' )->value; $filename = $params->getOption( 'filename' )->value; $version = $params->getOption( 'version' )->value; $outputFilename = $params->getOption( 'outputfilename' )->value; $output = getRstOutput( $filename ); if ( $output === false ) { echo " FAILED\n"; exit( 1 ); } $output = removeHeaderFooter( $output ); $output = addNewHeader( $component, $output, $filename ); $output = addExampleLineNumbers( $output ); $output = addLinks( $component, $output, $version ); $output = addNewFooter( $output ); $targetDir = $params->getOption( 'target' )->value; if ( $outputFilename ) { $filename = $outputFilename; } else { $filenameParts = explode( '/', $filename ); $filename = array_splice( $filenameParts, -1 ); $filename = basename( $filename[0], '.txt' ); $filename = "{$component}_$filename.html"; } //echo "$targetDir/{$component}_$filename.html\n"; file_put_contents( "$targetDir/$filename", $output ); echo " OK\n"; function getRstOutput( $fileName ) { exec( "rst2html $fileName", $output, $returnCode ); return $returnCode == 0 ? join( "\n", $output ) : false; } function removeHeaderFooter( $output ) { $output = substr( $output, strpos( $output, '
' ) + 7 ); $output = preg_replace( '@(.+?)<\/pre>@ms', 'callbackAddLineNumbers', $output ); } $lineNr = 0; function callbackAddLineNr( $args ) { global $lineNr; $nrString = str_replace( ' ', ' ', sprintf( '%3d', $lineNr ) ); if ( $lineNr == 0 ) { $val = ''; } else { $val = $nrString . ". {$args[1]}\n"; } $lineNr++; return $val; } function callbackAddLineNumbers( $args ) { global $lineNr; $lineNr = 0; if ( strstr( $args[1], '<?php' ) !== false ) { $listing = ''; $highlighted = highlight_string( html_entity_decode( $args[1] ), true ); $highlighted = preg_replace( '@^'; return $listing; } else { return $args[0]; } }.
$@ms', "", $highlighted ); $highlighted = preg_replace_callback( '@(.*?)
@ms', '
', $highlighted ); $highlighted = preg_replace( '@()(.*?)((
)+)(.*?)()@ms', '\1\2\6\3\1\5\6', $highlighted ); $highlighted = preg_replace( '@()(.+?)(
)()@ms', '\1\2\4\3', $highlighted ); $highlighted = preg_replace( '@@', '', $highlighted ); $highlighted = preg_replace( '@
.
@', "callbackAddLineNr", $highlighted ); $listing .= $highlighted . '