Giter Site home page Giter Site logo

dokuwiki-plugin-syntaxhighlighter4's Introduction

Github Release Minimum DokuWiki Version
Become a sponsor Donate Paypal

About

This plugin is an alternative to GeSHi server-side code highlighting of DokuWiki with client-side SyntaxHighlighter by Alex Gorbatchev.

The subfolder syntaxhighlighter4/dist contains a build of SyntaxHighlighter 4.x.

For compatibility and conflicts with others plugins, please refer to the official DokuWiki SyntaxHighlighter4 plugin page.

Download and Installation

Download and install the plugin using the Plugin Manager using the download link given above. Refer to Plugins on how to install plugins manually.

If you install this plugin manually, make sure it is installed in lib/plugins/syntaxhighlighter4/. If the folder is called different it will not work!

Syntax and Usage

<sxh [brush][; options]>
... code/text ...
</sxh>

Brush

The brush (language) that SyntaxHighlighter should use. Defaults to "text" if none is provided.
See the section brushes and themes for a complete list of available brushes.

Options

Semicolon separated options for SyntaxHighlighter, see SyntaxHighlighter Configuration.
The plugin handles the Block Title from SyntaxHighlighter 3 as an option, i.e. title: <title string>;.

Defaults

Syntaxhighlighter default options can be overrided via the Config Manager :

  • autoLinks: Allows you to turn detection of links in the highlighted element on and off. If the option is turned off, URLs won’t be clickable (default true)
  • firstLine: Allows you to change the first (starting) line number (default 1)
  • gutter: Allows you to turn gutter with line numbers (default true)
  • htmlScript: Allows you to highlight a mixture of HTML/XML code and a script which is very common in web development. Setting this value to true requires that you have shBrushXml.js loaded and that the brush you are using supports this feature (default false)
  • smartTabs: Allows you to turn smart tabs feature on and off (default true)
  • tabSize: Allows you to adjust tab size (default 4)
  • override: List of tags to override

Example

<sxh php; first-line: 89; highlight: [106,107]; title: New title attribute in action>
    /**
     * Render xhtml output or metadata
     *
     * @param string         $mode      Renderer mode (supported modes: xhtml)
     * @param Doku_Renderer  $renderer  The renderer
     * @param array          $data      The data from the handler() function
     * @return bool If rendering was successful.
     */
    public function render($mode, Doku_Renderer &$renderer, $data) {
        if($mode != 'xhtml') return false;

        if (count($data) != 3) {
            return true;
        }

        list($syntax, $attr, $content) = $data;
        if ($syntax == 'sxh') {
            $title = $this->procTitle($attr);
            $highlight = $this->procHighlight($attr);
            $renderer->doc .= '<pre class="brush: ' . strtolower($attr . $highlight) . '"' . $title . '>' . $renderer->_xmlEntities($content) . '</pre>';
        } else {
            $renderer->file($content);
        }

        return true;
    }
</sxh>

Expected result:

Features

Copy to clipboard

Double click anywhere inside SyntaxHighlighter code area to highlight the text and then copy it using Ctrl/Cmd+C or mouse right click > Copy.
Click outside the code area to restore highlighting.

Highlight a range of lines

Example:

<sxh php; highlight: [11-15]>
    /**
     * [Custom event handler which performs action]
     *
     * @param Doku_Event $event  event object by reference
     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
     *                           handler was registered]
     * @return void
     */

    public function handle_metaheader(Doku_Event &$event, $param) {
        // Add SyntaxHighlighter theme.
        $event->data['link'][] = array('rel' => 'stylesheet',
            'type' => 'text/css',
            'href' => DOKU_BASE . 'lib/plugins/syntaxhighlighter4/dist/'.$this->getConf('theme'),
        );

        // Register SyntaxHighlighter javascript.
        $event->data["script"][] = array("type" => "text/javascript",
            "src" => DOKU_BASE . "lib/plugins/syntaxhighlighter4/dist/syntaxhighlighter.js",
            "_data" => ""
        );
    }
</sxh>

Expected result:

List of brushes and themes

  • Official brushes
    • applescript
    • as3
    • base
    • bash
    • coldfusion
    • cpp
    • csharp
    • css
    • delphi
    • diff
    • erlang
    • groovy
    • haxe
    • java
    • javafx
    • javascript
    • perl
    • php
    • plain
    • powershell
    • python
    • ruby
    • sass
    • scala
    • sql
    • swift
    • tap
    • typescript
    • vb
    • xml
  • Custom brushes
    • halcon
    • IEC61131
    • kotlin
    • latex
    • Makefile
    • mel
    • objective-c
    • yaml
  • Official themes
    • default
    • django
    • eclipse
    • emacs
    • fadetogrey
    • mdultra
    • midnight
    • rdark
    • swift
  • Custom themes

How can I help ?

All kinds of contributions are welcome πŸ™Œ! The most basic way to show your support is to star 🌟 the project, or to raise issues πŸ’¬ You can also support this project by becoming a sponsor on GitHub πŸ‘ or by making a Paypal donation to ensure this journey continues indefinitely! πŸš€

Thanks again for your support, it is much appreciated! πŸ™

License

GPLv2. See LICENSE for more details.
Icon credit to Snip Master.

dokuwiki-plugin-syntaxhighlighter4's People

Contributors

crazy-max avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dokuwiki-plugin-syntaxhighlighter4's Issues

Underscores in last line get cut off

When the last line contains underscores, they get cut off. For example,

my_item.do_something_with_it(5);

looks like

my item.do something with it(5);

It looks like the line height is just that little bit too small. The problem doesn't appear in any lines above the last, though. I've tested it on Firefox and Chromium (both using Bitstream Vera Sans Mono as font).

Enable highlighting of sections within a line

It would be create to have a chance to only highlight a section of a line e.g. column 20 to 30. This is useful to clearly indicate portions of a code to alter. For example using current highlight option the following extension to the syntax shall work:

  • current behaviour: highlight: [10, 20-30] <- to highlight complete lines
  • additional behaviour: highlight: [10:5-10, 20-30:13-17] <- to highlight column 5 to ten in line 10 and column 13 to 17 in each line from 20 to 30 (like a block 'select')

Override <file> syntax and grab title

Thank you for this great plugin.

It would be nice if it could override <file> as well as <code>.

Also if it could parse the dokuwiki code and file syntax titles that would be awesome, as I wouldn't have to rewrite anything.

Reference: Downloadable Code Blocks
<code bash TITLE></code>
<file bash TITLE></file>

Uncaught Error: Brush wasn't configured for html-script option: bash

I have tried a couple of brushes I wanted to use like bash and cpp and I always get the following error:
Uncaught Error: Brush wasn't configured for html-script option: bash
at new HtmlScript (syntaxhighlighter.js:3414)
at Object.highlight (syntaxhighlighter.js:217)
at syntaxhighlighter.js:101
at HTMLDocument.listener (syntaxhighlighter.js:5296)

Other brushes like php for example render fine without an issue.

Cannot add code to dokuwiki page

Hello,

When I try to save some bash code to a dokuwiki page, I get an error on this specific line:

spawn sed -i "/$host/d" /root/.ssh/known_hosts

Is there a way to bypass this?

Kind regards,

John

Option to use <code/> instead of <sxh/>

Could you add an option to override the default Geshi highlighter? Another addon (Code Prettifier) does this, and it helps because you can get the syntax highlighted in the actual code mirror (of course it will still only highlight what Geshi supportsβ€”but at least most languages will be highlighted). It would also make it easier to switch between Geshi and your addon if technical difficulties emerge with either.

thanks

Icon in editor

Hello! )

Can you please add an icon in text editor? It will be very useful.

Installation errors

Hello!

After installing I have next errors

Warning: Declaration of syntax_plugin_syntaxhighlighter4::handle($match, $state, $pos, Doku_Handler &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in C:\xampp\htdocs\dokuwiki\lib\plugins\syntaxhighlighter4\syntax.php on line 199

Warning: Declaration of syntax_plugin_syntaxhighlighter4::render($mode, Doku_Renderer &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in C:\xampp\htdocs\dokuwiki\lib\plugins\syntaxhighlighter4\syntax.php on line 199

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\dokuwiki\lib\plugins\syntaxhighlighter4\syntax.php:199) in C:\xampp\htdocs\dokuwiki\inc\actions.php on line 210

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\dokuwiki\lib\plugins\syntaxhighlighter4\syntax.php:199) in C:\xampp\htdocs\dokuwiki\lib\tpl\dokuwiki\main.php on line 12

I think I because PHP7.
Can you fix it please.

Error in admin page (PHP 7 error)

Hello!

Unfortunately, when I go to admin page
/doku.php?id=user:admin&do=admin
There are 2 mistakes ((

Warning: Declaration of syntax_plugin_catlist::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in C:\xampp\htdocs\dokuwiki\lib\plugins\catlist\syntax.php on line 334

Warning: Declaration of syntax_plugin_catlist::render($mode, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in C:\xampp\htdocs\dokuwiki\lib\plugins\catlist\syntax.php on line 334

please add brush for go lang

Thanks for your work on syntaxhighlighter4.

Though c++ brush can temporarily highlight go syntax,
It would be happy to have complete go lang brush.

Cheers.

403 forbidden

Hi,
While using the demo code for syntaxhighlighter provided in readme page on Playground , When I click preview received the below error -
Forbidden
You don't have permission to access /doku.php on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

PS:I already changed the permission to 0755 for all the files.

What should I do now?

Unwanted vertical scrollbar appearing

Please see https://rtfm.kojukination.com/start for an example of this.

I've spent some time in the inspector trying to figure out what's going on, and the short of it is the container div seems to be just one pixel short of not needing the scrollbar. For example, if you go to my example page and inspect it, you'll probably see the container div like so...

<div class="syntaxhighlighter powershell" >

The inspector tells me that its height is 240px, and I see the scrollbar. If I use the inspector to change the code to...

<div class="syntaxhighlighter powershell" style="height:241px">

...the scrollbar will go away.

Unfortunately my CSS-foo is not strong enough to dissect all the existing style-sheet settings and figure out what is contributing to this extra pixel that doesn't fit. But I hope you can figure it out.

Otherwise I love your plugin and look forward to making use if it in my wiki. I'm just really OCD about that scrollbar :(

Thanks!

Line breaks

Hi. Is is possible, to show the code with line wrapping at the end of the container (no scrolling)?

span tags appear in sxh block of page when searching dokuwiki for string

If I have a block on a page:
<sxh> testing123 </sxh>
When searching dokuwiki for "testing123", the page will appear in the search results. Upon clicking the link from the search results to the page, the following in the sxh block of the rendered page:
<span class="search_hit">testing123</span>

Dokuwiki is effectively attempting to highlight the string that it found in the sxh code block. However, instead of rendering the HTML code, it is just printing it to the screen.

[Request] Round corner

Is it possible to add some option to round the corners of the code box please? This is really less aggressive with corners, thanks.

[Feature request] Link to download the code

In the code plugin it was possible to download the code by using <code py program.py> </code>

That would be nice to have the ability to download the code snipet as a file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.