Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3d2b18c
Fix for stripping link/style tags
j-ro Apr 23, 2014
f4a74fd
adding authorship
j-ro Sep 21, 2014
1da2915
dashes!
j-ro Sep 21, 2014
5d9c638
adding deploy script
j-ro Sep 23, 2014
16a6dec
versioning
j-ro Sep 23, 2014
c154a9e
updating names and versions
j-ro Sep 23, 2014
11494c6
updating tested up to
j-ro Sep 23, 2014
1739c08
fix for in-url javascript
j-ro Sep 23, 2014
c5cfb3b
newlines vs non-spaces fix
Jan 21, 2015
d13ec99
Merge pull request #1 from biziclop/master
j-ro Jan 21, 2015
12b3a2b
update for 1.5.2
j-ro Jan 22, 2015
1a6d92d
fixes for comments and newlines and IE
j-ro Jan 22, 2015
6c29c99
fixing readme version
j-ro Jan 22, 2015
57d4068
updating changelog
j-ro Jan 22, 2015
e9cdcca
Newline fix - the .js part
Jan 22, 2015
97beba9
Merge pull request #2 from biziclop/master
j-ro Jan 22, 2015
96c6a42
updating wordpress version
j-ro Apr 21, 2015
1718b02
updating version
j-ro Apr 24, 2015
e7fc1a8
wp 4.3 compat
j-ro Sep 29, 2015
b687c3f
touch
j-ro Sep 29, 2015
2035c33

j-ro Sep 29, 2015
f07cab3
update
j-ro Sep 29, 2015
d95aacd
touch
j-ro Sep 29, 2015
3216555
update
j-ro Sep 30, 2015
e3364a1
bump compat version
j-ro Dec 9, 2015
b890cdd
bump compatible version
j-ro Apr 13, 2016
830e853
fix description
j-ro Apr 30, 2016
bac5970
Exclude text widget editor
Azragh Dec 10, 2019
2a567fe
Merge pull request #3 from Azragh/patch-1
j-ro Dec 11, 2019
d8a9060
update contributors
j-ro Dec 11, 2019
35bbc5d
Update preserved_markup_plus.php
j-ro Dec 11, 2019
97711fe
update version and exempt text editor widget
j-ro Dec 11, 2019
a2b933a
Update deploy.sh
j-ro Dec 11, 2019
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
10 changes: 5 additions & 5 deletions admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}
});

if (tinymce.isIE) {
if (tinymce.isIE && tinymce.addUnload) {
tinymce.addUnload(function() {
ed.forceBlocks._previousFormats = 0; // Fix IE leak
});
Expand Down Expand Up @@ -246,7 +246,7 @@
edButtons[1] = new edButton('ed_em','i','<i>','</i>','i');
}

$('body').bind('afterPreWpautop', function(e, o) {
$('body:not(.widgets-php)').bind('afterPreWpautop', function(e, o) {
//On Switch to HTML & On save/update from Visual tab
//Now we replace all those temporary html comments with spaces and newlines
o.data = o.unfiltered;
Expand All @@ -260,7 +260,7 @@
o.data = o.data.replace(/\/\/ \]\]>/g, "");

//now decode newlines and tabs
o.data = o.data.replace(/<\!--mep-nl-->/g, "\r\n").replace(/<\!--mep-tab-->/g, " ");
o.data = o.data.replace(/(\r?\n|\s)?<\!--mep-nl-->/g, "\r\n").replace(/\s?<\!--mep-tab-->/g, " ");

//Fix broken >, <, &, etc symbols when they exist inside quote marks inside tag elements
o.data = fix_intra_tag_content("&amp;", o.data, "{-mep-amp}", "&");
Expand Down Expand Up @@ -322,7 +322,7 @@

//now: replace any newline characters with a custom mep html comment as a marker for where
//newline chars should be added back in when we're done
o.data = o.unfiltered.replace(/(\r\n|\n)/g, "<!--mep-nl-->").replace(/(\t|\s\s\s\s)/g, "<!--mep-tab-->");
o.data = o.unfiltered.replace(/(\r?\n)/g, "$1<!--mep-nl-->").replace(/(\t|\s\s\s\s)/g, " <!--mep-tab-->");

//finally: restore the whitespace back in pre & code tags
o.data = o.data.replace(/<mep-preserve-nl>/g, "\n").replace(/<mep-preserve-tab>/g, "\t").replace(/<mep-preserve-space>/g, " ");
Expand All @@ -331,4 +331,4 @@
o.data = o.data.replace(/"\/>/g, '" />');
});
});
})(jQuery);
})(jQuery);
253 changes: 253 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
#! /bin/bash
# See https://github.com/GaryJones/wordpress-plugin-svn-deploy for instructions and credits.
#
# Steps to deploying:
#
# 1. Ask for plugin slug.
# 2. Ask for local plugin directory.
# 3. Check local plugin directory exists.
# 4. Ask for main plugin file name.
# 5. Check main plugin file exists.
# 6. Check readme.txt version matches main plugin file version.
# 7. Ask for temporary SVN path.
# 8. Ask for remote SVN repo.
# 9. Ask for SVN username.
# 10. Ask if input is correct, and give chance to abort.
# 11. Check if Git tag exists for version number (must match exactly).
# 12. Checkout SVN repo.
# 13. Set to SVN ignore some GitHub-related files.
# 14. Export HEAD of master from git to the trunk of SVN.
# 15. Initialise and update and git submodules.
# 16. Move /trunk/assets up to /assets.
# 17. Move into /trunk, and SVN commit.
# 18. Move into /assets, and SVN commit.
# 19. Copy /trunk into /tags/{version}, and SVN commit.
# 20. Delete temporary local SVN checkout.

echo
echo "WordPress Plugin SVN Deploy v3.1.0"
echo
echo "Let's collect some information first. There are six questions."
echo
echo "Default values are in brackets - just hit enter to accept them."
echo

# Get some user input
# Can't use the -i flag for read, since that doesn't work for bash 3
printf "Q1. WordPress Repo Plugin Slug e.g. my-awesome-plugin: "
read -e PLUGINSLUG
echo

# Set up some default values. Feel free to change these in your own script
CURRENTDIR=$(pwd)
default_svnpath="/tmp/$PLUGINSLUG"
default_svnurl="https://plugins.svn.wordpress.org/$PLUGINSLUG"
default_svnuser="GaryJ"
default_plugindir="$CURRENTDIR/$PLUGINSLUG"
default_mainfile="$PLUGINSLUG.php"

echo "Q2. Your local plugin root directory (the Git repo)."
printf "($default_plugindir): "
read -e input
input="${input%/}" # Strip trailing slash
PLUGINDIR="${input:-$default_plugindir}" # Populate with default if empty
echo

# Check directory exists.
if [ ! -d "$PLUGINDIR" ]; then
echo "Directory $PLUGINDIR not found. Aborting."
exit 1;
fi

printf "Q3. Name of the main plugin file ($default_mainfile): "
read -e input
MAINFILE="${input:-$default_mainfile}" # Populate with default if empty
echo

# Check main plugin file exists.
if [ ! -f "$PLUGINDIR/$MAINFILE" ]; then
echo "Plugin file $PLUGINDIR/$MAINFILE not found. Aborting."
exit 1;
fi

echo "Checking version in main plugin file matches version in readme.txt file..."
echo

# Check version in readme.txt is the same as plugin file after translating both to Unix line breaks to work around grep's failure to identify Mac line breaks
PLUGINVERSION=$(grep -i "Version:" $PLUGINDIR/$MAINFILE | awk -F' ' '{print $NF}' | tr -d '\r')
echo "$MAINFILE version: $PLUGINVERSION"
READMEVERSION=$(grep -i "Stable tag:" $PLUGINDIR/readme.txt | awk -F' ' '{print $NF}' | tr -d '\r')
echo "readme.txt version: $READMEVERSION"

if [ "$READMEVERSION" = "trunk" ]; then
echo "Version in readme.txt & $MAINFILE don't match, but Stable tag is trunk. Let's continue..."
elif [ "$PLUGINVERSION" != "$READMEVERSION" ]; then
echo "Version in readme.txt & $MAINFILE don't match. Exiting...."
exit 1;
elif [ "$PLUGINVERSION" = "$READMEVERSION" ]; then
echo "Versions match in readme.txt and $MAINFILE. Let's continue..."
fi

echo

echo "Q4. Path to a local directory where a temporary SVN checkout can be made."
printf "Don't add trunk ($default_svnpath): "
read -e input
input="${input%/}" # Strip trailing slash
SVNPATH="${input:-$default_svnpath}" # Populate with default if empty
echo

echo "Q5. Remote SVN repo on WordPress.org."
printf "($default_svnurl): "
read -e input
input="${input%/}" # Strip trailing slash
SVNURL="${input:-$default_svnurl}" # Populate with default if empty
echo

printf "Q6. Your WordPress repo SVN username ($default_svnuser): "
read -e input
SVNUSER="${input:-$default_svnuser}" # Populate with default if empty
echo

echo "That's all of the data collected."
echo
echo "Slug: $PLUGINSLUG"
echo "Plugin directory: $PLUGINDIR"
echo "Main file: $MAINFILE"
echo "Temp checkout path: $SVNPATH"
echo "Remote SVN repo: $SVNURL"
echo "SVN username: $SVNUSER"
echo

printf "OK to proceed (Y|n)? "
read -e input
PROCEED="${input:-y}"
echo

# Allow user cancellation
if [ $(echo "$PROCEED" |tr [:upper:] [:lower:]) != "y" ]; then echo "Aborting..."; exit 1; fi

# Let's begin...
echo ".........................................."
echo
echo "Preparing to deploy WordPress plugin"
echo
echo ".........................................."
echo

echo

echo "Changing to $PLUGINDIR"
cd $PLUGINDIR

# Check for git tag (may need to allow for leading "v"?)
# if git show-ref --tags --quiet --verify -- "refs/tags/$PLUGINVERSION"
if git show-ref --tags --quiet --verify -- "refs/tags/$PLUGINVERSION"
then
echo "Git tag $PLUGINVERSION does exist. Let's continue..."
else
echo "$PLUGINVERSION does not exist as a git tag. Aborting.";
exit 1;
fi

echo

echo "Creating local copy of SVN repo trunk..."
svn checkout $SVNURL $SVNPATH --depth immediates
svn update --quiet $SVNPATH/trunk --set-depth infinity

echo "Ignoring GitHub specific files"
# Use local .svnignore if present
if [ -f ".svnignore" ]; then
echo "Using local .svnignore"
SVNIGNORE=$( <.svnignore )
else
echo "Using default .svnignore"
SVNIGNORE="README.md
Thumbs.db
.github
.git
.gitattributes
.gitignore
composer.lock"
fi

svn propset svn:ignore \""$SVNIGNORE"\" "$SVNPATH/trunk/"

echo "Exporting the HEAD of master from git to the trunk of SVN"
git checkout-index -a -f --prefix=$SVNPATH/trunk/

# If submodule exist, recursively check out their indexes
if [ -f ".gitmodules" ]
then
echo "Exporting the HEAD of each submodule from git to the trunk of SVN"
git submodule init
git submodule update
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
while read path_key path
do
#url_key=$(echo $path_key | sed 's/\.path/.url/')
#url=$(git config -f .gitmodules --get "$url_key")
#git submodule add $url $path
echo "This is the submodule path: $path"
echo "The following line is the command to checkout the submodule."
echo "git submodule foreach --recursive 'git checkout-index -a -f --prefix=$SVNPATH/trunk/$path/'"
git submodule foreach --recursive 'git checkout-index -a -f --prefix=$SVNPATH/trunk/$path/'
done
fi

echo

# Support for the /assets folder on the .org repo.
echo "Moving assets."
# Make the directory if it doesn't already exist
mkdir -p $SVNPATH/assets/
mv $SVNPATH/trunk/assets/* $SVNPATH/assets/
svn add --force $SVNPATH/assets/
svn delete --force $SVNPATH/trunk/assets

echo

echo "Changing directory to SVN and committing to trunk."
cd $SVNPATH/trunk/
# Delete all files that should not now be added.
# Use $SVNIGNORE for `rm -rf`. Setting propset svn:ignore seems flaky.
echo "$SVNIGNORE" | awk '{print $0}' | xargs rm -rf
svn status | grep -v "^.[ \t]*\..*" | grep "^\!" | awk '{print $2"@"}' | xargs svn del
# Add all new files that are not set to be ignored
svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2"@"}' | xargs svn add
svn commit --username=$SVNUSER -m "Preparing for $PLUGINVERSION release"

echo

echo "Updating WordPress plugin repo assets and committing."
cd $SVNPATH/assets/
# Delete all new files that are not set to be ignored
svn status | grep -v "^.[ \t]*\..*" | grep "^\!" | awk '{print $2"@"}' | xargs svn del
# Add all new files that are not set to be ignored
svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2"@"}' | xargs svn add
svn update --quiet --accept working $SVNPATH/assets/*
svn resolve --accept working $SVNPATH/assets/*
svn commit --username=$SVNUSER -m "Updating assets"

echo

echo "Creating new SVN tag and committing it."
cd $SVNPATH
svn copy --quiet trunk/ tags/$PLUGINVERSION/
# Remove assets and trunk directories from tag directory
svn delete --force --quiet $SVNPATH/tags/$PLUGINVERSION/assets
svn delete --force --quiet $SVNPATH/tags/$PLUGINVERSION/trunk
svn update --quiet --accept working $SVNPATH/tags/$PLUGINVERSION
#svn resolve --accept working $SVNPATH/tags/$PLUGINVERSION/*
cd $SVNPATH/tags/$PLUGINVERSION
svn commit --username=$SVNUSER -m "Tagging version $PLUGINVERSION"

echo

echo "Removing temporary directory $SVNPATH."
cd $SVNPATH
cd ..
rm -fr $SVNPATH/

echo "*** FIN ***"
29 changes: 18 additions & 11 deletions sb_preserved_markup.php → preserved_markup_plus.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?php

/*
Plugin Name: Preserved HTML Editor Markup
Plugin Name: Preserved HTML Editor Markup Plus
Plugin URI: http://www.marcuspope.com/wordpress/
Description: A Wordpress Plugin that preserves HTML markup in the TinyMCE editor, especially when switching between
html and visual tabs. Also adds support for HTML5 Block Anchors.
Author: Marcus E. Pope, marcuspope
Author: Marcus E. Pope, marcuspope, Jason Rosenbaum, J-Ro, Azragh, azragh
Author URI: http://www.marcuspope.com
Version: 1.5

Copyright 2011 Marcus E. Pope (email : me@marcuspope.com)
Version: 1.5.4

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
Expand Down Expand Up @@ -111,14 +109,21 @@ public static function init_tiny_mce($init) {
$init['fix_table_elements'] = false;
$init['verify_html'] = false;
$init['setup'] = 'emc2_tinymce_init';
$init['allow_script_urls'] = true;
$init['cleanup_on_startup'] = false;
$init['cleanup'] = false;
$init['validate_children'] = false;
$init['remove_redundant_brs'] = false;

$init['entities'] = '160,nbsp';

/*
Allow for html5 anchor tags
http://dev.w3.org/html5/markup/a.html
http://dev.w3.org/html5/markup/common-models.html#common.elem.phrasing
http://www.tinymce.com/wiki.php/Configuration:valid_children
*/
$init['valid_children'] = "+a[em|strong|small|mark|abbr|dfn|i|b|s|u|code|var|samp|kbd|sup|sub|q|cite|span|bdo|bdi|br|wbr|ins|del|img|embed|object|iframe|map|area|script|noscript|ruby|video|audio|input|textarea|select|button|label|output|datalist|keygen|progress|command|canvas|time|meter|p|hr|pre|ul|ol|dl|div|h1|h2|h3|h4|h5|h6|hgroup|address|blockquote|section|nav|article|aside|header|footer|figure|table|f|m|fieldset|menu|details]";
$init['valid_children'] = "+a[em|strong|small|mark|abbr|dfn|i|b|s|u|code|var|samp|kbd|sup|sub|q|cite|span|bdo|bdi|br|wbr|ins|del|img|embed|object|iframe|map|area|noscript|ruby|video|audio|input|textarea|select|button|label|output|datalist|keygen|progress|command|canvas|time|meter|p|hr|pre|ul|ol|dl|div|h1|h2|h3|h4|h5|h6|hgroup|address|blockquote|section|nav|article|aside|header|footer|figure|table|f|m|fieldset|menu|details|style|link],+body[style|link]";

return $init;
}
Expand Down Expand Up @@ -180,8 +185,8 @@ public static function fix_wysiwyg_content($c) {
//the html mode. FIXME: assuming four spaces is bad mmkay, what if I like only two spaces for a tab?
//and this could produce bad markup if a user had <p class="test">hello</p> in their markup. So
//work on a more flexible /\s/g approach when \s is inside or outside a tag definition
$c = preg_replace("/(\r\n|\n)/", "<!--mep-nl-->", $c); //preserve new lines
$c = preg_replace("/(\t|\s\s\s\s)/", "<!--mep-tab-->", $c); //preserve indents
$c = preg_replace("/(\r?\n)/", "\n<!--mep-nl-->", $c); //preserve new lines
$c = preg_replace("/(\t|\s\s\s\s)/", " <!--mep-tab-->", $c); //preserve indents

//Now we can restore all whitespace originally escaped in pre & code tags
$c = preg_replace("/<mep-preserve-nl>/m", "\n", $c);
Expand All @@ -208,8 +213,8 @@ public static function fix_post_content($post) {
//issue was caused by a js error in that function that resulted in nothing being stripped out before it was
//posted to the server here:
if (isset($post['post_content'])) {
$post['post_content'] = preg_replace('/<\!--mep-nl-->/m', "\r\n", $post['post_content']);
$post['post_content'] = preg_replace('/<\!--mep-tab-->/m', " ", $post['post_content']);
$post['post_content'] = preg_replace('/(\r?\n|\s)?<\!--mep-nl-->/m', "\r\n", $post['post_content']);
$post['post_content'] = preg_replace('/\s?<\!--mep-tab-->/m', " ", $post['post_content']);
$post['post_content'] = preg_replace_callback(
'/<code style=[\'"]display: none;[\'"]><!--[\s\S]*?--><\/code>/m',
array(
Expand Down Expand Up @@ -306,7 +311,7 @@ public static function admin_init() {
$plugin_data = get_plugin_data(__FILE__);
$cachebuster = $plugin_data['Version'];

wp_enqueue_script('emc2-pm-admin-js', WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__))."admin.js?v=".$cachebuster);
wp_enqueue_script('emc2-pm-admin-js', plugins_url("admin.js?v=".$cachebuster, __FILE__));
//wp_enqueue_script('emc2-pm-admin-js', WP_PLUGIN_URL.'/sb_preserved_markup/admin.js');

//provide nonce for ajax calls
Expand All @@ -319,10 +324,12 @@ public static function admin_init() {
'fix_editor_content'
), 1);

/*
add_filter('the_editor_content', array(
'MP_WP_Preserved_Markup',
'fix_wysiwyg_content'
), 1);
*/

add_filter('wp_insert_post_data', array(
'MP_WP_Preserved_Markup',
Expand Down
Loading