Skip to content

Commit f9400d3

Browse files
committed
Add renderer option: wrapperClasses
This can be used to solve CSS style conflicts. Signed-off-by: Jack Cherng <[email protected]>
1 parent f2f613c commit f9400d3

File tree

7 files changed

+45
-29
lines changed

7 files changed

+45
-29
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ $rendererOptions = [
9292
// internally, ops (tags) are all int type but this is not good for human reading.
9393
// set this to "true" to convert them into string form before outputting.
9494
'outputTagAsString' => true,
95+
// extra HTML classes added to the DOM of the diff container
96+
'wrapperClasses' => ['diff-wrapper'],
9597
];
9698

9799
// one-line simply compare two files

example/demo.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
// internally, ops (tags) are all int type but this is not good for human reading.
4949
// set this to "true" to convert them into string form before outputting.
5050
'outputTagAsString' => false,
51+
// extra HTML classes added to the DOM of the diff container
52+
'wrapperClasses' => ['diff-wrapper'],
5153
];
5254

5355
?>

example/diff-table.css

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* - dart-sass v1.18.0
55
*/
6-
.diff {
6+
.diff-wrapper.diff {
77
background-color: #fff;
88
border-collapse: collapse;
99
border-spacing: 0;
@@ -15,88 +15,88 @@
1515
width: 100%;
1616
word-break: break-all;
1717
}
18-
.diff th {
18+
.diff-wrapper.diff th {
1919
font-weight: 700;
2020
}
21-
.diff td,
22-
.diff th {
21+
.diff-wrapper.diff td,
22+
.diff-wrapper.diff th {
2323
border-collapse: separate;
2424
border: none;
2525
padding: 1px 2px;
2626
background: #fff;
2727
}
28-
.diff td a,
29-
.diff th a {
28+
.diff-wrapper.diff td a,
29+
.diff-wrapper.diff th a {
3030
color: #000;
3131
cursor: inherit;
3232
pointer-events: none;
3333
}
34-
.diff thead th {
34+
.diff-wrapper.diff thead th {
3535
background: #a6a6a6;
3636
border-bottom: 1px solid black;
3737
padding: 4px;
3838
text-align: left;
3939
}
40-
.diff tbody.skipped {
40+
.diff-wrapper.diff tbody.skipped {
4141
border-top: 1px solid black;
4242
}
43-
.diff tbody.skipped td,
44-
.diff tbody.skipped th {
43+
.diff-wrapper.diff tbody.skipped td,
44+
.diff-wrapper.diff tbody.skipped th {
4545
display: none;
4646
}
47-
.diff tbody th {
47+
.diff-wrapper.diff tbody th {
4848
background: #cccccc;
4949
border-right: 1px solid black;
5050
text-align: right;
5151
vertical-align: top;
5252
width: 4em;
5353
}
54-
.diff tbody th.sign {
54+
.diff-wrapper.diff tbody th.sign {
5555
background: #fff;
5656
border-right: none;
5757
padding: 1px 0;
5858
text-align: center;
5959
width: 1em;
6060
}
61-
.diff tbody th.sign.del {
61+
.diff-wrapper.diff tbody th.sign.del {
6262
background: #fbe1e1;
6363
}
64-
.diff tbody th.sign.ins {
64+
.diff-wrapper.diff tbody th.sign.ins {
6565
background: #e1fbe1;
6666
}
67-
.diff.diff-html {
67+
.diff-wrapper.diff.diff-html {
6868
white-space: pre-wrap;
6969
}
70-
.diff.diff-html .change.change-eq .old,
71-
.diff.diff-html .change.change-eq .new {
70+
.diff-wrapper.diff.diff-html .change.change-eq .old,
71+
.diff-wrapper.diff.diff-html .change.change-eq .new {
7272
background: #fff;
7373
}
74-
.diff.diff-html .change .old {
74+
.diff-wrapper.diff.diff-html .change .old {
7575
background: #fbe1e1;
7676
}
77-
.diff.diff-html .change .new {
77+
.diff-wrapper.diff.diff-html .change .new {
7878
background: #e1fbe1;
7979
}
80-
.diff.diff-html .change ins,
81-
.diff.diff-html .change del {
80+
.diff-wrapper.diff.diff-html .change ins,
81+
.diff-wrapper.diff.diff-html .change del {
8282
font-weight: 700;
8383
text-decoration: none;
8484
}
85-
.diff.diff-html .change ins {
85+
.diff-wrapper.diff.diff-html .change ins {
8686
background: #a0f1a0;
8787
}
88-
.diff.diff-html .change del {
88+
.diff-wrapper.diff.diff-html .change del {
8989
background: #f1a0a0;
9090
}
91-
.diff.diff-html .edit-container:hover {
91+
.diff-wrapper.diff.diff-html .edit-container:hover {
9292
box-shadow: 0 0 8px 2px #888;
9393
position: relative;
9494
z-index: 5;
9595
}
96-
.diff.diff-html .edit-container.edited {
96+
.diff-wrapper.diff.diff-html .edit-container.edited {
9797
background: #e1e1fb;
9898
}
99-
.diff.diff-html .edit {
99+
.diff-wrapper.diff.diff-html .edit {
100100
display: block;
101101
outline: none;
102102
}

example/diff-table.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* - dart-sass v1.18.0
55
*/
66

7-
.diff {
7+
.diff-wrapper.diff {
88
$bg-color: #fff;
99
$text-color: invert($bg-color);
1010

src/Renderer/AbstractRenderer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ abstract class AbstractRenderer implements RendererInterface
4949
// internally, ops (tags) are all int type but this is not good for human reading.
5050
// set this to "true" to convert them into string form before outputting.
5151
'outputTagAsString' => false,
52+
// extra HTML classes added to the DOM of the diff container
53+
'wrapperClasses' => ['diff-wrapper'],
5254
];
5355

5456
/**

src/Renderer/Html/Inline.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ protected function renderWoker(Differ $differ): string
3131
return $this->getResultForIdenticals();
3232
}
3333

34-
$html = '<table class="diff diff-html diff-inline">';
34+
$wrapperClasses = \array_merge(
35+
$this->options['wrapperClasses'],
36+
['diff', 'diff-html', 'diff-inline']
37+
);
38+
39+
$html = '<table class="' . \implode(' ', $wrapperClasses) . '">';
3540

3641
$html .= $this->renderTableHeader();
3742

src/Renderer/Html/SideBySide.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ protected function renderWoker(Differ $differ): string
3131
return $this->getResultForIdenticals();
3232
}
3333

34-
$html = '<table class="diff diff-html diff-side-by-side">';
34+
$wrapperClasses = \array_merge(
35+
$this->options['wrapperClasses'],
36+
['diff', 'diff-html', 'diff-side-by-side']
37+
);
38+
39+
$html = '<table class="' . \implode(' ', $wrapperClasses) . '">';
3540

3641
$html .= $this->renderTableHeader();
3742

0 commit comments

Comments
 (0)