Skip to content

Commit

Permalink
Added shortcode for [CODEPEN].
Browse files Browse the repository at this point in the history
  • Loading branch information
mosbth committed Jun 26, 2018
1 parent ee7d686 commit 6403976
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
7 changes: 7 additions & 0 deletions REVISION.md
Expand Up @@ -3,6 +3,13 @@ Revision history



v1.1.1 (2018-06-26)
-----------------------------------

* Added shortcode for [CODEPEN].



v1.1.0 (2018-05-24)
-----------------------------------

Expand Down
56 changes: 56 additions & 0 deletions src/TextFilter/TShortcode.php
Expand Up @@ -34,6 +34,7 @@ public function shortCode($text)
"/\[(FIGURE)[\s+](.+)\]/",
//'/\[(YOUTUBE) src=(.+) width=(.+) caption=(.+)\]/',
"/\[(YOUTUBE)[\s+](.+)\]/",
"/\[(CODEPEN)[\s+](.+)\]/",
"/\[(ASCIINEMA)[\s+](.+)\]/",
"/\[(BOOK)[\s+](.+)\]/",
//"/(```)([\w]*)\n([.]*)```[\n]{1}/s",
Expand All @@ -56,6 +57,10 @@ function ($matches) {
return self::shortCodeYoutube($matches[2]);
break;

case "CODEPEN":
return self::shortCodeCodepen($matches[2]);
break;

case "ASCIINEMA":
return self::shortCodeAsciinema($matches[2]);
break;
Expand Down Expand Up @@ -186,6 +191,57 @@ public static function shortCodeYoutube($options)



/**
* Shortcode for [CODEPEN].
*
* Usage example: [CODEPEN src=id-for-the-tube width=630 caption=""]
*
* @param string $options for the shortcode.
*
* @return array with all the options.
*/
public static function shortCodeCodepen($options)
{
$options= array_merge(
[
"id" => null,
"class" => null,
"src" => null,
"user" => null,
"title" => null,
"tab" => "result",
"theme" => 0,
"height" => 300,
"width" => "100%",
"caption" => null,
],
self::ShortCodeInit($options)
);
extract($options, EXTR_SKIP);

$id = $id ? " id=\"$id\"" : null;
$class = $class ? " class=\"figure figure-codepen $class\"" : " class=\"figure figure-codepen\"";

//$caption = t("Figure: !CAPTION", ["!CAPTION" => $caption]);
if ($caption) {
$caption = "<figcaption markdown=1>{$caption}</figcaption>";
}

// @codingStandardsIgnoreStart
$html = <<<EOD
<figure{$id}{$class} width="$width">
<p data-height="$height" data-theme-id="$theme" data-slug-hash="$src" data-default-tab="$tab" data-user="$user" data-embed-version="2" data-pen-title="$title" class="codepen">See the <a href="https://codepen.io/$user/pen/$src/">Pen</a> on <a href="https://codepen.io">CodePen</a>.</p>
{$caption}
</figure>
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
EOD;
// @codingStandardsIgnoreEnd

return $html;
}



/**
* Shortcode for <figure>.
*
Expand Down

0 comments on commit 6403976

Please sign in to comment.