websvn
websvn copied to clipboard
Syntax highlighting using shebang only?
I wonder, is it possible to have syntax highlighting based on the shebang of a file, or is the content not known at the time Geshi/Enscript is initialized?
Examples where Syntax highlighting would be very nice:
https://svn.viathinksoft.com/websvn/filedetails.php?repname=oidplus&path=%2Ftrunk%2Fdev%2Fgenerate_example_data_access
https://svn.viathinksoft.com/websvn/filedetails.php?repname=oidplus&path=%2Ftrunk%2Fdev%2Fgenerate_wellknown_other_mysql
One could likely implement content sniffing on the first line, but I think you can solve it this way: https://stackoverflow.com/a/15302869/696632 better.
I modified my copy of the code to do this. It currently works with enscript only, but I can look at the other markup language too. My solution is pretty inefficient since I don't really know the code base; just one function that does an svn cat, grabs first line, and checks if it is a shebang.
All my code recently has been on my own projects (http://svn.dailydata.net), and not real clear on what I should do with the code. If someone will point me to instructions, I'll be happy to upload and/or if you want it extended to the other one (don't remember name), I'll see what I can do.
Following is a diff using diff svnlook.php svnlook.php.original
` 631,640d630 < < // private function to open file, read first line and see if it is a Unix script < // with #! showing the type of file it is < function getFileType ( $path ) { < $output = runCommand( $this->svnCommandString('cat', $path,'','' ) ); < preg_match( '/^#!.^a-z\s$/', $output[0], $matches ); < return $matches[1]; < } < < 659,662c649 < } else if ( $type = $this->getFileType( $path) ) { // scripting language with #! in first line < $cmd .= ' --color --'.(!$config->getUseEnscriptBefore_1_6_3() ? 'highlight' : 'pretty-print').'='.$type; < } <
}
666c653 <
`
I modified my copy of the code to do this. It currently works with enscript only, but I can look at the other markup language too. My solution is pretty inefficient since I don't really know the code base; just one function that does an svn cat, grabs first line, and checks if it is a shebang.
All my code recently has been on my own projects (http://svn.dailydata.net), and not real clear on what I should do with the code. If someone will point me to instructions, I'll be happy to upload and/or if you want it extended to the other one (don't remember name), I'll see what I can do.
Following is a diff using diff svnlook.php svnlook.php.original
`
631,640d630 < < // private function to open file, read first line and see if it is a Unix script < // with #! showing the type of file it is < function getFileType ( $path ) { < $output = runCommand( $this->svnCommandString('cat', $path,'','' ) ); < preg_match( '/^#!.^a-z\s$/', $output[0], $matches ); < return $matches[1]; < } < < 659,662c649 < } else if ( $type = $this->getFileType( $path) ) { // scripting language with #! in first line < $cmd .= ' --color --'.(!$config->getUseEnscriptBefore_1_6_3() ? 'highlight' : 'pretty-print').'='.$type; < } <
}666c653
<
`
Add a readable patch please
I'd love to. Just don't know how. Can you tell me the command? Sorry, I've never submitted to another project before, and mine are so focused on specific areas I've never gotten a patch.
I'd love to. Just don't know how. Can you tell me the command? Sorry, I've never submitted to another project before, and mine are so focused on specific areas I've never gotten a patch.
You can attach a patch file.
figured it out. git clone make changes git diff filename > filename.diff send you filename.diff
found bug. Perl allows #! /usr/bin/perl -w (very old school). Will fix bug, then send patch.
It would not accept a filename with .diff, so I renamed it to .txt. I've run some tests but, if you see any problems, let me know and I'll fix them.
Also, have an idea for syntax highlighting php using the php built in's.
Rod
It would not accept a filename with .diff, so I renamed it to .txt. I've run some tests but, if you see any problems, let me know and I'll fix them.
Also, have an idea for syntax highlighting php using the php built in's.
Rod
Your patch isn't bad after all, I will get back to this next week.
Went through the patch and the current code. There are a few issues here:
- There is not reason why it should not work for both enscript and geshi
- It performs yet another
svn catwhile it could reuse the command in the file - It completely ignored rev and peg