wporg-developer icon indicating copy to clipboard operation
wporg-developer copied to clipboard

Missing indentation on code block

Open petitphp opened this issue 1 year ago • 6 comments

Initially reported in slack #meta channel.

Description

On the current developer documentation, some code blocks are missing indentation when displaying multiple lines (see attached screenshot). Examples where this issue can be seen : WP_Query reference or register_post_type

Screenshot

missing_spacing

petitphp avatar Oct 06 '23 08:10 petitphp

Unfortunately the examples given above aren't in the content on the staging site, eg. the https://developer.wordpress.org/redesign-test/reference/functions/register_post_type/#flushing-rewrite-on-activation section doesn't exist.

@StevenDufresne do you know if/how we can get the staging content to be on par with prod please?

adamwoodnz avatar Oct 26 '23 03:10 adamwoodnz

Running the cron jobs passing the--url=developer.wordpress.org/redesign-test should work.

StevenDufresne avatar Nov 01 '23 23:11 StevenDufresne

https://github.com/WordPress/wporg-developer/blob/1892b5001515d4521e34ca1de5161396d86f8dc0/env/setup.sh#L16

Docs: https://developer.wordpress.org/cli/commands/cron/event/run/

adamwoodnz avatar Nov 02 '23 03:11 adamwoodnz

Looks like we fixed something in the parsers because https://developer.wordpress.org/redesign-test/reference/functions/register_post_type/#flushing-rewrite-on-activation is there now, and indentation does still look broken

Image

adamwoodnz avatar Nov 16 '23 20:11 adamwoodnz

Looks like we fixed something in the

How it was fixed was mentioned in this PR description Note I Section, if anyone is interested in it, please take a look.

renintw avatar Nov 20 '23 12:11 renintw

Summary of the issue:

Root cause: This seems to be a longstanding issue. It arises from the lack of indentation when inputting in the editor. To fix it, we would need to add indentation to the PHP snippets in the editor's text view. Additionally, there's no need to add extra pre tags; if we do, we'll need to include additional classes and place it inside the [php] shortcode. Otherwise, the sticky header will break.

As shown in this link, geisthanen manually converted the original code, which lacked indentation, into content with Prism-style classes wrapped in <pre> tags. However, it's unclear how this conversion was done; I suspect they might have run a script they wrote themselves. Perhaps someone among you knows about this part.

Regardless, to modify the indentation issue, it means filtering the user's content input in the editor. I've tried formatting $content (via this function), but the possibilities are too numerous and it seems there are no existing tools or functions for formatting, it doesn't make sense to start from scratch. So, before I spend more time on this, I'd like to see if anyone has any thoughts off the top of your head on previous discussions or methods to handle this formatting issue. @adamwoodnz @StevenDufresne

Currently, I've manually fixed the indentation on the WP_Query and register_post_type pages, one of which had dozens of snippets... Other pages might also have this issue, and manually fixing them doesn't make good sense. Additionally, I've also fixed some issues with the sticky header breaking due to incorrectly added <pre> tags.

register_post_type image

WP_Query image

renintw avatar Nov 20 '23 17:11 renintw