Skip to content

Commit b08305f

Browse files
committed
Added code name aliases to support "js" and "json".
1 parent c2ccc9c commit b08305f

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/DocParser.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ class DocParser
2525
*/
2626
private $file;
2727

28+
/**
29+
* Aliases for code fence language names.
30+
*
31+
* @var array<string,string>
32+
*/
33+
private $langAliases = array(
34+
'js' => 'javascript',
35+
'html' => 'html5',
36+
'json' => 'javascript'
37+
);
38+
2839
public function __construct(DocFile $file)
2940
{
3041
$parse = new ParsedownExtra();
@@ -123,10 +134,19 @@ private function parseCode() : void
123134

124135
foreach($result[2] as $idx => $matchedText)
125136
{
126-
$this->html = str_replace($matchedText, $this->renderCode($matchedText, $result[1][$idx]), $this->html);
137+
$this->html = str_replace($matchedText, $this->renderCode($matchedText, $this->resolveLanguage($result[1][$idx])), $this->html);
127138
}
128139
}
129140

141+
private function resolveLanguage(string $lang) : string
142+
{
143+
if(isset($this->langAliases[$lang])) {
144+
return $this->langAliases[$lang];
145+
}
146+
147+
return $lang;
148+
}
149+
130150
private function renderCode(string $code, string $language) : string
131151
{
132152
$code = html_entity_decode($code);

0 commit comments

Comments
 (0)