Skip to content

Commit a2ae8d6

Browse files
authored
Merge pull request #377 from KevinBatdorf/fix-quote-parse-issue
2 parents 1276a0f + f274a84 commit a2ae8d6

11 files changed

Lines changed: 91 additions & 51 deletions

File tree

cypress/e2e/extra-settings.cy.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ context('Extra Settings', () => {
3131
codeOutput: '<script><</script>',
3232
});
3333

34-
cy.findBlock('code-block-pro', 'pre')
34+
cy.findBlock('code-block-pro', '> div > div > pre')
3535
.invoke('html')
3636
.should('not.contain', encodeURI('<'));
3737

3838
cy.previewCurrentPage();
3939

40-
cy.get('.wp-block-kevinbatdorf-code-block-pro pre')
40+
cy.get('.wp-block-kevinbatdorf-code-block-pro pre.shiki')
4141
.should('exist')
4242
.should('contain', '<script><</script>');
4343
});
@@ -49,13 +49,13 @@ context('Extra Settings', () => {
4949

5050
cy.addCode('<script>&lt;</script>');
5151

52-
cy.findBlock('code-block-pro', 'pre')
52+
cy.findBlock('code-block-pro', '> div > div > pre')
5353
.invoke('html')
5454
.should('contain', '>lt</span>'); // formatted with highlighter
5555

5656
cy.previewCurrentPage();
5757

58-
cy.get('.wp-block-kevinbatdorf-code-block-pro pre')
58+
cy.get('.wp-block-kevinbatdorf-code-block-pro pre.shiki')
5959
.should('exist')
6060
.should('contain', '<script>&lt;</script>');
6161
});
@@ -68,12 +68,12 @@ context('Extra Settings', () => {
6868

6969
cy.setLanguage('plaintext');
7070
cy.addCode('[embed]foo[/embed]');
71-
cy.findBlock('code-block-pro', 'pre')
71+
cy.findBlock('code-block-pro', '> div > div > pre')
7272
.invoke('html')
7373
.should('contain', '[embed]foo[/embed]'); // Doesn't render
7474

7575
cy.previewCurrentPage();
76-
cy.get('.wp-block-kevinbatdorf-code-block-pro pre')
76+
cy.get('.wp-block-kevinbatdorf-code-block-pro pre.shiki')
7777
.should('exist')
7878
.invoke('html')
7979
.should('contain', '<a href="http://foo">foo</a>'); // Renders
@@ -82,12 +82,12 @@ context('Extra Settings', () => {
8282
cy.focusBlock('code-block-pro');
8383
cy.openSideBarPanel('Extra Settings');
8484
cy.get('[data-cy="use-escape-shortcodes"]').check();
85-
cy.findBlock('code-block-pro', 'pre')
85+
cy.findBlock('code-block-pro', '> div > div > pre')
8686
.invoke('html')
8787
.should('contain', '[embed]foo[/embed]'); // Doesn't render
8888

8989
cy.previewCurrentPage();
90-
cy.get('.wp-block-kevinbatdorf-code-block-pro pre')
90+
cy.get('.wp-block-kevinbatdorf-code-block-pro pre.shiki')
9191
.should('exist')
9292
.invoke('html')
9393
.should('contain', '[embed]foo[/embed]'); // Doesn't render

cypress/e2e/height.cy.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ context('Max Height', () => {
7171

7272
cy.previewCurrentPage();
7373

74-
cy.contains('foo = "5"').should('not.be.visible');
74+
cy.get('.line').contains('foo = "5"').should('not.be.visible');
7575

7676
cy.get('.cbp-see-more-simple-btn')
7777
.should('have.attr', 'aria-expanded', 'false')
7878
.click();
7979

80-
cy.contains('foo = "5"').should('be.visible');
80+
cy.get('.line').contains('foo = "5"').should('be.visible');
8181

8282
cy.get('.cbp-see-more-simple-btn').should('not.exist');
8383
});
@@ -123,7 +123,7 @@ context('Max Height', () => {
123123

124124
cy.previewCurrentPage();
125125

126-
cy.contains('foo = "5"').should('not.be.visible');
126+
cy.get('.line').contains('foo = "5"').should('not.be.visible');
127127

128128
cy.get('.cbp-see-more-simple-btn')
129129
.should('exist')
@@ -136,7 +136,7 @@ context('Max Height', () => {
136136
'true',
137137
);
138138

139-
cy.contains('foo = "5"').should('be.visible');
139+
cy.get('.line').contains('foo = "5"').should('be.visible');
140140

141141
cy.get('.cbp-see-more-simple-btn').should(
142142
'have.text',
@@ -188,9 +188,9 @@ context('Max Height', () => {
188188

189189
cy.previewCurrentPage();
190190

191-
cy.contains('foo = "5"').should('not.be.visible');
191+
cy.get('.line').contains('foo = "5"').should('not.be.visible');
192192
cy.get('.cbp-see-more-simple-btn').click();
193-
cy.contains('foo = "5"').should('be.visible');
193+
cy.get('.line').contains('foo = "5"').should('be.visible');
194194
cy.get('.cbp-see-more-simple-btn').should('not.exist');
195195

196196
cy.go('back');
@@ -208,7 +208,7 @@ context('Max Height', () => {
208208

209209
cy.previewCurrentPage();
210210

211-
cy.contains('foo = "5"').should('not.be.visible');
211+
cy.get('.line').contains('foo = "5"').should('not.be.visible');
212212
cy.get('.cbp-see-more-simple-btn').should('not.exist');
213213
});
214214

cypress/e2e/misc.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ context('Miscellaneous', () => {
2323
it('Persists settings', () => {
2424
cy.addCode('const foo = "bar";');
2525
cy.setTheme('dracula');
26-
cy.findBlock('code-block-pro', 'pre')
26+
cy.findBlock('code-block-pro', '> div > div > pre')
2727
.invoke('html')
2828
.should('contain', '<span style="color: #FF79C6">const</span>');
2929

@@ -35,7 +35,7 @@ context('Miscellaneous', () => {
3535

3636
// confirm theme is persisted
3737
cy.addCode('const foo = "bar";');
38-
cy.findBlock('code-block-pro', 'pre')
38+
cy.findBlock('code-block-pro', '> div > div > pre')
3939
.invoke('html')
4040
.should('contain', '<span style="color: #FF79C6">const</span>');
4141
});

cypress/e2e/padding.cy.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ afterEach(() => {
2626
});
2727
context('Line numbers', () => {
2828
it('Line numbers disabled, padding enabled', () => {
29-
cy.findBlock('code-block-pro', 'pre').should(
29+
cy.findBlock('code-block-pro', '> div > div > pre').should(
3030
'have.css',
3131
'padding',
3232
'16px 0px 16px 16px',
@@ -39,13 +39,13 @@ context('Line numbers', () => {
3939
cy.addCode('line 1\nline 2\nline 3');
4040
cy.previewCurrentPage();
4141

42-
cy.get('.wp-block-kevinbatdorf-code-block-pro pre')
42+
cy.get('.wp-block-kevinbatdorf-code-block-pro pre.shiki')
4343
.should('exist')
4444
.should('have.css', 'padding', '16px 0px 16px 16px');
4545
});
4646

4747
it('Line numbers disabled, padding disabled', () => {
48-
cy.findBlock('code-block-pro', 'pre').should(
48+
cy.findBlock('code-block-pro', '> div > div > pre').should(
4949
'have.css',
5050
'padding',
5151
'16px 0px 16px 16px',
@@ -60,7 +60,7 @@ context('Line numbers', () => {
6060
cy.get('[data-cy="disable-padding"').check();
6161
cy.get('[data-cy="disable-padding"').should('be.checked');
6262

63-
cy.findBlock('code-block-pro', 'pre').should(
63+
cy.findBlock('code-block-pro', '> div > div > pre').should(
6464
'have.css',
6565
'padding',
6666
'0px',
@@ -72,7 +72,7 @@ context('Line numbers', () => {
7272

7373
cy.previewCurrentPage();
7474

75-
cy.get('.wp-block-kevinbatdorf-code-block-pro pre')
75+
cy.get('.wp-block-kevinbatdorf-code-block-pro pre.shiki')
7676
.should('exist')
7777
.should('have.css', 'padding', '0px');
7878
});
@@ -93,7 +93,7 @@ context('Line numbers', () => {
9393

9494
cy.previewCurrentPage();
9595

96-
cy.get('.wp-block-kevinbatdorf-code-block-pro pre')
96+
cy.get('.wp-block-kevinbatdorf-code-block-pro pre.shiki')
9797
.should('exist')
9898
.should('have.css', 'padding', '16px 0px 16px 16px');
9999
});
@@ -130,7 +130,7 @@ context('Line numbers', () => {
130130

131131
cy.previewCurrentPage();
132132

133-
cy.get('.wp-block-kevinbatdorf-code-block-pro pre')
133+
cy.get('.wp-block-kevinbatdorf-code-block-pro pre.shiki')
134134
.should('exist')
135135
.should('have.css', 'padding', '0px');
136136
});

cypress/e2e/themes.cy.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ context('Theme checks', () => {
2626
// Nord is the default
2727
cy.addCode('const foo = "bar";');
2828
cy.setTheme('nord');
29-
cy.findBlock('code-block-pro', 'pre')
29+
cy.findBlock('code-block-pro', '> div > div > pre')
3030
.invoke('html')
3131
.should('contain', '<span style="color: #81A1C1">const</span>');
3232

3333
cy.setTheme('dracula');
34-
cy.findBlock('code-block-pro', 'pre')
34+
cy.findBlock('code-block-pro', '> div > div > pre')
3535
.invoke('html')
3636
.should('contain', '<span style="color: #FF79C6">const</span>');
3737

3838
cy.setTheme('rose-pine-dawn');
39-
cy.findBlock('code-block-pro', 'pre')
39+
cy.findBlock('code-block-pro', '> div > div > pre')
4040
.invoke('html')
4141
.should('contain', '<span style="color: #286983">const</span>');
4242

php/compatibility.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,11 @@
1111
if (!class_exists('Prismatic')) {
1212
class Prismatic
1313
{
14-
public static function options_general()
15-
{
16-
}
17-
public static function options_advanced()
18-
{
19-
}
20-
public static function options_prism()
21-
{
22-
}
23-
public static function options_highlight()
24-
{
25-
}
26-
public static function options_plain()
27-
{
28-
}
29-
}
30-
function prismatic()
31-
{
14+
public static function options_general() {}
15+
public static function options_advanced() {}
16+
public static function options_prism() {}
17+
public static function options_highlight() {}
18+
public static function options_plain() {}
3219
}
20+
function prismatic() {}
3321
}

readme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ Themes are rendered inside the editor as you type or make changes, so the code b
313313

314314
== Changelog ==
315315

316+
- Prevents wp_texturize from affecting copied code snippets. You will see a block update for this change as I had to wrap the code in a pre tag.
317+
316318
= 1.27.3 - 2025-05-15 =
317319
- Prevents smart quotes, typographic dashes, and other non-ASCII characters from affecting copied code snippets.
318320

src/editor/components/buttons/copy/CopyButton.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,17 @@ export const CopyButton = ({ attributes }: { attributes: Attributes }) => {
6767
aria-live={hasTextButton ? 'polite' : undefined}
6868
className="code-block-pro-copy-button">
6969
{copyButtonUseTextarea ? (
70-
<textarea
71-
className="code-block-pro-copy-button-textarea"
72-
aria-hidden="true"
73-
readOnly
74-
value={codeToCopy}
75-
/>
70+
<pre
71+
className="code-block-pro-copy-button-pre"
72+
aria-hidden="true">
73+
<textarea
74+
className="code-block-pro-copy-button-textarea"
75+
tabIndex={-1}
76+
aria-hidden="true"
77+
readOnly
78+
value={codeToCopy}
79+
/>
80+
</pre>
7681
) : null}
7782
<Component text={copyButtonString} />
7883
</span>

src/front/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
@apply bg-transparent;
173173
}
174174
/* Keep this selector aggressively specific */
175+
body .wp-block-kevinbatdorf-code-block-pro:not(#x) .code-block-pro-copy-button-pre,
175176
body .wp-block-kevinbatdorf-code-block-pro:not(#x) .code-block-pro-copy-button-textarea {
176177
clip: rect(0, 0, 0, 0);
177178
@apply absolute top-0 left-0 w-px h-px opacity-0 pointer-events-none -m-1 overflow-hidden resize-none border-0 shadow-none bg-transparent text-transparent whitespace-nowrap;

src/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { transformToCBP, transformFromCBP } from './editor/transforms';
99
import { BlockOutput } from './front/BlockOutput';
1010
import { blockIcon } from './icons';
1111
import { Attributes } from './types';
12+
import { handleValidationErrors } from './util/errors';
13+
14+
handleValidationErrors();
1215

1316
registerBlockType<Attributes>(blockConfig.name, {
1417
...blockConfig,

0 commit comments

Comments
 (0)