Add syntax highlighting in the Classic Post & Page HTML text editor, Gutenberg Code Editor, and Theme & Plugin editors using Codemirror.js
I don't use wordpress anymore and don't have the time to maintain this code. It still appears to work with the most recent version of wordpress (v6.1). I you would like to contribute, send me a message.
There was a v3 in the works that uses the Monaco code editor rather than CodeMirror. Its on github as WPcode, but I don't have time for that either.
[shortcodes/]
Ctrl+S
(Cmd+S
on Mac)F11
/Esc
hotkeysIf you are not a developer, please use the HTML Editor Syntax Highlighter plugin page on WordPress.org to download and install it. You can also download the latest release from here.
If you're a regular user of this plugin, please consider taking a short User Experience Survey to provide feedback that will help shape the new version 3.0.
Please report any issues or suggestions.
npm install -g gulp-cli
.npm install
on the project folder.gulp build
to build the project.Running gulp
will build the project and run it in a watch state. Making any changes to files will automatically rebuild the project. Install the LiveReload chrome browser extension and the page will reload when the project rebuilds.
Don't manually edit the release
branch. Only merge master
into the release
branch to update it
master
branchreadme.txt
& ChangeLog.md
readme.txt
gulp package
compiling to vX.X.X
release
branch dist folderrelease
with the version number in the commit note: updating to vX.X.X
.vX.X.X @ Target:release
, Add relevant release notes from ChangeLog.md
svn co https://plugins.svn.wordpress.org/html-editor-syntax-highlighter/
/trunk
(TODO: better way?)svn stat
and/or svn diff
on the SVN repo and make sure the changes look correctsvn ci -m "committing version X.X.X to trunk"
svn cp trunk tags/X.X.X
to make a tagged copy in the tags foldersvn ci -m "tagging version X.X.X"
and release the new version to the worldPaste this code in the editor to test out all the different syntax highlighting features.
<div>
[shortcode attribute="value" standAloneAttribute bool=true int=42 ]
[oneliner noquotes=stringvaluewithnospaces]
[self-closing-syntax html='<label class="name">Label</label>' /]
shortcode content
<a href="#">nested html</a>
[[escapedshortcode]]
[ [brackets that-dont-count]]
[/shortcode]
</div>
a really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really long line that should wrap and indent properly
<!--more WordPress More Tag Text --><!--noteaser--><!--nextpage-->
<!--HTML comment--><!--[shortcode]-->
<div style=" width:200px; height:400px; ">styled div</div>
<style>
/* css comment */
#identifier, .class{
width:200px;
height:400px;
}
/* square brackets in css block */
element[attribute="value"]{ color:red; }
</style>
<input onclick=" document.getElementById('identifier').style.width = '200px'; "/>
<script>
// javascript comment
var obj = {
key: value,
keytwo: valuetwo,
array: ['valueone', 'valuetwo'] // square brackets in javascript block
};
document.getElementById('identifier').style.width = '200px';
var string = '</script' + '>'; // writing this straight out will break the mix
</script>
ERRORS!
[/matchlessEndTag]<div class="right after error"></div>
[shortcode no_square_brackets='aa[<div here="whatever" adn=" ></div>]aaa']
[no/special|characters\in*shortcode^names or.attribute`names=error /]
& ડ 	 &error
<?php
// this is meta highlighting
[shortcode]
<div class="something"></div>
$var = 'value';
?>
For promotional text:
<h1>HTML Editor Syntax Highlighter</h1>
<p class="description">
Add syntax highlighting to the Classic Text Editor, Gutenberg Code Editor, and Theme & Plugin Editors. It also highlights [[shortcodes]] like HTML!
[shortcode attribute="value" standAloneAttribute bool=true int=42 /]
</p>
<div>
[shortcode ]
[oneliner html='<label class="name">Label</label>']
shortcode content
<a href="#">nested html</a>
[[escapedshortcode]]
[/shortcode]
</div>
<!--more WordPress More Tag Text --><!--noteaser--><!--nextpage-->
<!-- HTML comment --><!-- commented out [shortcode] -->
<p>It works with inline CSS!</p>
<style> /* css comment */
#identifier, .class, element[attribute="value"] {
width: 200px;
color: rebeccapurple;
}
</style>
<p>It works with inline JavaScript Too!</p>
<script> // javascript comment
var obj = {
key: value,
number: 200,
array: ['valueone', 'valuetwo']
};
document.getElementById('identifier').style.width = obj.number + 'px';
</script>