-
-
Save tbaddade/3a2ce01bf6a15feb46a17764f047dde8 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
class App | |
{ | |
/* Convert markup to html | |
* @use REX_VALUE[id=1 callback='App::convertMarkup'] | |
* @use $text = App::convertMarkup('REX_VALUE[1]'); | |
* | |
* @param string $markup | |
* @param string $parser | |
* | |
* @return string | |
*/ | |
public static function convertMarkup($markup, $parser = 'textile') | |
{ | |
if ($markup == '') { | |
return false; | |
} | |
$prefix = ''; | |
$suffix = ''; | |
if (is_array($markup)) { | |
$prefix = (isset($markup['prefix'])) ? $markup['prefix'] : ''; | |
$suffix = (isset($markup['suffix'])) ? $markup['suffix'] : ''; | |
$subject = (isset($markup['subject'])) ? $markup['subject'] : ''; | |
$subject = (isset($markup['output']) && $markup['output'] == 'html') ? $subject : str_replace('<br />', '', htmlspecialchars_decode($subject)); | |
$markup = $subject; | |
} else { | |
$markup = htmlspecialchars_decode($markup); | |
$markup = str_replace('<br />', '', $markup); | |
} | |
switch ($parser) { | |
case 'textile': | |
if (rex_addon::get('rex_markitup')->isAvailable()) { | |
return $prefix . rex_markitup::parseOutput ('textile', $markup) . $suffix; | |
} | |
return $prefix . rex_textile::parse($markup) . $suffix; | |
case 'markdown': | |
return $prefix . (new ParsedownExtra)->text($markup) . $suffix; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment