Export method code snippets#258
Draft
adamziel wants to merge 12 commits into
Draft
Conversation
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.
Exploration work in progress. @sirreal, could you take a look when you have a chance?
What it does
Exports runnable PHP examples from DocBlocks as
doc.code_snippets, strips those snippet fences fromdoc.long_description, and stores the snippet metadata during import.A DocBlock can pair a
phpfence withexpected-outputand optional setup Blueprint data:For reusable setup, define a named setup Blueprint once and reference it from multiple PHP fences:
File-level setup Blueprints are inherited by functions, classes, and methods in that file, so one setup definition can be reused by several examples.
Screenshot
Actual
wporg-developerrender from an imported fixture using this parser branch plus WordPress/wporg-developer#567. The second and third examples share a named setup Blueprint.Rationale
WordPress.org docs need structured data for
php-code-snippet, with JSON as the intermediate format. Exportingcode,expected_output, and setup Blueprint data avoids reverse-parsing rendered HTML later.Stripping snippet fences from
long_descriptionkeeps the theme from rendering duplicate examples: the plain code fence disappears and the runnable snippet becomes the representation of that example.Implementation
export_docblock()is now the single path for snippet extraction. It:code_snippetsfor PHP fencessetup_blueprintsfor named setup definitionslong_descriptionWPORG_Parser\Importerstores the arrays as_wp-parser_code_snippetsand_wp-parser_setup_blueprintspost meta so themes can render them after import.The parser is intentionally narrow:
phpfences only; other fences are metadata or ignoredblueprint,setup-blueprint, andjson blueprintfences to nearby PHP snippetssetupblueprint,setup-blueprint, andjson setupblueprintfences once undersetup_blueprintsblueprint=<name>,setup-blueprint=<name>, orsetupblueprint=<name>expected-outputas the end of the following-metadata run so later setup data can belong to the next snippetThis is not a full Markdown parser; it extracts the DocBlock fence shapes needed for JSON export.
Testing instructions
Run:
The tests cover snippets with no metadata, expected output, inline Blueprints before and after PHP, reusable named setup Blueprints, file-level setup Blueprints inherited by methods, multiple snippets sharing the same setup, string Blueprint fallback, case-insensitive fence names, info strings, non-PHP fences, exact fence lengths, different-length fences inside snippets, text after would-be closers, indented fences, metadata boundaries, description stripping, and unterminated fences.