Code snippets: Support "Outputs:" comments in runnable snippets - #297
Merged
Conversation
Contributor
Corpus diff0 hunks. No behavior change over WordPress 7.1, parser at |
Member
The two examples that shipped in WordPress 7.1 use this. I suspect it's OK to remove, but those examples will lose the expected output. For 7.2, I'd expect to use whatever updated form is expected everywhere. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Core PR WordPress/wordpress-develop#13267 replaces a separate
expected-outputfence with a trailing output comment.This PR adds support for the
// Outputs:syntax to the runnable code snippets. That is in addition to the already supportedexpected-outputsyntax.Output formats
Literal one-line output
Everything after
// Outputs:is literal output. Quotes and other punctuation have no special meaning.{ "code": "echo esc_html( \"<egg>\" );", "expected_output": "<egg>" }Literal multiline output
An empty
// Outputs:starts a multiline block. Each following//is one output line. One space after//is the comment delimiter; further indentation is output.Empty final comments preserve final newlines. Quotes remain literal:
This exports
"first\n\"second \"\n".JSON-encoded output
// Outputs (JSON-encoded):requires one JSON string. Use it when otherwise invisible trailing whitespace, tabs, escaped quotes, or several encoded newlines must be explicit:// Outputs (JSON-encoded): "first\nsecond \n\n"The format is selected by the header, never by the output text. Unicode can remain literal in the DocBlock, including
// Outputs (JSON-encoded): "✅ Complete ".The
expected-outputfence remains supported for compatibility. It is still attached to the preceding interactive PHP fence and removed from rendered documentation. New examples should use one of the trailing comment forms above. The exported JSON shape stays the same, so consumers continue to receiveexpected_outputas a string.Testing
The expanded unit tests cover literal one-line and multiline output, literal quotes, indentation, trailing spaces, one and several final newlines, Unicode, valid JSON escapes, malformed JSON, non-string JSON values, non-final comments, strings, heredocs, block comments, same-line comments, text after a PHP closing tag, expected-output fence compatibility, output conflicts, and unattached metadata errors.