-
Notifications
You must be signed in to change notification settings - Fork 4
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
Updated "advanced blueprint" example to match Playground documentation #7
Updated "advanced blueprint" example to match Playground documentation #7
Conversation
Relevant issues - however, I think this spec is part of the Blueprints API v2 which isn't quite yet ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was necessary to wrap the code
step in backticks to match the functioning API spec.
(There's a live demo on this page that works)
Without the backticks, the MDX code rendering fails without error
@flexseth Thanks for the fix! How can the rendered doc be previewed? Does the final result include the backticks or not? If it does, that's a bit of a problem as that won't work in Playground. The functioning API spec uses backticks to split the code over multiple lines. The price to pay is that it isn't a valid JSON anymore, only valid JavaScript. And a doubly wrapped strings could lead to a syntax error, e.g.: {
"code": "`<?php require_once 'wordpress/wp-load.php'; wp_insert_post(array('post_title' => 'wp-load.php required for WP functionality', 'post_status' => 'publish')); ?>`"
} Would output two backticks and work. However, this, without the closing {
"code": "`<?php require_once 'wordpress/wp-load.php'; wp_insert_post(array('post_title' => 'wp-load.php required for WP functionality', 'post_status' => 'publish')); `"
} In the Blueprints v2 I'd like to include the following multiline string syntax: {
"code": [
"<?php",
"function test() {",
" return 'test';",
"}"
]
} |
This is to say, we may need to fix the doc renderer to fix the problem. If the backticks are displayed in the final doc, we can't have them :( cc @dd32 |
I see. That was the only example that I found that worked with What you end up having to do is wrap code that is in backticks in a code block, perhaps escaping. It's not pretty, there's an example below. I'll try out your PHP code sample after coffee 😀 Here's that code on GitHub, it's a bit difficult to decipher without formatting
You will notice there are formatting issues here, also. Last week I ran into a similar example on the REST API, where someone wanted to use the backtick syntax to highlight a URL. And it messed up the paragraph until the next line break. I believe this was due to GitHub's Markdown renderer believing it to be code inside of code, an then leaving an extraneous backtick... it previewed OK using the Markdown Preview Enhanced extension for VS Code. In the REST API use case... The code had to be changed from
And below is a screenshot of what it actually looks like in the GitHub Markdown editor (I am not trying to re-create this in Markdown 😆) This isn't 100% accurate but hopefully proves the point about the syntax |
I think it's possible to make it look good on the front-end, rendered from Markdown, but it's going to lead to a lot of escaping, and wrapping stuff in code blocks that isn't actually wrapped in code blocks. Potentially making the documentation much more difficult to edit and maintain. cc: @dd32
I believe this would be... {
"code": [
"<code><?php",
"function test() {",
" return 'test';",
"}?></code>"
]
} |
Oh, sorry, I didn't mean PHP syntax coloring, I just meant the backticks shouldn't be in the final JSON displayed to the end readers of that documentation. It's absolutely fine for PHP to be treated as a JSON string and not be syntax highlighted. |
@adamziel I think if you replace the backticks with |
Might be a bit beyond the scope of this PR, but can you use |
@helgatheviking yes, you can! Or did you mean to update those examples to actually use wp-cli? |
cc @tellyworth @StevenDufresne for reviews as I don't have the handbook build environment set up. |
Well more examples are always great! In reviewing the doc, I found the import file, but my plugin's live preview doesn't seem to actually import that file. |
@tellyworth @StevenDufresne, @adamziel - this code is incorrect I believe. We discussed wrapping the code in backticks which is not correct, I need to revert that change. Didn't have a chance to get to it yesterday but I should be able to clean up this commit today |
fc636d0
to
6d66720
Compare
6d66720
to
56cdbd1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamziel please review these changes - the backtick has been removed so the "advanced blueprint" example matches the documentation
Advanced Blueprint example - currently broken
Documentation
Relevant issue
Once approved, if you can please ping @javiercasares
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamziel - here's the changes in an easier to read / approve format.
I don't have it configured either but the changes look ok to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tellyworth if you could please review the PR and see the completed code
step, merging the PR will help when the repo syncs from SVN again to not overwrite manual changes that were made. Code sample has been updated on the WP.org Plugins Handbook manually. Please review :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I don't think we have any way to preview the change to confirm correct handling/escaping, so let's just go with it and if there's an issue then deal with the new problem.
Yeah I've been looking at some of the idiosyncrasies with escaping PHP inside JSON code blocks. It's a bit iffy - but you're right, there is no way to preview the Markdown it it does not look like. Happy to work on the formatting if it doesn't look right with the end product and adjust accordingly, I'll keep the issues open until it looks right. TY for reviewing, look forward to merge so I can check the formatting! |
I'm not having any success with that yet and I can't tell if it's CLI or the playground. I have an issue open at CLI as well. Just tested my
resulting in this error... which I think is coming back to the block attributes not getting inserted correctly.
|
@helgatheviking the issue seems to be with escaping the quotes. You have JSON in a shell command in JSON. Your Block markup seems to be:
Escaping that for wp post create --post_title="User Directory Demo" --post_type=page --post_status=publish --post_author=1 --post_content='<!-- wp:simple-user-listing/directory-block {"columns":3,"showAllUsers":false,"roles":"subscriber","usersPerPage":9,"className":"is-style-grid"} /-->' Now, bringing that into a Blueprint requires encoding the entire command as JSON: {
"landingPage": "/wp-admin/edit.php?post_type=page",
"phpExtensionBundles": [
"kitchen-sink"
],
"steps": [
{
"step": "login",
"username": "admin",
"password": "password"
},
{
"step": "wp-cli",
"command": "wp post create --post_title=\"User Directory Demo\" --post_type=page --post_status=publish --post_author=1 --post_content='<!-- wp:simple-user-listing/directory-block {\"columns\":3,\"showAllUsers\":false,\"roles\":\"subscriber\",\"usersPerPage\":9,\"className\":\"is-style-grid\"} /-->'"
}
]
} Which works as expected: |
Apologies for the multiple commits. If possible to clean this up, please do so. I tried to rebase but don't think it worked like it was supposed to! Nonetheless, this PR matches the code sample on Devhub to the documentation for Playground
Fixes
The blueprint on the dev docs was as follows (incomplete)
New blueprint sample