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

Question: Is there a way of capturing the class of an existing code block #6

Open
caraya opened this issue Apr 8, 2018 · 4 comments

Comments

@caraya
Copy link

caraya commented Apr 8, 2018

Is there a way for this block to capture the class of an existing code block? Is this what #4 is designed to support?

If this solves the issue I can then close WordPress/gutenberg/issues/5392

BTW, thanks for tackling this one!

@mkaz
Copy link
Owner

mkaz commented Apr 9, 2018

I think it depends on what you mean by an existing code block and waht the class looks like.

My idea for Issue #4 in this repo was auto converting from markdown pasted in like: ```php and setting the class name to PHP.

I need to read up more on how transform works, and how it might work with extending a core block. It seems like it could be something to do from old posts markup depending on the structure of the code.

@caraya
Copy link
Author

caraya commented Apr 9, 2018

Something similar... I've been evaluating using Gutenberg in a blog that has several codeblocks fenced with ``` and the language name, the same way you're thinking about doing it for pasted content. What I'm not sure is whether Gutenberg will work with the converted HTML or the raw Markdown.

@mkaz
Copy link
Owner

mkaz commented Apr 10, 2018

Doing a little more research, it looks like pasted in markdown is handled via the RichText component and specifically this function strips out the extra language info, since the default code block does not have a language attribute.

I'll need to think more about how this could work. I commented on a similar issue here, with regards to table losing class names. Maybe during conversion there could be some rules to set the block's additional class field, if that gets set it might be easier to hook into.

At least it is pretty straight-forward to go through and set the language on code blocks once they get imported., I've done it for old posts I'm converting on my mkaz.blog site. I convert the classic post to blocks and then click into each code block and select the language.

@caraya
Copy link
Author

caraya commented Apr 10, 2018

I agree it's possible... it's just frustrating.

Thank you for taking the time to look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants