mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-05 05:04:31 +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:
@@ -355,82 +355,9 @@ class Test_WP_Customize_Custom_CSS_Setting extends WP_UnitTestCase {
|
||||
$result = $this->setting->validate( $basic_css );
|
||||
$this->assertTrue( $result );
|
||||
|
||||
// Check for Unclosed Comment.
|
||||
$unclosed_comment = $basic_css . ' /* This is a comment. ';
|
||||
// Check for markup.
|
||||
$unclosed_comment = $basic_css . '</style>';
|
||||
$result = $this->setting->validate( $unclosed_comment );
|
||||
$this->assertTrue( array_key_exists( 'unclosed_comment', $result->errors ) );
|
||||
|
||||
// Check for Unopened Comment.
|
||||
$unclosed_comment = $basic_css . ' This is a comment.*/';
|
||||
$result = $this->setting->validate( $unclosed_comment );
|
||||
$this->assertTrue( array_key_exists( 'imbalanced_comments', $result->errors ) );
|
||||
|
||||
// Check for Unclosed Curly Brackets.
|
||||
$unclosed_curly_bracket = $basic_css . ' a.link { text-decoration: none;';
|
||||
$result = $this->setting->validate( $unclosed_curly_bracket );
|
||||
$this->assertTrue( array_key_exists( 'imbalanced_curly_brackets', $result->errors ) );
|
||||
|
||||
// Check for Unopened Curly Brackets.
|
||||
$unopened_curly_bracket = $basic_css . ' a.link text-decoration: none; }';
|
||||
$result = $this->setting->validate( $unopened_curly_bracket );
|
||||
$this->assertTrue( array_key_exists( 'imbalanced_curly_brackets', $result->errors ) );
|
||||
|
||||
// Check for Unclosed Braces.
|
||||
$unclosed_brace = $basic_css . ' input[type="text" { color: #f00; } ';
|
||||
$result = $this->setting->validate( $unclosed_brace );
|
||||
$this->assertTrue( array_key_exists( 'imbalanced_braces', $result->errors ) );
|
||||
|
||||
// Check for Unopened Braces.
|
||||
$unopened_brace = $basic_css . ' inputtype="text"] { color: #f00; } ';
|
||||
$result = $this->setting->validate( $unopened_brace );
|
||||
$this->assertTrue( array_key_exists( 'imbalanced_braces', $result->errors ) );
|
||||
|
||||
// Check for Imbalanced Double Quotes.
|
||||
$imbalanced_double_quotes = $basic_css . ' div.background-image { background-image: url( "image.jpg ); } ';
|
||||
$result = $this->setting->validate( $imbalanced_double_quotes );
|
||||
$this->assertTrue( array_key_exists( 'unequal_double_quotes', $result->errors ) );
|
||||
|
||||
// Check for Unclosed Parentheses.
|
||||
$unclosed_parentheses = $basic_css . ' div.background-image { background-image: url( "image.jpg" ; } ';
|
||||
$result = $this->setting->validate( $unclosed_parentheses );
|
||||
$this->assertTrue( array_key_exists( 'imbalanced_parentheses', $result->errors ) );
|
||||
|
||||
// Check for Unopened Parentheses.
|
||||
$unopened_parentheses = $basic_css . ' div.background-image { background-image: url "image.jpg" ); } ';
|
||||
$result = $this->setting->validate( $unopened_parentheses );
|
||||
$this->assertTrue( array_key_exists( 'imbalanced_parentheses', $result->errors ) );
|
||||
|
||||
// A basic Content declaration with no other errors should not throw an error.
|
||||
$content_declaration = $basic_css . ' a:before { content: ""; display: block; }';
|
||||
$result = $this->setting->validate( $content_declaration );
|
||||
$this->assertTrue( $result );
|
||||
|
||||
// An error, along with a Content declaration will throw two errors.
|
||||
// In this case, we're using an extra opening brace.
|
||||
$content_declaration = $basic_css . ' a:before { content: "["; display: block; }';
|
||||
$result = $this->setting->validate( $content_declaration );
|
||||
$this->assertTrue( array_key_exists( 'imbalanced_braces', $result->errors ) );
|
||||
$this->assertTrue( array_key_exists( 'possible_false_positive', $result->errors ) );
|
||||
|
||||
$css = 'body { background: #f00; } h1.site-title { font-size: 36px; } a:hover { text-decoration: none; } input[type="text"] { padding: 1em; } /* This is a comment */';
|
||||
$this->assertTrue( $this->setting->validate( $css ) );
|
||||
|
||||
$validity = $this->setting->validate( $css . ' /* This is another comment.' );
|
||||
$this->assertInstanceOf( 'WP_Error', $validity );
|
||||
$this->assertContains( 'unclosed code comment', join( ' ', $validity->get_error_messages() ) );
|
||||
|
||||
$css = '/* This is comment one. */ /* This is comment two. */';
|
||||
$this->assertTrue( $this->setting->validate( $css ) );
|
||||
|
||||
$basic_css = 'body { background: #f00; } h1.site-title { font-size: 36px; } a:hover { text-decoration: none; } input[type="text"] { padding: 1em; }';
|
||||
$this->assertTrue( $this->setting->validate( $basic_css ) );
|
||||
|
||||
$css = $basic_css . ' .link:before { content: "*"; display: block; }';
|
||||
$this->assertTrue( $this->setting->validate( $css ) );
|
||||
|
||||
$css .= ' ( trailing';
|
||||
$validity = $this->setting->validate( $css );
|
||||
$this->assertWPError( $validity );
|
||||
$this->assertNotEmpty( $result->get_error_message( 'possible_false_positive' ) );
|
||||
$this->assertTrue( array_key_exists( 'illegal_markup', $result->errors ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2351,7 +2351,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
$data = json_decode( $json, true );
|
||||
$this->assertNotEmpty( $data );
|
||||
|
||||
$this->assertEqualSets( array( 'theme', 'url', 'browser', 'panels', 'sections', 'nonce', 'autofocus', 'documentTitleTmpl', 'previewableDevices', 'changeset', 'timeouts' ), array_keys( $data ) );
|
||||
$this->assertEqualSets( array( 'theme', 'url', 'browser', 'panels', 'sections', 'nonce', 'autofocus', 'documentTitleTmpl', 'previewableDevices', 'customCss', 'changeset', 'timeouts' ), array_keys( $data ) );
|
||||
$this->assertEquals( $autofocus, $data['autofocus'] );
|
||||
$this->assertArrayHasKey( 'save', $data['nonce'] );
|
||||
$this->assertArrayHasKey( 'preview', $data['nonce'] );
|
||||
|
||||
@@ -358,7 +358,7 @@ class Tests_User extends WP_UnitTestCase {
|
||||
// Test update of fields in _get_additional_user_keys()
|
||||
$user_data = array(
|
||||
'ID' => self::$author_id, 'use_ssl' => 1, 'show_admin_bar_front' => 1,
|
||||
'rich_editing' => 1, 'first_name' => 'first', 'last_name' => 'last',
|
||||
'rich_editing' => 1, 'syntax_highlighting' => 1, 'first_name' => 'first', 'last_name' => 'last',
|
||||
'nickname' => 'nick', 'comment_shortcuts' => 'true', 'admin_color' => 'classic',
|
||||
'description' => 'describe'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user