Title: Editing pre
Last modified: August 4, 2018

---

# Editing pre

 *  Resolved [Natalya](https://wordpress.org/support/users/nalitana/)
 * (@nalitana)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/editing-pre/)
 * Hello! I’m not very good at php, please explain to me how to wrap the pre tag
   in a div now? The block automatically converts the content to plain HTML and 
   adds the <p> auto-tags between <div> and pre. I add my styles for pre without
   using java and I’m adding the Schema micro-markup for the code. But now it’s 
   impossible to do.
    -  This topic was modified 7 years, 10 months ago by [Natalya](https://wordpress.org/support/users/nalitana/).

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Moderator [Marius L. J.](https://wordpress.org/support/users/clorith/)
 * (@clorith)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/editing-pre/#post-10560333)
 * Hi,
 * I’m afraid I don’t quite understand the question here, what are you trying to
   achieve, and do you have an example of what it looks like with and without Gutenberg
   enabled?
 * If I add a code block (the one that created the `<pre>` tag) it does not add 
   any `p` or `div` tags, so if you could describe this a bit more we can hopefully
   figure this out together.
 *  Thread Starter [Natalya](https://wordpress.org/support/users/nalitana/)
 * (@nalitana)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/editing-pre/#post-10560688)
 * Sorry for my translation into English. I wanted to say that I need to add the
   div and the “expand” button for the “pre” block, and also add the language data,
   class, but if I want to add this data, the “pre” block is converted to an HTML
   block.
    You try to add your class to “pre” without hooks and java and you will
   see that this is impossible without converting the block to HTML.
 *     ```
       <div class=”block”>
          <button>Expand</button>
           <div class=”text-hidden” tabindex=”0″>
   
            <pre class="">
               pre[data-lang]::before {
                  display: block;
                  content: attr(data-lang);
                  color: firebrick;
                }
               button {
                  font-size: 0.8em;
                  background-color: #f5f7f9;
                  border-bottom: 5px solid #eb7565;
               }
               .text-hidden {
                  display: block;
                  height: 100px;
                  outline: none;
                  overflow: hidden;
               }
            </pre>
   
          </div>
       </div>
       ```
   
    -  This reply was modified 7 years, 10 months ago by [Natalya](https://wordpress.org/support/users/nalitana/).
 *  Thread Starter [Natalya](https://wordpress.org/support/users/nalitana/)
 * (@nalitana)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/editing-pre/#post-10560851)
 * I made a small GIF, where the tag `pre` added `data-lang="HTML"`.
    [Screenshot](https://screenpresso.com/=K80fb)
 * Of course, this is not the biggest problem, you guys did a great job. But it 
   would be nice if the block `pre` was not converted to an HTML block when editing.
 * P.S. By the way, yesterday the tag `p` was automatically added to the HTML block,
   but today everything was fine.
 *  Moderator [Marius L. J.](https://wordpress.org/support/users/clorith/)
 * (@clorith)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/editing-pre/#post-10561682)
 * Ahh, I see.
 * So, what is happening here is that Gutenberg looks for pre-approved attributes,
   the `data-lang` one is unknown and that’s why it gets stripped away.
 * We have a [ticket to make sure we don’t remove manually inserted data](https://github.com/WordPress/gutenberg/issues/6878)
   like this from users, which I believe applies to your situation.
 * You could also use the `Custom HTML` block if you wanted complete control, if
   nothing else then as a temporary solution until the ticket above is resolved.
 *  Thread Starter [Natalya](https://wordpress.org/support/users/nalitana/)
 * (@nalitana)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/editing-pre/#post-10569112)
 * Hello Marius! Unfortunately, the block with arbitrary HTML still automatically
   inserts tags `& nbsp; <br> and <p>` when you preview the article and when you
   publish it. They are generated exactly in the published form. It breaks all the
   styles of the article. I used to use the hook and shortcode, which remove the
   automatic creation of tags, now it does not work, even in a classic editor, after
   installing Gutenberg.
 *     ```
       /**
        * Disabling formatting of the visual editor in the right place and create the shortcode.
        */
       function my_formatter($content) {
       	$new_content = '';
       	$pattern_full = '{(\[raw\].*?\[/raw\])}is';
       	$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
       	$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
   
       	foreach ($pieces as $piece) {
       		if (preg_match($pattern_contents, $piece, $matches)) {
       			$new_content .= $matches[1];
       		} else {
       			$new_content .= wptexturize(wpautop($piece));
       		}
       	}
       	return $new_content;
       } 
       remove_filter('the_content', 'wpautop');
       remove_filter('the_content', 'wptexturize');
   
       add_filter('the_content', 'my_formatter', 99);
       ```
   
 *  Thread Starter [Natalya](https://wordpress.org/support/users/nalitana/)
 * (@nalitana)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/editing-pre/#post-10569183)
 * The screenshot shows that when writing an article in an HTML block, there are
   no auto-tags, and in the published form they are generated automatically.
    [Screenshot](https://screenpresso.com/=c4fee#)
 *  Moderator [Marius L. J.](https://wordpress.org/support/users/clorith/)
 * (@clorith)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/editing-pre/#post-10571625)
 * Hi,
 * I’m afraid I’m unable to replicate this my self.
 * The `<br>` tag is in the HTML in the top screenshot you showed me, so that is
   expected to be there in the output, but there are no `<p>` tags added by the 
   HTML comment lines like you are showing.
 * Do you perhaps have other plugins (or the theme) interfering with the content?
   Are you able to try saving yoru content without any other plugins and a default
   them (such as Twenty Seventeen) and seeing if the problem persists?

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Editing pre’ is closed to new replies.

 * ![](https://ps.w.org/gutenberg/assets/icon-256x256.jpg?rev=1776042)
 * [Gutenberg](https://wordpress.org/plugins/gutenberg/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gutenberg/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gutenberg/)
 * [Active Topics](https://wordpress.org/support/plugin/gutenberg/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gutenberg/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gutenberg/reviews/)

## Tags

 * [html](https://wordpress.org/support/topic-tag/html/)
 * [pre](https://wordpress.org/support/topic-tag/pre/)

 * 7 replies
 * 2 participants
 * Last reply from: [Marius L. J.](https://wordpress.org/support/users/clorith/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/editing-pre/#post-10571625)
 * Status: resolved