Making WordPress.org

Changeset 10068


Ignore:
Timestamp:
07/13/2020 10:40:31 PM (6 years ago)
Author:
coffee2code
Message:

Developer theme: Convert lists (defined using * or - for items) appearing in descriptions into actual HTML lists.

Props ocean90, coffee2code.
See #5304.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/formatting.php

    r10067 r10068  
    4040                add_filter( 'devhub-format-description', array( __CLASS__, 'fix_param_hash_formatting' ), 9 );
    4141                add_filter( 'devhub-format-description', array( __CLASS__, 'fix_param_description_html_as_code' ) );
     42                add_filter( 'devhub-format-description', array( __CLASS__, 'convert_lists_to_markup' ) );
    4243
    4344                add_filter( 'devhub-format-hash-param-description', array( __CLASS__, 'autolink_references' ) );
     
    316317                foreach ( $allowable_tags as $tag ) {
    317318                        $text = str_replace( array( "&lt;{$tag}&gt;", "&lt;/{$tag}&gt;" ), array( "<{$tag}>", "</{$tag}>" ), $text );
    318                 }
    319 
    320                 // Convert asterisks to a list.
    321                 // Inline lists in param descriptions aren't handled by parser.
    322                 // Example: https://developer.wordpress.org/reference/functions/add_menu_page/
    323                 if ( false !== strpos( $text, ' * ' ) )  {
    324                         // Display as simple plaintext list.
    325                         $text = str_replace( ' * ', '<br /> * ', $text );
    326319                }
    327320
     
    485478
    486479        /**
     480         * Converts simple Markdown-like lists into list markup.
     481         *
     482         * Necessary in cases like hash param descriptions which don't see Markdown
     483         * list processing during parsing.
     484         *
     485         * Recognizes lists where list items are denoted with an asterisk or dash.
     486         *
     487         * Does not handle nesting of lists.
     488         *
     489         * @param string $text The text to process for lists.
     490         * @return string
     491         */
     492        public static function convert_lists_to_markup( $text ) {
     493                $inline_list = false;
     494                $li = '<br /> * ';
     495
     496                // Convert asterisks to a list.
     497                // Example: https://developer.wordpress.org/reference/functions/add_menu_page/
     498                if ( false !== strpos( $text, ' * ' ) )  {
     499                        // Display as simple plaintext list.
     500                        $text = str_replace( ' * ', "\n" . $li, $text );
     501                        $inline_list = true;
     502                }
     503
     504                // Convert dashes to a list.
     505                // Example: https://developer.wordpress.org/reference/classes/wp_term_query/__construct/
     506                // Example: https://developer.wordpress.org/reference/hooks/password_change_email/
     507                if ( false !== strpos( $text, ' - ' ) )  {
     508                        // Display as simple plaintext list.
     509                        $text = str_replace( ' - ', "\n" . $li, $text );
     510                        $inline_list = true;
     511                }
     512
     513                // If list detected.
     514                if ( $inline_list ) {
     515                        // Replace first item, ensuring the opening 'ul' tag is prepended.
     516                        $text = preg_replace( '~^' . preg_quote( $li ) . '(.+)$~mU', "<ul><li>\$1</li>\n", $text, 1 );
     517                        // Wrap subsequent list items in 'li' tags.
     518                        $text = preg_replace( '~^' . preg_quote( $li ) . '(.+)$~mU', "<li>\$1</li>\n", $text );
     519                        $text = trim( $text );
     520
     521                        // Close the list if it hasn't been closed before start of next hash parameter.
     522                        //$text = preg_replace( '~(</li>)(\s+</li>)~smU', '$1</ul>$2', $text );
     523                        $text = preg_replace( '~(</li>)(\s*</li>)~smU', '$1</ul>$2', $text );
     524
     525                        // Closethe list if it hasn't been closed and it's the end of the description.
     526                        if ( '</li>' === substr( trim( $text ), -5 ) ) {
     527                                $text .= '</ul>';
     528                        }
     529                }
     530
     531                return $text;
     532        }
     533
     534        /**
    487535         * Formats the output of params defined using hash notation.
    488536         *
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss

    r9716 r10068  
    10881088                                        font-style: italic;
    10891089                                }
     1090
     1091                                ul {
     1092                                        margin-left: 25px;
     1093                                        margin-left: 2.5rem;
     1094                                }
    10901095                        }
    10911096                        .param-hash {
    10921097                                margin-left: 1.2em;
    10931098                                margin-bottom: 0.5em;
    1094                                 li {
     1099                                > li {
    10951100                                        margin-top: 1em;
     1101                                }
     1102                                li li {
     1103                                        list-style-type: circle;
     1104                                }
     1105                                .param-hash > li {
     1106                                        list-style-type: disc;
    10961107                                }
    10971108                        }
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css

    r9716 r10068  
    14771477}
    14781478
     1479.devhub-wrap .wp-parser-class .parameters dd ul, .devhub-wrap .wp-parser-function .parameters dd ul, .devhub-wrap .wp-parser-hook .parameters dd ul, .devhub-wrap .wp-parser-method .parameters dd ul {
     1480  margin-left: 25px;
     1481  margin-left: 2.5rem;
     1482}
     1483
    14791484.devhub-wrap .wp-parser-class .parameters .param-hash, .devhub-wrap .wp-parser-function .parameters .param-hash, .devhub-wrap .wp-parser-hook .parameters .param-hash, .devhub-wrap .wp-parser-method .parameters .param-hash {
    14801485  margin-left: 1.2em;
     
    14821487}
    14831488
    1484 .devhub-wrap .wp-parser-class .parameters .param-hash li, .devhub-wrap .wp-parser-function .parameters .param-hash li, .devhub-wrap .wp-parser-hook .parameters .param-hash li, .devhub-wrap .wp-parser-method .parameters .param-hash li {
     1489.devhub-wrap .wp-parser-class .parameters .param-hash > li, .devhub-wrap .wp-parser-function .parameters .param-hash > li, .devhub-wrap .wp-parser-hook .parameters .param-hash > li, .devhub-wrap .wp-parser-method .parameters .param-hash > li {
    14851490  margin-top: 1em;
     1491}
     1492
     1493.devhub-wrap .wp-parser-class .parameters .param-hash li li, .devhub-wrap .wp-parser-function .parameters .param-hash li li, .devhub-wrap .wp-parser-hook .parameters .param-hash li li, .devhub-wrap .wp-parser-method .parameters .param-hash li li {
     1494  list-style-type: circle;
     1495}
     1496
     1497.devhub-wrap .wp-parser-class .parameters .param-hash .param-hash > li, .devhub-wrap .wp-parser-function .parameters .param-hash .param-hash > li, .devhub-wrap .wp-parser-hook .parameters .param-hash .param-hash > li, .devhub-wrap .wp-parser-method .parameters .param-hash .param-hash > li {
     1498  list-style-type: disc;
    14861499}
    14871500
Note: See TracChangeset for help on using the changeset viewer.