Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax highlighting using shebang only? #203

Open
danielmarschall opened this issue Nov 7, 2023 · 9 comments
Open

Syntax highlighting using shebang only? #203

danielmarschall opened this issue Nov 7, 2023 · 9 comments

Comments

@danielmarschall
Copy link
Contributor

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

@michael-o
Copy link
Member

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.

@rrodolico
Copy link

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
<

`

@michael-o
Copy link
Member

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

@rrodolico
Copy link

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.

@michael-o
Copy link
Member

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.

@rrodolico
Copy link

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.

@rrodolico
Copy link

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

svnlook.php.txt

@michael-o
Copy link
Member

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

svnlook.php.txt

Your patch isn't bad after all, I will get back to this next week.

@michael-o
Copy link
Member

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 cat while it could reuse the command in the file
  • It completely ignored rev and peg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants