Skip to content

Commit

Permalink
Normalization of Variable
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Yousuf Fazal <[email protected]>
  • Loading branch information
myousuffazal committed Oct 25, 2023
1 parent dd1df7e commit e6b5dd7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Domain/ContentRenderer/CodeRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private function getWrapperAttributes( string $contentUrl ): array {
$attributes['class'] = $this->getWrapperClasses();

if ( !empty( $this->showSpecificLines ) ) {
$attributes['data-show-lines'] = $this->showSpecificLines;
$attributes['data-show-lines'] = $this->lineNormalizer( $this->showSpecificLines );
}

$attributes['data-toolbar-order'] = 'copy-to-clipboard';
Expand All @@ -71,4 +71,21 @@ private function getWrapperAttributes( string $contentUrl ): array {
return $attributes;
}

/**
* @return string
*/
private function lineNormalizer( string $lines ) {
$exploded = explode( ',', preg_replace( '/\s+/', '', $lines ) );

$ranges = array_filter( $exploded, function( $value ) {
if ( preg_match( '/^\d+$/', $value ) || preg_match( '/^(\d+)-(\d+)$/', $value ) ) {
return true;
}
else {
return false;
}
});

return implode( ',', $ranges );
}
}

0 comments on commit e6b5dd7

Please sign in to comment.