$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>formatting - Images that copy code to clipboard when you click on them|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

formatting - Images that copy code to clipboard when you click on them

matteradmin8PV0评论

I run a website about a programming language which is very well-integrated with a front-end which adds a lot of styling to the code that cannot be replicated in the browser. For that reason, I publish my tutorials by having blocks of text interspersed with images of code. Clicking on the images copies the code to the clipboard so that people can use them in their own front-end. Here is what the HTML code for this looks like:

<img src="..." />
<textarea>code goes here</textarea>

The textarea element is hidden using CSS. This used to work because I had disabled wpautop but now that I upgraded to Gutenberg, this doesn't seem to be an option anymore. Now it inserts <br /> tags in my content.

What is a long-term, proper solution to this problem? Can blocks help me?

I run a website about a programming language which is very well-integrated with a front-end which adds a lot of styling to the code that cannot be replicated in the browser. For that reason, I publish my tutorials by having blocks of text interspersed with images of code. Clicking on the images copies the code to the clipboard so that people can use them in their own front-end. Here is what the HTML code for this looks like:

<img src="..." />
<textarea>code goes here</textarea>

The textarea element is hidden using CSS. This used to work because I had disabled wpautop but now that I upgraded to Gutenberg, this doesn't seem to be an option anymore. Now it inserts <br /> tags in my content.

What is a long-term, proper solution to this problem? Can blocks help me?

Share Improve this question edited Feb 13, 2019 at 19:57 C. E. asked Feb 13, 2019 at 18:14 C. E.C. E. 1012 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I think that clipboard.js is your best bet to what you're looking for.

Install that script, then just change your img to

<img src="..." data-clipboard-text="..."> And you should be good to go.

Post a comment

comment list (0)

  1. No comments so far