Giter VIP home page Giter VIP logo

syntaxhighlighter's Introduction

SyntaxHighlighter Evolved

WordPress Plugin Version WordPress Tested WordPress Plugin Downloads WordPress Plugin Rating

Easily post syntax-highlighted code to your WordPress site without having to modify the code at all. As seen on WordPress.com.

Supports the new Gutenberg editor!

Block Development Workflow

Source code is located in the src folder. Run npm install to install all of the required modules.

When making changes to the block:

  • Run npm start to build a development version with file watching.
  • Run npm run build to build a minified production file.

syntaxhighlighter's People

Contributors

aaronfc avatar alexsanford avatar astralbodies avatar bor0 avatar caitp avatar candrews avatar chrishardie avatar david-szabo97 avatar dependabot[bot] avatar donnapep avatar donnchawp avatar fjorgemota avatar gikaragia avatar gogdzl avatar iandunn avatar jaclync avatar jeherve avatar jom avatar keoshi avatar kraftbj avatar manoz avatar merkushin avatar renatho avatar shield-9 avatar sirbrillig avatar thedebian avatar tute-avalos avatar viper007bond avatar wevsty avatar yscik 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

syntaxhighlighter's Issues

Consider unregistering "c" as a shortcode

It results in [c] getting stripped from stuff. See #71.

Drawback: It'd break existing usages of the shortcode. Maybe check last modified date? The problem is people will install the plugin update at different times.

Nested shortcode problem

Hi,

Can somebody help me with this issue:

[code]

[xml]

[/code]

output:

1

should be:

[xml]

this works:

[code]

[[xml]]

[/code]

It seems to be the same issue as here: #26
Instead of [c] it's [xml].

Is there way to fix f.g. tell Wordpress not to parse shortcodes inside code blocks?

The source for this could be: https://github.com/Viper007Bond/syntaxhighlighter/search?q=do_shortcode&ref=cmdform

This functions allows you to parse nested shortcodes:
http://www.sitepoint.com/wordpress-nested-shortcodes/

I hope this can set theme each block

I hope I can use code like this
[code theme="Emacs"]
gcc -o file a.c b.c c.c
[/code]

I want to use Default theme to show code, and use Emacs theme to show Console output.

Illegal filtering of generic java code tokens

Thanks for this great plugin, it's great for attrative and readable code rendering.
Using Version 3.1.3 of the plugin, I stumpled into an issue:

[sourcecode language="java"]
public class Aggregator <T> {}

is rendered to

public class Aggregator {}

and thus mutilated to meaninglessness

the generic codetoken <T> is filtered away. I know can easily be interpreted as HTML-Syntax, but here it is part of legal java syntax.

It may be of interest, that after updating the wordpress post, the -Tag is removed from the text alltogehter.

Generic syntax came up with Java 1.5, can you please make a statement of compatility of the plugin and the supported java syntax versions.

When I try to use HTML-Escape tokens like &lt; &gt; the code

public class Aggregator &lt; &gt; is still rendered to public class Aggregator

the HTML escapes tokens are not displayed, but survive at least in the source text without being removed by any obsure hidden filtering. This is suggested as solution by
http://codex.wordpress.org/Writing_Code_in_Your_Posts should generally help, but it fails here.

You can check the erronous rendering at my blog at:
http://www.knowledgeware-consulting.ch/java/generic-types-and-generic-algorithms

My idea of a syntax highligther is that of any coder. Code should be taken as literal text. No programm tokens should vanish. Only color formatting should be added. No extra preprocessing of the code should be necessary. The coders reputation should not be ruined by an syntax highlighter, that conseals some program tokens....I know this is no easy issue, interaction between wordpress renderer and the input and rendered output of the plugin may become quite complex.

Can you please resolve this issue.

Kind regards

Othmar Lippuner

PS: Sorry I now this is a nitty-gritty issue. I experienced it myself when writting this text here. At had to joggle quite a bit with these HTML escapes ;-) at least it's not filtered out here....

A brush for GraphViz

A Brush for the Dot Language in GraphViz

The brush can be found on this gist: shBrushDot.js. Please feel free to use it, modify it, or add it to the plugin as you see fit

I created this brush some time ago. You can see it in action on my blog.

Shortcodes get injected with pre tags by tinymce when block-level html is included.

Steps to reproduce:

  1. Create a post
  2. In the text tab of tiny mce add a SH shortcode with an h1 (or any block-level tag) in it.
  3. Save the post
  4. After page reload, switch to the visual tab (to see the visual affect of injected pre tags)
  5. Switch back to the text tab ( to see injected code )

Example short code
[html]<h1>This is an h1</h1>[html]

Expected output:

The user should be able to switch tiny mce modes (text/visual) and the content should not have code injected at the very least.

Actual Output:

Since SH passes unescaped html to the editor and wraps the shortcode in pre tags, tiny mce breaks up the shortcode in to segments injecting closing and opening pre tags to exclude the block level element from the pre content. This is because block-level elements are not valid children of the pre element.

collapse appears to be broken

Hello, I noticed an interesting problem recently. After updating to v3.1.7, the collapse function seems to have broken. Specifically, if I remove the collapse argument from my code blocks, they show up, and if I leave collapse in, the code disappears completely. Manually setting light="false" and toolbar="true" in the code header doesn't affect anything. (I also tried manually setting collapse="false" as a test, and that worked fine.) Setting the default behavior to collapse=true in the settings pane makes all code disappear.

Do you have any ideas or workarounds?
Cheers,
Phil

do_shortcode($post_meta_field) returns 1 for each shortcode

If you use

echo do_shortcode(get_post_meta('fieldname', $post->ID, true));

you'll get your shortcodes and their content returned as '1'

Example

$content_from_a_post_meta_field = '
This is an 
[php]$example_demonstration = true[/php]
for your convenience';

echo do_shortcode($content_from_a_post_meta_field);

returns "This is an 1 for your convenience"

BuddyPress / bbPress Support

Hi Alex,

Would it be possible to please add support for BuddyPress and bbPress (default forums for BuddyPress)?

Forum discussions can often involve pasting code snippets, and being able to use SyntaxHighlighter Evolved makes sense.

Thanks!

Emoji links are shown in plaintext if code contains an emoticon

I haven't inspected how and when the emoticons in a post are converted into emojis. But currently, when some emoticons are present inside of the shortcode for the syntaxhighlighter, they are converted to the emojis, before the syntaxhighlighter converts the code into the HTML markup, so the link for the emoji is shown. Here is an example for such a highlighted code:

emoji-she

How to escape square brackets?

It seems that text between square brackets are stripped from the highlighted code. For instance, in this code:

[diff "csharp"]
  xfuncname = ^[ \\t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe|async|partial)[ \\t]+)*[][<>@.~_[:alnum:]]+[ \\t]+[<>@._[:alnum:]]+[ \\t]*\\(.*\\))[ \\t]*$

the [diff "csharp"] part was stripped, maybe because it looks like a shortcode. Is there a way to escape it? As a workaround, I changed it to [ diff "csharp"], but it's not ideal.

HTML belonging to the post are shown as highlighted code

Hi,

I've installed your plugin from the wordpress plugin factory as well as by cloning it from Git.
Using several shortcodes gives me all the same problem:
tags are shown in the highlight. Also, html encoded characters are shown as the encoded entity.

I've attached an image for you to see.
I have not modified any content of your plugin. Do you have any idea what I could check or how to fix this issue?
Many thanks in advance.

image
Extra info:
WordPress 3.5.1.
SyntaxHighlighter Evolved Version 3.1.6

'autolinks' preference ignored for bash

Take a look at http://make.wordpress.org/core/handbook/automated-testing/#installation

Code being used is in the WordPress blog post:

[sourcecode language="bash" autolinks="false"]
$ svn co http://develop.svn.wordpress.org/trunk/ wordpress-develop
$ cd wordpress-develop
[/sourcecode]

Resulting Code Display Output:

$ svn co <a href="http://develop.svn.wordpress.org/trunk/" rel="nofollow">http://develop.svn.wordpress.org/trunk/</a> wordpress-develop
$ cd wordpress-develop

Expected Code Display Output

$ svn co http://develop.svn.wordpress.org/trunk/ wordpress-develop
$ cd wordpress-develop

Data URI causes WP to fail save and preview

I don't know what's happening but when I try to enter some code similar to this:

[js]
$("img.placeholder").attr("src", "data:image/svg+xml;charset=utf8;base64," + encoded));
[/js]

It seems to hang wordpress:

  • When I click the "Save Draft" the spinner just goes on and on until I get a browser error about page not responding. If I try to click "Preview" again the preview tries to load but it goes on forever before finally failing.
  • The problem seems to be in the "data:image/" part. Even putting "data :image/" will fix it (note the space between "data" and the colon). I tried escaping with '%3A' but the same thing happens.

As a workaround I tried to put a similar character, like a ꞉ (modifier letter colon, unicode 0xa789), but that may have other consequences in browser without fonts.

[ps] becomes 1

example:
my code(In the background):
pt.append(str(psutil.disk_usage(psutil.disk_partitions()[ps][1])[-1])+'%')
but show:
pt.append(str(psutil.disk_usage(psutil.disk_partitions()1[1])[-1])+'%')
why???

Add "inline" option?

Perhaps add an option the shortcodes to specify inline="true/false"

Default would be false, where the code will be unchanged from how it is now.

If you specify true, it would remove the gutter and put the code inline without display:block CSS.

This is really useful for displaying short single lines of code inline with the text.

Thanks

Valid single quotes in SQL block not highlighted correctly

In a block of SQL code there appears to be an error in how single quotes are parsed. In the following block of code, everything from DEFAULT '' down to '%' is appearing as if it was a very long string literal.

This can be seen live at http://jeremythomerson.com/2013/05/30/urlencoder-function-for-mysql/

Here is the entire block of SQL that is causing the problem:

DELIMITER ;

DROP FUNCTION IF EXISTS urlencode;

DELIMITER |

CREATE FUNCTION URLENCODE(str VARCHAR(4096) CHARSET utf8) RETURNS VARCHAR(4096) CHARSET utf8
DETERMINISTIC
CONTAINS SQL
BEGIN
   -- the individual character we are converting in our loop
   -- NOTE: must be VARCHAR even though it won't vary in length
   -- CHAR(1), when used with SUBSTRING, made spaces '' instead of ' '
   DECLARE sub VARCHAR(1) CHARSET utf8;
   -- the ordinal value of the character (i.e. ñ becomes 50097)
   DECLARE val BIGINT DEFAULT 0;
   -- the substring index we use in our loop (one-based)
   DECLARE ind INT DEFAULT 1;
   -- the integer value of the individual octet of a character being encoded
   -- (which is potentially multi-byte and must be encoded one byte at a time)
   DECLARE oct INT DEFAULT 0;
   -- the encoded return string that we build up during execution
   DECLARE ret VARCHAR(4096) DEFAULT '';
   -- our loop index for looping through each octet while encoding
   DECLARE octind INT DEFAULT 0;

   IF ISNULL(str) THEN
      RETURN NULL;
   ELSE
      SET ret = '';
      -- loop through the input string one character at a time - regardless
      -- of how many bytes a character consists of
      WHILE ind &lt;= CHAR_LENGTH(str) DO
         SET sub = MID(str, ind, 1);
         SET val = ORD(sub);
         -- these values are ones that should not be converted
         -- see http://tools.ietf.org/html/rfc3986
         IF NOT (val BETWEEN 48 AND 57 OR     -- 48-57  = 0-9
                 val BETWEEN 65 AND 90 OR     -- 65-90  = A-Z
                 val BETWEEN 97 AND 122 OR    -- 97-122 = a-z
                 -- 45 = hyphen, 46 = period, 95 = underscore, 126 = tilde
                 val IN (45, 46, 95, 126)) THEN
            -- This is not an &quot;unreserved&quot; char and must be encoded:
            -- loop through each octet of the potentially multi-octet character
            -- and convert each into its hexadecimal value
            -- we start with the high octect because that is the order that ORD
            -- returns them in - they need to be encoded with the most significant
            -- byte first
            SET octind = OCTET_LENGTH(sub);
            WHILE octind &gt; 0 DO
               -- get the actual value of this octet by shifting it to the right
               -- so that it is at the lowest byte position - in other words, make
               -- the octet/byte we are working on the entire number (or in even
               -- other words, oct will no be between zero and 255 inclusive)
               SET oct = (val &gt;&gt; (8 * (octind - 1)));
               -- we append this to our return string with a percent sign, and then
               -- a left-zero-padded (to two characters) string of the hexadecimal
               -- value of this octet)
               SET ret = CONCAT(ret, '%', LPAD(HEX(oct), 2, 0));
               -- now we need to reset val to essentially zero out the octet that we
               -- just encoded so that our number decreases and we are only left with
               -- the lower octets as part of our integer
               SET val = (val &amp; (POWER(256, (octind - 1)) - 1));
               SET octind = (octind - 1);
            END WHILE;
         ELSE
            -- this character was not one that needed to be encoded and can simply be
            -- added to our return string as-is
            SET ret = CONCAT(ret, sub);
         END IF;
         SET ind = (ind + 1);
      END WHILE;
   END IF;
   RETURN ret;
END;

|

DELIMITER ;

Broken HTML when switching between text and visual

Steps to reproduce:

  1. Open tinymce editor in text mode

  2. Add the following example

    <ul>
      <li>[javascript][/javascript]</li>
      <li>[java][/java]</li>
    </ul>
    
  3. Switch to visual tab

Expected result: Two items of the unordered list with the given shortcodes
Actual result: One item and broken HTML.

image

Unwanted whitespace at the end of every snippet

Wherever I try to use the highlighter I get some whitespace at the bottom. Take a look at the attached image:
highligher
I tried changing the options, I resetted to the default ones, without any success so far...

Java Parse Error

When i insert

    public void clear(){

        // Die Liste der Objekt in diesem Node leeren
        objects.clear();

        // Für Alle Child Nodes
        for(int i = 0; i < nodes.length; i++)
        {
            // Den Node löschen, falls er noch existiert
            if (nodes[i] != null){
                nodes[i].clear();
                nodes[i] = null;
            }
        }
    }

into the text editor it spits out:

    public void clear(){

        // Die Liste der Objekt in diesem Node leeren
        objects.clear();

        // Für Alle Child Nodes
        for(int i = 0; i <span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>< nodes.length; i++)
        {
            // Den Node löschen, falls er noch existiert
            if (nodes[i] != null){
                nodes[i].clear();
                nodes[i] = null;
            }
        }
    }

yet im not sure if some other Plugin is causing this issue.

Yandex Metrica Problem

Hi,

When I activate that plugin yandex metrica codes doesn't work, do you have a known solution about that.

syntaxhighlighter broken on WP 4.4

Hi,

Firstly, thanks for this plugin. My blog revolves around code fragments, so use of this plugin is pretty central to everything I do.

I am not sure whether this is directly linked to WP 4.4, but I updated my site some time ago and have now noticed that a lot of my code (which is mostly R) is not being rendered properly by the plugin.

You can see examples here: http://www.exegetic.biz/blog/2015/01/download-option-chain-from-google-finance-in-r-an-update/. Quotes are being rendered as " and the "<" character in the assignment operator is showing up as <.

Thanks,
Andrew.

some help with language plugins

Hi there,

I'd like to adopt this project here and update it for compatibility with Syntax Highlighter Evolved. Any chance you know of instructions on how I can actually install the said plugin? I'm a bit new to all this, and the author didn't respond.

!important Tags in CSS and Themes

I think it is a little difficult to customize how the plugin looks. You added the possibility for custom css classes but they are so high level that they get overwritten by the !important tag even when using !important too. I would like a theme with a special background color but theres also the possibility missing to create a new theme. I would love to see either custom theme support or any other fix to change text color and background color easily and without losing the changes due to updating.

Edit: Just found this: https://alex.blog/wordpress-plugins/syntaxhighlighter/adding-a-new-theme/ but still its well hidden and a little complicated to do for beginners

Title being in capital letters

If I set the title of a code the text get's capitalized - at least in my setup which is pretty much a standard wordpress installation. This is undesireable and I consider it a but as sometimes it's quite important (e.g. in the unix environments it's often crucial to know the exact spelling of e.g. file names: config.file is somthing else that CONFIG.FILE).

Feature Request: Code from GitHub

I love this plugin. I use it and recommend it. I would like to request a feature.

You know what would be an awesome feature? To not even had the code on the blog, except cached, but instead keep the code on github.

It could be implemented as follows.

[csharp codeFromUrl="https://raw.githubusercontent.com/rhyous/SimpleArgs/master/Rhyous.SimpleArgs/Model/Argument.cs"]
[/csharp]

I took at look at your code base, but wouldn't be sure where or how to add this feature.

Visual editor support

Currently, <and > get entity encoded when switching between the visual and HTML tabs of the post editor. I know that this is a known bug, but very annoying. (I'm pretty certain it is fixable, though.)

WordPress Defer Functionality Breaks Plugin

Using 'Defer' in functions.php breaks plugin, It converts all code highlighting to none & make it black on grey background you can have a look on my website: http://mandarapte.com/apple/stop-spam-blocking-spam-senders-ip-address-ultimate-solution-block-spam-order-deny-ip-htaccess/

I am using following code defer or async .js files in footer

Code:

// Adapted from https://gist.github.com/toscho/1584783
add_filter( 'clean_url', function( $url )
{
if ( FALSE === strpos( $url, '.js' ) )
{
return $url;
}
return "$url' defer='defer";
}, 11, 1 );

&amp; get's escaped multiple times in TinyMCE 4

When using TinyMCE 4 a problem can occur with the escaping of & characters.

There is a blind search and replace of & to &amp;.
In the TinyMCE javascript there is unescaping and escaping for pre_wpautop and wpautop which should avoid this problem.

The solution which worked best for me is to add an additional replace to make sure there are no &amp;amp; occurences in the shortcode content.

Uncaught DOMException: Failed to execute 'insertBefore' on 'Node'

I'm using Virtue Premium theme and Syntax Highlighter can't be initialized. In Chrome console there is following error:

Uncaught DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.

I assume Virtue Premium theme is affecting custom style elements placement.

To fix this just replace document.getElementsByTagName("head")[0] with document.getElementById("syntaxhighlighteranchor").parentNode in syntaxhighlighter.php (lines 709 and 724).

This fix should work in all other cases as well.

Small project completion

  1. Add class to wrapper DIV (.syntaxhighlighter-wrapper)
  2. Add trigger after code highlighted (syntaxhighlighter_complete)

Enable 'r' language shortcode

Currently the 'r' language is not supported in the shortcode. Is it possible to enable it? because we really need it to highlight using shortcode.

"data[c]" in c code showed as "data1"

Hello,

When trying to highlight c language code with syntaxhighlighter, the "data[c]" is showed as "data1". Something like this:

[code lang="c"]

char data[100];
int cpp;

for (c=0;c<100;c++)
data[c]="a";
[/code]

will be showed as this:

c

TinyMCE Advanced - Stop removing p and br tags issue

From my testing, I seem to have a major issue when combining Syntax Highlighter and TinyMCE Advanced with this option turned on:

"Stop removing the <p> and <br /> tags when saving and show them in the HTML editor"

When I have this option on, and I re-save a post using this Syntax Highlighter the code gets 100% mangled with <br /> tags all over the place. Having this options is super handy in my experience with the WP HTML editor, so any ideas how these two can be combined?

Thanks!

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.