Skip to content

Commit

Permalink
Added code name aliases to support "js" and "json".
Browse files Browse the repository at this point in the history
  • Loading branch information
Mistralys committed Mar 18, 2021
1 parent c2ccc9c commit b08305f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/DocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ class DocParser
*/
private $file;

/**
* Aliases for code fence language names.
*
* @var array<string,string>
*/
private $langAliases = array(
'js' => 'javascript',
'html' => 'html5',
'json' => 'javascript'
);

public function __construct(DocFile $file)
{
$parse = new ParsedownExtra();
Expand Down Expand Up @@ -123,10 +134,19 @@ private function parseCode() : void

foreach($result[2] as $idx => $matchedText)
{
$this->html = str_replace($matchedText, $this->renderCode($matchedText, $result[1][$idx]), $this->html);
$this->html = str_replace($matchedText, $this->renderCode($matchedText, $this->resolveLanguage($result[1][$idx])), $this->html);
}
}

private function resolveLanguage(string $lang) : string
{
if(isset($this->langAliases[$lang])) {
return $this->langAliases[$lang];
}

return $lang;
}

private function renderCode(string $code, string $language) : string
{
$code = html_entity_decode($code);
Expand Down

0 comments on commit b08305f

Please sign in to comment.