Skip to content

Commit 79895f9

Browse files
westonruterpierlonjohnwatkins0
authored
[2.0 branch] Fix parsing of docblocks that contain code snippets (#5748)
* Fix parsing of docblocks that contain code snippets * Add variable to docs for `amp_dev_mode_enabled` filter * Wrap HTML tag in backticks * Add more markdown formatting and restore linebreak * Remove obsolete amp_is_canonical() examples * Reorder composer.json fields * Ensure alphabetical order for patches in composer.json * Run composer update Co-authored-by: Pierre Gordon <[email protected]> Co-authored-by: John Watkins <[email protected]>
1 parent da521c2 commit 79895f9

File tree

5 files changed

+79
-72
lines changed

5 files changed

+79
-72
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@
4545
"extra": {
4646
"downloads": {
4747
"phpstan": {
48-
"url": "https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar",
4948
"path": "vendor/bin/phpstan",
50-
"type": "phar"
49+
"type": "phar",
50+
"url": "https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar"
5151
}
5252
},
5353
"patches": {
5454
"sabberworm/php-css-parser": {
55-
"Add additional validation for size unit <https://github.com/sabberworm/PHP-CSS-Parser/pull/193>": "https://github.com/sabberworm/PHP-CSS-Parser/compare/3bc5ded67d77a52b81608cfc97f23b1bb0678e2f%5E...468da3441945e9c1bf402a3340b1d8326723f7d9.patch",
56-
"Validate name-start code points for identifier <https://github.com/sabberworm/PHP-CSS-Parser/pull/185>": "https://github.com/sabberworm/PHP-CSS-Parser/compare/d42b64793f2edaffeb663c63e9de79069cdc0831%5E...113df5d55e94e21c6402021dfa959924941d4c29.patch",
57-
"Fix parsing CSS selectors which contain commas <https://github.com/westonruter/PHP-CSS-Parser/pull/1>": "https://github.com/westonruter/PHP-CSS-Parser/compare/master...10a2501c119abafced3e4014aa3c0a3453a86f67.patch"
55+
"1. Add additional validation for size unit <https://github.com/sabberworm/PHP-CSS-Parser/pull/193>": "https://github.com/sabberworm/PHP-CSS-Parser/compare/3bc5ded67d77a52b81608cfc97f23b1bb0678e2f%5E...468da3441945e9c1bf402a3340b1d8326723f7d9.patch",
56+
"2. Validate name-start code points for identifier <https://github.com/sabberworm/PHP-CSS-Parser/pull/185>": "https://github.com/sabberworm/PHP-CSS-Parser/compare/d42b64793f2edaffeb663c63e9de79069cdc0831%5E...113df5d55e94e21c6402021dfa959924941d4c29.patch",
57+
"3. Fix parsing CSS selectors which contain commas <https://github.com/westonruter/PHP-CSS-Parser/pull/1>": "https://github.com/westonruter/PHP-CSS-Parser/compare/master...10a2501c119abafced3e4014aa3c0a3453a86f67.patch"
5858
}
5959
}
6060
},

composer.lock

Lines changed: 40 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/src/Parser/Parser.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ public function parse_files( $files, $root ) {
174174
*
175175
* This function fixes text by merging consecutive lines of text into a
176176
* single line. A special exception is made for text appearing in `<code>`
177-
* and `<pre>` tags, as newlines appearing in those tags are always
178-
* intentional.
177+
* and `<pre>` tags or wrapped in triple backticks (```), as newlines
178+
* appearing in those are always intentional.
179179
*
180180
* @param string $text Text for which to fix the newlines.
181181
*
@@ -194,6 +194,15 @@ static function ( $matches ) use ( $replacement_string ) {
194194
$text
195195
);
196196

197+
// Replace newline characters within triple backticks with replacement string.
198+
$text = preg_replace_callback(
199+
'/(?<=```)(.+)(?=```)/s',
200+
static function ( $matches ) use ( $replacement_string ) {
201+
return preg_replace( '/[\n\r]/', $replacement_string, $matches[1] );
202+
},
203+
$text
204+
);
205+
197206
// Merge consecutive non-blank lines together by replacing the newlines with a space.
198207
$text = preg_replace(
199208
"/[\n\r](?!\s*[\n\r])/m",

docs/templates/function.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
```
1010

1111
{{# has_description }}
12-
{{ get_description }}
12+
{{{ get_description }}}
1313

1414
{{/ has_description }}
1515
{{# has_arguments }}

includes/amp-helper-functions.php

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -325,42 +325,35 @@ function amp_correct_query_when_is_front_page( WP_Query $query ) {
325325
*
326326
* Themes can register support for this with `add_theme_support( AMP_Theme_Support::SLUG )`:
327327
*
328-
* add_theme_support( AMP_Theme_Support::SLUG );
328+
* ```php
329+
* add_theme_support( AMP_Theme_Support::SLUG );
330+
* ```
329331
*
330332
* This will serve templates in AMP-first, allowing you to use AMP components in your theme templates.
331333
* If you want to make available in transitional mode, where templates are served in AMP or non-AMP documents, do:
332334
*
333-
* add_theme_support( AMP_Theme_Support::SLUG, array(
334-
* 'paired' => true,
335-
* ) );
335+
* ```php
336+
* add_theme_support( AMP_Theme_Support::SLUG, array(
337+
* 'paired' => true,
338+
* ) );
339+
* ```
336340
*
337-
* Transitional mode is also implied if you define a template_dir:
341+
* Transitional mode is also implied if you define a `template_dir`:
338342
*
339-
* add_theme_support( AMP_Theme_Support::SLUG, array(
340-
* 'template_dir' => 'amp',
341-
* ) );
343+
* ```php
344+
* add_theme_support( AMP_Theme_Support::SLUG, array(
345+
* 'template_dir' => 'amp',
346+
* ) );
347+
* ```
342348
*
343349
* If you want to have AMP-specific templates in addition to serving AMP-first, do:
344350
*
345-
* add_theme_support( AMP_Theme_Support::SLUG, array(
346-
* 'paired' => false,
347-
* 'template_dir' => 'amp',
348-
* ) );
349-
*
350-
* If you want to force AMP to always be served on a given template, you can use the templates_supported arg,
351-
* for example to always serve the Category template in AMP:
352-
*
353-
* add_theme_support( AMP_Theme_Support::SLUG, array(
354-
* 'templates_supported' => array(
355-
* 'is_category' => true,
356-
* ),
357-
* ) );
358-
*
359-
* Or if you want to force AMP to be used on all templates:
360-
*
361-
* add_theme_support( AMP_Theme_Support::SLUG, array(
362-
* 'templates_supported' => 'all',
363-
* ) );
351+
* ```php
352+
* add_theme_support( AMP_Theme_Support::SLUG, array(
353+
* 'paired' => false,
354+
* 'template_dir' => 'amp',
355+
* ) );
356+
* ```
364357
*
365358
* @see AMP_Theme_Support::read_theme_support()
366359
* @return boolean Whether this is in AMP 'canonical' mode, that is whether it is AMP-first and there is not a separate (paired) AMP URL.
@@ -1450,7 +1443,7 @@ function amp_get_content_embed_handlers( $post = null ) {
14501443
/**
14511444
* Determine whether AMP dev mode is enabled.
14521445
*
1453-
* When enabled, the <html> element will get the data-ampdevmode attribute and the plugin will add the same attribute
1446+
* When enabled, the `<html>` element will get the data-ampdevmode attribute and the plugin will add the same attribute
14541447
* to elements associated with the admin bar and other elements that are provided by the `amp_dev_mode_element_xpaths`
14551448
* filter.
14561449
*
@@ -1468,7 +1461,7 @@ function amp_is_dev_mode() {
14681461
* queries for the expressions returned by the 'amp_dev_mode_element_xpaths' filter.
14691462
*
14701463
* @since 1.3
1471-
* @param bool Whether AMP dev mode is enabled.
1464+
* @param bool $is_dev_mode_enabled Whether AMP dev mode is enabled.
14721465
*/
14731466
return apply_filters(
14741467
'amp_dev_mode_enabled',

0 commit comments

Comments
 (0)