Skip to content

Commit

Permalink
refactor: extract to helper
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Sep 1, 2018
1 parent fd2f3ad commit 25b90f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/BlockElementParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function isBlock()

protected function atx()
{
if (isset($this->trimmedLine[0]) && $this->trimmedLine[0] === '#') {
if (\substr($this->trimmedLine, 0, 1) === '#') {
$level = \strlen($this->trimmedLine) - \strlen(\ltrim($this->trimmedLine, '#'));
$head = $this->h($level, $this->trimmedLine);

Expand All @@ -105,11 +105,7 @@ protected function code()
$codeBlock = \preg_match(static::RE_MD_CODE, $this->line, $codeMatch);

if ($codeBlock || (!$this->inList && !$this->inQuote && $isShifted)) {
$lang = isset($codeMatch[1])
? ' class="language-' . $codeMatch[1] . '"'
: '';

$this->markup .= "\n<pre><code{$lang}>";
$this->markup .= $this->codeStart($codeMatch);

if (!$codeBlock) {
$this->markup .= $this->escape(\substr($this->line, $this->indentLen));
Expand Down
9 changes: 9 additions & 0 deletions src/HtmlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public function h($level, $line)
return '';
}

public function codeStart($lang)
{
$lang = isset($lang[1])
? ' class="language-' . $lang[1] . '"'
: '';

return "\n<pre><code{$lang}>";
}

public function tableStart($line, $delim = '|')
{
$table = "<table>\n<thead>\n<tr>\n";
Expand Down

0 comments on commit 25b90f1

Please sign in to comment.