mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 07:40:07 +00:00
Editor: Add CodeMirror-powered code editor with syntax highlighting, linting, and auto-completion.
* Code editor is integrated into the Theme/Plugin Editor, Additional CSS in Customizer, and Custom HTML widget. Code editor is not yet integrated into the post editor, and it may not be until accessibility concerns are addressed. * The CodeMirror component in the Custom HTML widget is integrated in a similar way to TinyMCE being integrated into the Text widget, adopting the same approach for integrating dynamic JavaScript-initialized fields. * Linting is performed for JS, CSS, HTML, and JSON via JSHint, CSSLint, HTMLHint, and JSONLint respectively. Linting is not yet supported for PHP. * When user lacks `unfiltered_html` the capability, the Custom HTML widget will report any Kses-invalid elements and attributes as errors via a custom Kses rule for HTMLHint. * When linting errors are detected, the user will be prevented from saving the code until the errors are fixed, reducing instances of broken websites. * The placeholder value is removed from Custom CSS in favor of a fleshed-out section description which now auto-expands when the CSS field is empty. See #39892. * The CodeMirror library is included as `wp.CodeMirror` to prevent conflicts with any existing `CodeMirror` global. * An `wp.codeEditor.initialize()` API in JS is provided to convert a `textarea` into CodeMirror, with a `wp_enqueue_code_editor()` function in PHP to manage enqueueing the assets and settings needed to edit a given type of code. * A user preference is added to manage whether or not "syntax highlighting" is enabled. The feature is opt-out, being enabled by default. * Allowed file extensions in the theme and plugin editors have been updated to include formats which CodeMirror has modes for: `conf`, `css`, `diff`, `patch`, `html`, `htm`, `http`, `js`, `json`, `jsx`, `less`, `md`, `php`, `phtml`, `php3`, `php4`, `php5`, `php7`, `phps`, `scss`, `sass`, `sh`, `bash`, `sql`, `svg`, `xml`, `yml`, `yaml`, `txt`. Props westonruter, georgestephanis, obenland, melchoyce, pixolin, mizejewski, michelleweber, afercia, grahamarmfield, samikeijonen, rianrietveld, iseulde. See #38707. Fixes #12423, #39892. git-svn-id: https://develop.svn.wordpress.org/trunk@41376 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
62
src/wp-admin/css/code-editor.css
Normal file
62
src/wp-admin/css/code-editor.css
Normal file
@@ -0,0 +1,62 @@
|
||||
.wrap [class*="CodeMirror-lint-marker"],
|
||||
.wp-core-ui [class*="CodeMirror-lint-message"],
|
||||
.wrap .CodeMirror-lint-marker-multiple {
|
||||
background-image: none;
|
||||
}
|
||||
|
||||
.wrap [class*="CodeMirror-lint-marker"]:before {
|
||||
font: normal 18px/1 dashicons;
|
||||
position: relative;
|
||||
top: -2px;
|
||||
}
|
||||
|
||||
.wp-core-ui [class*="CodeMirror-lint-message"]:before {
|
||||
font: normal 16px/1 dashicons;
|
||||
left: 16px;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.wp-core-ui .CodeMirror-lint-message-error,
|
||||
.wp-core-ui .CodeMirror-lint-message-warning {
|
||||
box-shadow: 0 1px 1px 0 rgba( 0, 0, 0, 0.1 );
|
||||
margin: 5px 0 2px;
|
||||
padding: 3px 12px 3px 28px;
|
||||
}
|
||||
|
||||
.wp-core-ui .CodeMirror-lint-message-warning {
|
||||
background-color: #fff8e5;
|
||||
border-left: 4px solid #ffb900;
|
||||
}
|
||||
|
||||
.wrap .CodeMirror-lint-marker-warning:before,
|
||||
.wp-core-ui .CodeMirror-lint-message-warning:before {
|
||||
content: "\f534";
|
||||
color: #f6a306;
|
||||
}
|
||||
|
||||
.wp-core-ui .CodeMirror-lint-message-error {
|
||||
background-color: #fbeaea;
|
||||
border-left: 4px solid #dc3232;
|
||||
}
|
||||
|
||||
.wrap .CodeMirror-lint-marker-error:before,
|
||||
.wp-core-ui .CodeMirror-lint-message-error:before {
|
||||
content: "\f153";
|
||||
color: #dc3232;
|
||||
}
|
||||
|
||||
.wp-core-ui .CodeMirror-lint-tooltip {
|
||||
background: none;
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
direction: ltr;
|
||||
}
|
||||
|
||||
.wrap .CodeMirror .CodeMirror-matchingbracket {
|
||||
background: rgba(255, 150, 0, .3);
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.CodeMirror {
|
||||
text-align: left;
|
||||
}
|
||||
@@ -2200,7 +2200,7 @@ h1.nav-tab-wrapper, /* Back-compat for pre-4.4 */
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
#template div {
|
||||
#template > div {
|
||||
margin-right: 190px;
|
||||
}
|
||||
|
||||
@@ -3015,13 +3015,18 @@ img {
|
||||
#template textarea {
|
||||
font-family: Consolas, Monaco, monospace;
|
||||
font-size: 13px;
|
||||
width: 97%;
|
||||
background: #f9f9f9;
|
||||
-moz-tab-size: 4;
|
||||
-o-tab-size: 4;
|
||||
tab-size: 4;
|
||||
}
|
||||
|
||||
#template textarea,
|
||||
#template .CodeMirror {
|
||||
width: 97%;
|
||||
height: calc( 100vh - 220px );
|
||||
}
|
||||
|
||||
/* rtl:ignore */
|
||||
#template textarea,
|
||||
#docs-list {
|
||||
@@ -3032,6 +3037,25 @@ img {
|
||||
width: 97%;
|
||||
}
|
||||
|
||||
#file-editor-linting-error {
|
||||
margin-top: 1em;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
#file-editor-linting-error > .notice {
|
||||
margin: 0;
|
||||
display: inline-block;
|
||||
}
|
||||
#file-editor-linting-error > .notice > p {
|
||||
width: auto;
|
||||
}
|
||||
#template .submit {
|
||||
margin-top: 1em;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#template .submit input[type=submit][disabled] {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
#templateside {
|
||||
float: right;
|
||||
width: 190px;
|
||||
@@ -3585,12 +3609,13 @@ img {
|
||||
margin-top: -5px;
|
||||
}
|
||||
|
||||
#template div {
|
||||
#template > div {
|
||||
float: none;
|
||||
margin: 0;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
#template .CodeMirror,
|
||||
#template textarea {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@@ -550,6 +550,20 @@ p.customize-section-description {
|
||||
margin-top: 22px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.customize-section-description ul {
|
||||
margin-left: 1em;
|
||||
}
|
||||
.customize-section-description ul > li {
|
||||
list-style: disc;
|
||||
}
|
||||
.section-description-buttons {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.section-description-buttons button.button-link {
|
||||
color: #0073aa;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.customize-control {
|
||||
width: 100%;
|
||||
@@ -1154,6 +1168,19 @@ p.customize-section-description {
|
||||
margin-bottom: -12px;
|
||||
}
|
||||
|
||||
.customize-section-description-container + #customize-control-custom_css:last-child .CodeMirror {
|
||||
height: calc( 100vh - 185px );
|
||||
}
|
||||
.CodeMirror-lint-tooltip,
|
||||
.CodeMirror-hints {
|
||||
z-index: 500000 !important;
|
||||
}
|
||||
|
||||
.customize-section-description-container + #customize-control-custom_css:last-child .customize-control-notifications-container {
|
||||
margin-left: 12px;
|
||||
margin-right: 12px;
|
||||
}
|
||||
|
||||
@media screen and ( max-width: 640px ) {
|
||||
.customize-section-description-container + #customize-control-custom_css:last-child {
|
||||
margin-right: 0;
|
||||
|
||||
@@ -645,6 +645,20 @@ div#widgets-right .widget-top:hover,
|
||||
line-height: 1.4em;
|
||||
}
|
||||
|
||||
.custom-html-widget-fields > p > .CodeMirror {
|
||||
border: 1px solid #e5e5e5;
|
||||
}
|
||||
.custom-html-widget-fields code {
|
||||
padding-top: 1px;
|
||||
padding-bottom: 1px;
|
||||
}
|
||||
ul.CodeMirror-hints {
|
||||
z-index: 101; /* Due to z-index 100 set on .widget.open */
|
||||
}
|
||||
.widget-control-actions .custom-html-widget-save-button.button.validation-blocked {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* =Media Queries
|
||||
-------------------------------------------------------------- */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user