Follow Sebastiaan de Jonge on Twitter
Sebastiaan de Jonge

Blog

11Oct

Code Snippets

Posted on October 11, 2010 in Extensions by Sebastiaan de Jonge

Some days ago I got a request from someone who was interested in my code snippets plugin. At that time I couldn't really offer the extension, it was simply too specific for my own website. Now that I've made some changes, I feel more comfortable with making it public.

So let's talk about my code highlighter, and why I like it so much. And actually the answer is really simple, I've create a code highlighter that completely fits my needs. Of course this was possible because I built it myself.

Features

  • Code and syntax highlighting is done via GeSHi
  • Better support for TypoScript (better than default GeSHi)
  • Configurable code wrappers via TypoScript (stdWrap)
  • Quick and easy selection due to the fact it's a 'totally new content element.

Screenshots

Just some TypoScript code 
  1. ## Page setup
  2. page {
  3.         10 = TEMPLATE
  4.         10 {
  5.                 ## Template setup
  6.                 template = FILE
  7.                 template.file = fileadmin/themes/szebi/html/template_main.html
  8.         }
  9. }
## Page setup
page {
	10 = TEMPLATE
	10 {
		## Template setup
		template = FILE
		template.file = fileadmin/themes/szebi/html/template_main.html
	}
}

Installation

Simply download the extension at the bottom of this article, or export the most recent version from the repository on Forge. Install it in your TYPO3 backend by using the extension manager, include the static template and you're all done. All required files are then loaded automatically.

Additional Configuration

There are some settings you can change by TypoScript configuration. Here's a list of the things you can change:

TypoScript configuration options 
  1. # This configurations is done in the 'setup' part of your TypoScript template
  2. plugin.tx_sdjcodesnippets_pi1 {
  3.     # Enable code highlighting or not
  4.     enable = 1
  5.  
  6.     # Show plain code as well
  7.     showPlain = 1
  8.  
  9.     # Show the code title
  10.     showTitle = 1
  11.  
  12.     # Wrapper for the highlighted code snippet
  13.     code_stdWrap.wrap = |
  14.  
  15.     # Wrapper for the plain code snippet
  16.     plain_stdWrap.wrap = <pre class="code" id="plain-888a7d04">|</pre>
  17.  
  18.     # Wrapper for the title
  19.     title_stdWrap.wrap = <h5 class="code-header">|&nbsp;<a id="888a7d04" class="code-toggle" onclick="if(document.getElementById('plain-888a7d04').style.display == 'block') { document.getElementById('plain-888a7d04').style.display } else {  } return false;" href="#" title="Toggle plain/highlighted code">!!<=:==////./></a></h5>
  20.  
  21.     # Wrapper for the whole output
  22.     full_stdWrap.wrap = |
  23. }
# This configurations is done in the 'setup' part of your TypoScript template
plugin.tx_sdjcodesnippets_pi1 {
    # Enable code highlighting or not
    enable = 1

    # Show plain code as well
    showPlain = 1

    # Show the code title
    showTitle = 1

    # Wrapper for the highlighted code snippet
    code_stdWrap.wrap = |

    # Wrapper for the plain code snippet
    plain_stdWrap.wrap = <pre class="code" id="plain-888a7d04">|</pre>

    # Wrapper for the title
    title_stdWrap.wrap = <h5 class="code-header">|&nbsp;<a id="888a7d04" class="code-toggle" onclick="if(document.getElementById('plain-888a7d04').style.display == 'block') { document.getElementById('plain-888a7d04').style.display } else {  } return false;" href="#" title="Toggle plain/highlighted code"><img style="float:right;" alt="" src="fileadmin/themes/szebi/img/page_white_code.png" /></a></h5>

    # Wrapper for the whole output
    full_stdWrap.wrap = |
}

The extension is provided with some stylesheets that will work under the default configuration. I didn't have time yet to provide stylesheets for all supported languages, since there are quite some. I'm also not 100% aware of what all these syntaxes should look like, so I prefer not to make any suggestions for that.

No manual

Not yet at least. I just had the time to modify the extension in such a way so it can actually be set available to the public. I will start working on a manual though, once that is done I will also post this extension to the TER. For now this post will have to do as 'manual'. ;-]

Contribute!

If you like the extension and you would like to add something to it, or you have some ideas to make it better. Feel free to let me know! The project is hosted on TYPO3's Forge, so feel free to post any suggestions or issues there. If you would like to contribute code to the extension as well, feel free to apply for it.

Attached files

Arrow downsdj_code_snippets-0.1.0.t3x
556 K
Arrow downsdj_code_snippets_tnce.jpg
46 K
Arrow downsdj_code_snippets_beform.jpg
72 K

Comments (3)

  1. Gravatar: Pim BroensPim Broenson October 12, 2010
    at 14:42
    Reply to this comment

    Nice feature

    That's a nice one mate, GeSHi usually has a nice code highlighting. So it's a nice addition to the content elements.

    One thing I saw in one of the screencaps (first one actually) is the use of the word 'langauge', did you by any change mean 'language'? :)

  2. Gravatar: Sebastiaan de JongeSebastiaan de Jongeon October 12, 2010
    at 17:31

    RE: Nice feature

    Indeed, well spotted. At the time of writing that extension I was still using Eclipse PDT. It unfortunately does not note any spelling mistakes to you. Unlike PhpStorm ;-) I'll correct it, but it's a minor tweak so..

  3. Gravatar: Andreas BeckerAndreas Beckeron November 8, 2010
    at 10:00
    Reply to this comment

    code highlighting plugin

    Lovely!
    I remember your post a few months ago about your switch to t3blog and the creation of your code highlighting plugin.
    Thank you for sharing the code of your highlighting plugin.

Got something to say?

 
Notify me when someone adds another comment to this post
 

Search

Categories

Tags

Archive

Blogroll

Syndicate