markdown = $parser; $this->configuration = $configuration; } private function isMarkdownEnabled(): bool { if (null === $this->markdownEnabled) { $this->markdownEnabled = $this->configuration->isTimesheetMarkdownEnabled(); } return $this->markdownEnabled; } /** * Transforms the entities comment (customer, project, activity ...) into HTML. * * @param string|null $content * @param bool $fullLength * @return string */ public function commentContent(?string $content, bool $fullLength = false): string { if (empty($content)) { return ''; } if (!$fullLength && \strlen($content) > 101) { $content = trim(substr($content, 0, 100)) . ' …'; } if ($this->isMarkdownEnabled()) { $content = $this->markdown->toHtml($content); } elseif ($fullLength) { $content = '

' . nl2br($content) . '

'; } return $content; } /** * Transforms the entities comment (customer, project, activity ...) into a one-liner. * * @param string|null $content * @param bool $fullLength * @return string */ public function commentOneLiner(?string $content, bool $fullLength = true): string { if (empty($content)) { return ''; } $addHellip = false; if (!$fullLength && \strlen($content) > 52) { $content = trim(substr($content, 0, 50)); $addHellip = true; } $content = explode(PHP_EOL, $content); $result = $content[0]; if (\count($content) > 1 || $addHellip) { $result .= ' …'; } return $result; } /** * Transforms the timesheet description content into HTML. * * @param string|null $content * @return string */ public function timesheetContent(?string $content): string { if (empty($content)) { return ''; } if ($this->isMarkdownEnabled()) { return $this->markdown->toHtml($content); } return nl2br($content); } /** * Transforms the given Markdown content into HTML * * @param string $content * @return string */ public function markdownToHtml(string $content): string { return $this->markdown->withFullMarkdownSupport($content); } }