sed_display_code.
A plugin to format and display a text file—specifically a file of code—in a convenient manner.
There are other plugins out there that do this too, but this was my first shot an a TXP plugin—a project on which to cut my php teeth—and I wanted a code listing with cleaner layout than glx_code and a lot leaner output than GeSHi. This is the result.
All of the listings on this page are generated with this plugin.
Examples
The following listings demonstrate the features of this plugin.
rving.com/files/snip.php.txt was not found.
Tag Used To Generate Listing 1.
<txp:sed_display_code file="snip.php" list_no="1" show_count='Copies Grabbed: '/>
Listing 1 Notes
- No Syntax highlighting.
That’s right, no syntax highlighting. The bulk of Dunstan’s original code to do this was to recognise and mark up comment blocks. To correctly handle comments from a variety of possible source languages requires quite a lot of parsing. In the end I decided that I could simply do without comment highlighting—in fact, I could do without any form of syntax highlighting. Doing without it really simplifies the code. If you simply must have syntax highlighting then go grab the GeSHi plugin. - Integration with TXP File Management
By default, v0.5 will use TXP’s files directory for storing your files and the download link can show how many times a file has been grabbed. - Customisable download link.
If you want a download link—you can have it! You can then change the text and tooltip displayed. If you don’t want a link—you can surpress it.
Easy! - Alternate row styling.
The styles for odd and even rows can be defined in your css file.
rving.com/files/snip.php.txt was not found.
Tag Used To Generate Listing 2.
<txp:sed_display_code file="snip.php" link_text='' highlight1="5,6,7" list_no="2" />
Listing 2 Notes
- Download link surpressed.
This listing useslink_text=''to prevent the download link from being output. - Line highlighting.
You can define up to three sets of line numbers to be highlighted in your listing. Useful if you want to draw attention to certain aspects of your code. Each highlight set is customisable via your CSS file. - Robust tabulation at the start of lines.
Correctly displays lines from the source file that have tabs embedded in the middle of them. Check out the highlighted lines and also the source (from listing 1) to see the cleanup. - Preserves blank lines.
Any line of the source file that is blank produces a corresponding blank line in the screen output.
| # | Code |
|---|---|
| 0251 | function sed_generate_row ( $wrap, $line_no, $line, $row_class, $line_cell_class ) { |
| 0252 | $pv_space = ' '; |
| 0253 | |
| 0254 | $pv_line_no_cell = doTag( $line_no, $wrap, '' ); |
| 0255 | $pv_line_cell = doTag( $line, $wrap, $line_cell_class ); |
| 0256 | |
| 0257 | return doTag( $pv_line_no_cell.$pv_line_cell, 'tr', $row_class )."\n"; |
| 0258 | } |
Tag Used To Generate Listing 3.
<txp:sed_display_code dir='code' file="sed_display_code-0.2.php" start="251" end="258" link_text='' highlight3="251,257" list_no="3" />
Listing 3 Notes
- Specific Directory
You can re-direct the plugin to get your code from a specific directory if you prefer not to use TXP file management. - Customisable start & end lines.
You can list just a portion of a file by defining the start line, end line or both. - Tabulation on wrapped lines.
Check out lines 251 and 257 in the listing. Unlike code listers that use ordered lists as the basis for the output, this plugin also indents the wrapped portion of lines.
rving.com/files/doesnt-exist.php.txt could not be located!
Tag Used To Generate Listing 4.
<txp:sed_display_code file="doesnt-exist.php" list_no="4" err_text="could not be located!"/>
Listing 4 Notes
- Error Message Styling
You can specify custom error messages and an error style for CSS markup if a file cannot be found.
Downloads
The latest version is available here—as are any prior versions.
- sed_display_code-0.5.txt [33.07KB]
v0.5 of the Display Code Plugin.<br/>Adds integration with TXP file management. : 1445 download(s)
- sed_display_code-0.4.txt [26.40KB]
v0.4 Of the Display Code Plugin. : 1324 download(s)
- sed_display_code-0.3.txt [25.79KB]
v0.3 of the Display Code Plugin. : 1107 download(s)
- sed_display_code-0.2.txt [27.87KB]
v0.2 of the Display Code Plugin : 1098 download(s)
- sed_display_code-0.1.txt [17.63KB]
v0.1 of the Display Code Plugin : 1213 download(s)
Manual
For detailed instructions and example tags, please refer to the manual.