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

Fix regular expression #68 #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion syntaxhighlighter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
( function($) {
var shortcodes = window.syntaxHLcodes || 'sourcecode',
regex = new RegExp( '(?:<pre>\\s*)?(\\[(' + shortcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?', 'gi' );
regex = new RegExp( '(?:<pre>\\s*)?(\\[(' + shortcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?', 'gi' );

window.syntaxHLescape = {};

Expand Down
2 changes: 1 addition & 1 deletion syntaxhighlighter_mce-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
tinymce.PluginManager.add( 'syntaxhighlighter', function( editor ) {
editor.on( 'BeforeSetContent', function( event ) {
var shortcodes = window.syntaxHLcodes || 'sourcecode',
regex = new RegExp( '(?:<p>\\s*)?(?:<pre>\\s*)?(\\[(' + shortcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?(?:\\s*<\\/p>)?', 'gi' );
regex = new RegExp( '(?:<p>\\s*)?(?:<pre>\\s*)?(\\[(' + shortcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?(?:\\s*<\\/p>)?', 'gi' );

if ( event.content && event.content.indexOf( '[' ) !== -1 ) {
event.content = event.content.replace( regex, function( match, shortcode ) {
Expand Down
10 changes: 5 additions & 5 deletions syntaxhighlighter_mce.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if ( typeof syntaxHLcodes == 'undefined' ) {
_visualToHtml : function(content) {
content = tinymce.trim(content);
// 2 <br> get converted to \n\n and are needed to preserve the next <p>
content = content.replace(new RegExp('(<pre>\\s*)?(\\[(' + syntaxHLcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\3\\])(\\s*<\\/pre>)?', 'gi'),
content = content.replace(new RegExp('(<pre>\\s*)?(\\[(' + syntaxHLcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]*?\\[\\/\\3\\])(\\s*<\\/pre>)?', 'gi'),
function(a) {
a = a.replace( /<br \/>([\t ])/g, '<br \/><%%KEEPWHITESPACE%%>$1' );
return a + '<br /><br />';
Expand All @@ -51,14 +51,14 @@ if ( typeof syntaxHLcodes == 'undefined' ) {
_htmlToVisual : function(content) {
content = tinymce.trim(content);

content = content.replace(new RegExp('(<p>\\s*)?(<pre>\\s*)?(\\[(' + syntaxHLcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\4\\])(\\s*<\\/pre>)?(\\s*<\\/p>)?', 'gi'), '<pre>$3</pre>');
content = content.replace(new RegExp('(<p>\\s*)?(<pre>\\s*)?(\\[(' + syntaxHLcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]*?\\[\\/\\4\\])(\\s*<\\/pre>)?(\\s*<\\/p>)?', 'gi'), '<pre>$3</pre>');
content = content.replace(/<\/pre><pre>/gi, '\n');

// Remove anonymous, empty paragraphs.
content = content.replace(/<p>(\s|&nbsp;)*<\/p>/mg, '');

// Look for <p> <br> in the [tag]s, replace with <br />
content = content.replace(new RegExp('\\[(' + syntaxHLcodes + ')[^\\]]*\\][\\s\\S]+?\\[\\/\\1\\]', 'gi'),
content = content.replace(new RegExp('\\[(' + syntaxHLcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]+?\\[\\/\\1\\]', 'gi'),
function(a) {
return a.replace(/<br ?\/?>[\r\n]*/g, '<br />').replace(/<\/?p( [^>]*)?>[\r\n]*/g, '<br />');
});
Expand All @@ -85,7 +85,7 @@ function pre_wpautop2(content) {

content = this._pre_wpautop(content);

content = content.replace(new RegExp('\\[(' + syntaxHLcodes + ')[^\\]]*\\][\\s\\S]+?\\[\\/\\1\\]', 'gi'),
content = content.replace(new RegExp('\\[(' + syntaxHLcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]+?\\[\\/\\1\\]', 'gi'),
function(a) {
return a.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&').replace(/<%%KEEPWHITESPACE%%>/g, '');
});
Expand All @@ -95,7 +95,7 @@ function pre_wpautop2(content) {

function wpautop2(content) {
// js htmlspecialchars
content = content.replace(new RegExp('\\[(' + syntaxHLcodes + ')[^\\]]*\\][\\s\\S]+?\\[\\/\\1\\]', 'gi'),
content = content.replace(new RegExp('\\[(' + syntaxHLcodes + ')(?:\\s+[^\\]])*\\][\\s\\S]+?\\[\\/\\1\\]', 'gi'),
function(a) {
return a.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
});
Expand Down