Skip to content

Commit a3e968c

Browse files
committed
Replaced css by class
1 parent 329edfa commit a3e968c

File tree

3 files changed

+82
-69
lines changed

3 files changed

+82
-69
lines changed

examples/css/highlighter.css

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/Highlighter.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Demyanovs\PHPHighlight;
44

5+
use Demyanovs\PHPHighlight\Themes\Styles;
56
use Demyanovs\PHPHighlight\Themes\Theme;
67

78
class Highlighter
@@ -75,12 +76,12 @@ private function wrapCode(string $text, string $bgColor = '', string $filePath =
7576
$wrapper = '<div class="code-block-wrapper">';
7677
if ($this->_showActionPanel) {
7778
$wrapper .= '
78-
<div class="meta">
79-
<div class="actions">
80-
<span class="js-copy-clipboard copy-text" onclick="PHPHighlight.copyClipboard(this)">copy</span>
81-
<span class="meta-divider"></span>
79+
<div class="meta" style="' . Styles::getCodeBlockWrapperMetaStyle() . '">
80+
<div class="actions" style="' . Styles::getCodeBlockWrapperActionsStyle() . '">
81+
<span class="js-copy-clipboard copy-text" style="' . Styles::getCodeBlockWrapperCopyTextStyle() . '" onclick="PHPHighlight.copyClipboard(this)">copy</span>
82+
<span class="meta-divider" style="' . Styles::getCodeBlockWrapperMetaDividerStyle() . '"></span>
8283
</div>
83-
<div class="info">
84+
<div class="info" style="' . Styles::getCodeBlockWrapperInfoStyle() . '">
8485
<span>' . $filePath . '</span>
8586
</div>
8687
</div>';
@@ -91,7 +92,7 @@ private function wrapCode(string $text, string $bgColor = '', string $filePath =
9192
if ($this->_showLineNumbers) {
9293
$line_numbers = $this->setLineNumbers(count(explode(PHP_EOL, $text)));
9394
}
94-
$wrapper .= '<div class="code-highlighter" style="background-color: ' . $bgColor . '">' . $line_numbers . '<div class="code-block">' . $text . '</div></div></div>';
95+
$wrapper .= '<div class="code-highlighter" style="' . Styles::getCodeHighlighterStyle() . '; background-color: ' . $bgColor . '">' . $line_numbers . '<div class="code-block">' . $text . '</div></div></div>';
9596

9697
return $wrapper;
9798
}
@@ -100,10 +101,10 @@ private function setLineNumbers(int $count) : string
100101
{
101102
$line_numbers = '';
102103
for ($i = 1; $i < $count+1; $i++) {
103-
$line_numbers .= '<span class="line-number" style="color: ' . $this->_theme::getDefaultColor() . '">' . $i . '</span>';
104+
$line_numbers .= '<span class="line-number" style="' . Styles::getLineNumberStyle() . '; color: ' . $this->_theme::getDefaultColor() . '">' . $i . '</span>';
104105
}
105106

106-
return '<div class="line-numbers">' . $line_numbers . '</div>';
107+
return '<div class="line-numbers" style="' . Styles::getLineNumbersStyle() . '">' . $line_numbers . '</div>';
107108
}
108109

109110
public function setShowActionPanel(bool $status) : void

src/Themes/Styles.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Class for replacing css file
4+
*/
5+
6+
namespace Demyanovs\PHPHighlight\Themes;
7+
8+
class Styles
9+
{
10+
/** @var string */
11+
private static $_codeHighlighterStyle = "display: block; padding: 5px; border: 1px solid #ddd; border-radius: 3px; font-size: 12px; font-family: 'SFMono-Regular',Consolas,'Liberation Mono',Menlo,Courier,monospace; overflow-x: auto; overflow-y: hidden; white-space: pre-wrap; tab-size: 4;";
12+
13+
/** @var string */
14+
private static $_codeBlockWrapperMetaStyle = 'padding: 5px 10px; border: 1px solid #ddd; border-bottom: none; background-color: #eee; border-top-left-radius: 4px; border-top-right-radius: 4px;';
15+
16+
/** @var string */
17+
private static $_codeBlockWrapperInfoStyle = 'height: 23px; line-height: 23px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;';
18+
19+
/** @var string */
20+
private static $_codeBlockWrapperActionsStyle = 'float: left; line-height: 22px; margin-right: 10px;';
21+
22+
/** @var string */
23+
private static $_codeBlockWrapperMetaDivider = 'display: inline-block; width: 1px; height: 15px; margin: 0 3px; vertical-align: middle; background-color: #ddd;';
24+
25+
/** @var string */
26+
private static $_codeBlockWrapperCopyTextStyle = 'font-size: 16px; cursor: pointer;';
27+
28+
/** @var string */
29+
private static $_lineNumbersStyle = 'margin-right: 15px; color: #000; font-weight: normal; float: left;';
30+
31+
/** @var string */
32+
private static $_lineNumberStyle = 'display: block;';
33+
34+
public static function getCodeHighlighterStyle() : string
35+
{
36+
return self::$_codeHighlighterStyle;
37+
}
38+
39+
public static function getCodeBlockWrapperMetaStyle() : string
40+
{
41+
return self::$_codeBlockWrapperMetaStyle;
42+
}
43+
44+
public static function getCodeBlockWrapperInfoStyle() : string
45+
{
46+
return self::$_codeBlockWrapperInfoStyle;
47+
}
48+
49+
public static function getCodeBlockWrapperActionsStyle() : string
50+
{
51+
return self::$_codeBlockWrapperActionsStyle;
52+
}
53+
54+
public static function getCodeBlockWrapperMetaDividerStyle() : string
55+
{
56+
return self::$_codeBlockWrapperMetaDivider;
57+
}
58+
59+
public static function getCodeBlockWrapperCopyTextStyle() : string
60+
{
61+
return self::$_codeBlockWrapperCopyTextStyle;
62+
}
63+
64+
public static function getLineNumbersStyle() : string
65+
{
66+
return self::$_lineNumbersStyle;
67+
}
68+
69+
public static function getLineNumberStyle() : string
70+
{
71+
return self::$_lineNumberStyle;
72+
}
73+
}

0 commit comments

Comments
 (0)