Skip to content

Commit 53f582c

Browse files
committed
refactor: extract codeline, hr to helper
1 parent 25b90f1 commit 53f582c

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

Diff for: src/BlockElementParser.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ private function codeInternal($codeBlock)
129129
if (($codeBlock && \substr(\ltrim($this->line), 0, 3) !== '```')
130130
|| \strpos($this->line, $this->indentStr) === 0
131131
) {
132-
$this->markup .= "\n"; // @todo: donot use \n for first line
133-
$this->markup .= $codeBlock ? $this->line : \substr($this->line, $this->indentLen);
132+
$this->markup .= $this->codeLine($this->line, $codeBlock, $this->indentLen);
134133

135134
$this->pointer++;
136135

@@ -143,13 +142,9 @@ private function codeInternal($codeBlock)
143142

144143
protected function rule()
145144
{
146-
if ($this->trimmedPrevLine === ''
147-
&& \preg_match(static::RE_MD_RULE, $this->trimmedLine)
148-
) {
149-
$this->markup .= "\n<hr />";
145+
$this->markup .= $hr = $this->hr($this->trimmedPrevLine, $this->trimmedLine);
150146

151-
return \true;
152-
}
147+
return (bool) $hr;
153148
}
154149

155150
protected function listt()

Diff for: src/HtmlHelper.php

+15
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ public function h($level, $line)
3131
return '';
3232
}
3333

34+
public function hr($prevLine, $line)
35+
{
36+
if ($prevLine === '' && \preg_match(BlockElementParser::RE_MD_RULE, $line)) {
37+
return "\n<hr />";
38+
}
39+
}
40+
3441
public function codeStart($lang)
3542
{
3643
$lang = isset($lang[1])
@@ -40,6 +47,14 @@ public function codeStart($lang)
4047
return "\n<pre><code{$lang}>";
4148
}
4249

50+
public function codeLine($line, $isBlock, $indentLen = 4)
51+
{
52+
$code = "\n"; // @todo: donot use \n for first line
53+
$code .= $isBlock ? $line : \substr($line, $indentLen);
54+
55+
return $code;
56+
}
57+
4358
public function tableStart($line, $delim = '|')
4459
{
4560
$table = "<table>\n<thead>\n<tr>\n";

0 commit comments

Comments
 (0)