Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple code block #826

Merged
merged 4 commits into from
May 22, 2017
Merged

Add simple code block #826

merged 4 commits into from
May 22, 2017

Conversation

ellatrix
Copy link
Member

See #516.

@ellatrix
Copy link
Member Author

  • I had to reset content for Editable on init because something went wrong with spacing when React sets it. I'll look into that.
  • I tried PRE > CODE in the edit function, but that doesn't seem to work well, so I just added PRE for edit and PRE > CODE for save.

@ellatrix ellatrix mentioned this pull request May 17, 2017
@ellatrix ellatrix added the [Feature] Blocks Overall functionality of blocks label May 17, 2017
@ellatrix
Copy link
Member Author

Any good demo content for a code block?

@jasmussen
Copy link
Contributor

I usually look for gems here:

http://codecrap.com/content/best/

;)

@ellatrix
Copy link
Member Author

Haha, that's good too :) Wasn't sure if we need anything that fits with the current content. Maybe even something about creating blocks...

Anyway, that can be a separate PR.

@jasmussen
Copy link
Contributor

It could be the markup of the block itself. Wouldn't that be cool?

@ellatrix
Copy link
Member Author

Okay, white space is stripped because TinyMCE will not set the raw content on load, but parse it. Normally whitespace is preserved in PRE, but in this case it's the root element. A bug I guess. Not sure how to fix it other than the current fix.

@jasmussen
Copy link
Contributor

Really really cool, I dig it! Colors look good too.

Like for the pre block, let's zero out the margin and use the intrinsic padding for spacing between blocks instead.

Let's also use $editor-html-font for the font. It's a nice stack.

Also looks like the padding optically appears taller above and below the content inside.

I can make these changes in your branch if you like? Just let me know.

@ellatrix
Copy link
Member Author

@jasmussen Please do! :)

@jasmussen
Copy link
Contributor

Done! Spiffied it up a bit.


edit( { attributes, setAttributes, focus, setFocus } ) {
return (
<Editable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be an Editable, or would a controlled textarea work just as well? Since we're not using any formatting features. Or at least we don't show the formatting toolbar, but Cmd-B still bolds text, which seems unexpected.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I guess we do not. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One annoying thing will be auto resizing it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've pulled in react-autosize-textarea for the Text mode. We can probably use that here as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure how do handle focus without complicating it a lot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure how do handle focus without complicating it a lot.

Can you explain the problem you're encountering?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't have to pass a focus object. Just noticing that the texture is not focussing immediately on click.

@ellatrix ellatrix force-pushed the add/code-block branch 2 times, most recently from 3ae8ed0 to 9848bb0 Compare May 18, 2017 17:01
@jasmussen
Copy link
Contributor

Looks and works real well.

Tiny niggle: looks like there's an extra linebreak in the post-content.js:

screen shot 2017-05-22 at 14 16 27

;)

@ellatrix ellatrix merged commit ae8734d into master May 22, 2017
@ellatrix ellatrix deleted the add/code-block branch May 22, 2017 12:25
edit( { attributes, setAttributes, setFocus } ) {
return (
<TextareaAutosize
defaultValue={ attributes.content }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could have been value= instead to treat the input as a controlled component, ensuring that if, for whatever reason, the value were assigned explicitly, the textarea would be updated to reflect it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I tried value but got some issues. Will try again.

@dmsnell
Copy link
Member

dmsnell commented May 22, 2017

What happens if we try to write <!-- /wp:core/code --> in the text block?

@ellatrix
Copy link
Member Author

@dmsnell It will be encoded?

@StaggerLeee
Copy link

Would like to ask if you could add background-color for code block in backend ?
Something like: background-color: #f5f5f5; makes a great difference. At least when there is no pointer focus on code block.

And if you can style "pre" tag the same as "div[data-type="core/code"] textarea". For backward compability when people remove syntax plugins, or similar.

@jasmussen
Copy link
Contributor

@StaggerLeee that's a great point. May I kindly ask that you open this suggestion as a separate, new, ticket?

@StaggerLeee
Copy link

StaggerLeee commented Aug 31, 2017

Is it possible to take over old TinyMce blocks with
<pre class="lang:css decode:true ">
<pre class="lang:php decode:true">
inside ?

Detect opening and closing tags and make one new Gutenberg (code) block of it ?

Right now they are shown as simple text, not inside block(s). Making converting to Gutenberg almost impossible for any website dealing with code snippets for years.
Front-end is done, few CSS lines. But additional editing in Gutenberg is not easy and possible. Not to mention problems with code formatting if it ends as simple text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants