diff2html/src/__tests__/diff2html-tests.ts

1263 lines
279 KiB
TypeScript
Raw Normal View History

import fs from 'fs';
2019-12-29 22:31:32 +00:00
import { parse, html } from '../diff2html';
import { DiffFile, LineType, OutputFormatType } from '../types';
const diffExample1 =
2019-12-29 22:31:32 +00:00
'diff --git a/sample b/sample\n' +
'index 0000001..0ddf2ba\n' +
'--- a/sample\n' +
'+++ b/sample\n' +
'@@ -1 +1 @@\n' +
'-test\n' +
'+test1\n';
2019-10-12 21:45:49 +00:00
const jsonExample1: DiffFile[] = [
{
blocks: [
{
lines: [
{
2019-12-29 22:31:32 +00:00
content: '-test',
2019-10-12 21:45:49 +00:00
type: LineType.DELETE,
oldNumber: 1,
2019-12-29 22:31:32 +00:00
newNumber: undefined,
},
{
2019-12-29 22:31:32 +00:00
content: '+test1',
2019-10-12 21:45:49 +00:00
type: LineType.INSERT,
oldNumber: undefined,
2019-12-29 22:31:32 +00:00
newNumber: 1,
},
],
2019-10-12 21:45:49 +00:00
oldStartLine: 1,
oldStartLine2: undefined,
newStartLine: 1,
2019-12-29 22:31:32 +00:00
header: '@@ -1 +1 @@',
},
],
deletedLines: 1,
addedLines: 1,
2019-12-29 22:31:32 +00:00
checksumBefore: '0000001',
checksumAfter: '0ddf2ba',
oldName: 'sample',
newName: 'sample',
language: '',
2019-10-12 21:45:49 +00:00
isCombined: false,
2019-12-29 22:31:32 +00:00
isGitDiff: true,
},
];
2016-04-25 16:12:27 +00:00
2019-12-29 22:31:32 +00:00
describe('Diff2Html', () => {
describe('parse', () => {
2019-12-29 22:31:32 +00:00
it('should parse simple diff to json', () => {
const diff =
2019-12-29 22:31:32 +00:00
'diff --git a/sample b/sample\n' +
'index 0000001..0ddf2ba\n' +
'--- a/sample\n' +
'+++ b/sample\n' +
'@@ -1 +1 @@\n' +
'-test\n' +
'+test1\n';
2019-10-12 21:45:49 +00:00
const result = parse(diff);
2019-12-22 19:52:51 +00:00
expect(result).toMatchInlineSnapshot(`
2022-10-15 23:01:01 +00:00
[
{
2019-12-22 19:52:51 +00:00
"addedLines": 1,
2022-10-15 23:01:01 +00:00
"blocks": [
{
2019-12-22 19:52:51 +00:00
"header": "@@ -1 +1 @@",
2022-10-15 23:01:01 +00:00
"lines": [
{
2019-12-22 19:52:51 +00:00
"content": "-test",
"newNumber": undefined,
"oldNumber": 1,
"type": "delete",
},
2022-10-15 23:01:01 +00:00
{
2019-12-22 19:52:51 +00:00
"content": "+test1",
"newNumber": 1,
"oldNumber": undefined,
"type": "insert",
},
],
"newStartLine": 1,
"oldStartLine": 1,
"oldStartLine2": null,
},
],
"checksumAfter": "0ddf2ba",
"checksumBefore": "0000001",
"deletedLines": 1,
"isCombined": false,
"isGitDiff": true,
"language": undefined,
"newName": "sample",
"oldName": "sample",
},
]
`);
});
// Test case for issue #49
2019-12-29 22:31:32 +00:00
it('should parse diff with added EOF', () => {
const diff =
2019-12-29 22:31:32 +00:00
'diff --git a/sample.scala b/sample.scala\n' +
'index b583263..8b2fc3e 100644\n' +
'--- a/b583263..8b2fc3e\n' +
'+++ b/8b2fc3e\n' +
'@@ -50,5 +50,7 @@ case class Response[+A](value: Option[A],\n' +
' object ResponseErrorCode extends JsonEnumeration {\n' +
' val NoError, ServiceError, JsonError,\n' +
' InvalidPermissions, MissingPermissions, GenericError,\n' +
'- TokenRevoked, MissingToken = Value\n' +
'-}\n' +
'\\ No newline at end of file\n' +
'+ TokenRevoked, MissingToken,\n' +
'+ IndexLock, RepositoryError, NotValidRepo, PullRequestNotMergeable, BranchError,\n' +
'+ PluginError, CodeParserError, EngineError = Value\n' +
'+}\n';
2019-10-12 21:45:49 +00:00
const result = parse(diff);
2019-12-22 19:52:51 +00:00
expect(result).toMatchInlineSnapshot(`
2022-10-15 23:01:01 +00:00
[
{
2019-12-22 19:52:51 +00:00
"addedLines": 4,
2022-10-15 23:01:01 +00:00
"blocks": [
{
2019-12-22 19:52:51 +00:00
"header": "@@ -50,5 +50,7 @@ case class Response[+A](value: Option[A],",
2022-10-15 23:01:01 +00:00
"lines": [
{
2019-12-22 19:52:51 +00:00
"content": " object ResponseErrorCode extends JsonEnumeration {",
"newNumber": 50,
"oldNumber": 50,
"type": "context",
},
2022-10-15 23:01:01 +00:00
{
2019-12-22 19:52:51 +00:00
"content": " val NoError, ServiceError, JsonError,",
"newNumber": 51,
"oldNumber": 51,
"type": "context",
},
2022-10-15 23:01:01 +00:00
{
2019-12-22 19:52:51 +00:00
"content": " InvalidPermissions, MissingPermissions, GenericError,",
"newNumber": 52,
"oldNumber": 52,
"type": "context",
},
2022-10-15 23:01:01 +00:00
{
2019-12-22 19:52:51 +00:00
"content": "- TokenRevoked, MissingToken = Value",
"newNumber": undefined,
"oldNumber": 53,
"type": "delete",
},
2022-10-15 23:01:01 +00:00
{
2019-12-22 19:52:51 +00:00
"content": "-}",
"newNumber": undefined,
"oldNumber": 54,
"type": "delete",
},
2022-10-15 23:01:01 +00:00
{
2019-12-22 19:52:51 +00:00
"content": "+ TokenRevoked, MissingToken,",
"newNumber": 53,
"oldNumber": undefined,
"type": "insert",
},
2022-10-15 23:01:01 +00:00
{
2019-12-22 19:52:51 +00:00
"content": "+ IndexLock, RepositoryError, NotValidRepo, PullRequestNotMergeable, BranchError,",
"newNumber": 54,
"oldNumber": undefined,
"type": "insert",
},
2022-10-15 23:01:01 +00:00
{
2019-12-22 19:52:51 +00:00
"content": "+ PluginError, CodeParserError, EngineError = Value",
"newNumber": 55,
"oldNumber": undefined,
"type": "insert",
},
2022-10-15 23:01:01 +00:00
{
2019-12-22 19:52:51 +00:00
"content": "+}",
"newNumber": 56,
"oldNumber": undefined,
"type": "insert",
},
],
"newStartLine": 50,
"oldStartLine": 50,
"oldStartLine2": null,
},
],
"checksumAfter": "8b2fc3e",
"checksumBefore": "b583263",
"deletedLines": 2,
"isCombined": false,
"isGitDiff": true,
"language": "8b2fc3e",
"mode": "100644",
"newName": "8b2fc3e",
"oldName": "b583263..8b2fc3e",
},
]
`);
});
});
2016-04-25 16:12:27 +00:00
describe('html', () => {
2019-12-29 22:31:32 +00:00
it('should generate pretty line by line html from diff', () => {
2019-10-13 18:21:19 +00:00
const result = html(diffExample1, { drawFileList: false });
2019-12-22 19:52:51 +00:00
expect(result).toMatchInlineSnapshot(`
2022-10-15 23:01:01 +00:00
"<div class="d2h-wrapper">
<div id="d2h-675094" class="d2h-file-wrapper" data-lang="">
<div class="d2h-file-header">
<span class="d2h-file-name-wrapper">
<svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">
<path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>
</svg> <span class="d2h-file-name">sample</span>
<span class="d2h-tag d2h-changed d2h-changed-tag">CHANGED</span></span>
<label class="d2h-file-collapse">
<input class="d2h-file-collapse-input" type="checkbox" name="viewed" value="viewed">
2021-01-23 15:07:14 +00:00
Viewed
</label>
2019-12-22 19:52:51 +00:00
</div>
2022-10-15 23:01:01 +00:00
<div class="d2h-file-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
2019-12-22 19:52:51 +00:00
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-info"></td>
<td class="d2h-info">
<div class="d2h-code-line">@@ -1 +1 @@</div>
2019-12-22 19:52:51 +00:00
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del d2h-change">
<div class="line-num1">1</div>
<div class="line-num2"></div>
2019-12-22 19:52:51 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"><del>test</del></span>
2019-12-22 19:52:51 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-ins d2h-change">
<div class="line-num1"></div>
<div class="line-num2">1</div>
2019-12-22 19:52:51 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-ins d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">+</span>
<span class="d2h-code-line-ctn"><ins>test1</ins></span>
2019-12-22 19:52:51 +00:00
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>"
`);
2016-04-25 16:12:27 +00:00
});
2019-12-29 22:31:32 +00:00
it('should generate pretty line by line html from json', () => {
2019-10-13 18:21:19 +00:00
const result = html(jsonExample1, { drawFileList: false });
2019-12-22 19:52:51 +00:00
expect(result).toMatchInlineSnapshot(`
2022-10-15 23:01:01 +00:00
"<div class="d2h-wrapper">
<div id="d2h-675094" class="d2h-file-wrapper" data-lang="">
<div class="d2h-file-header">
<span class="d2h-file-name-wrapper">
<svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">
<path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>
</svg> <span class="d2h-file-name">sample</span>
<span class="d2h-tag d2h-changed d2h-changed-tag">CHANGED</span></span>
<label class="d2h-file-collapse">
<input class="d2h-file-collapse-input" type="checkbox" name="viewed" value="viewed">
2021-01-23 15:07:14 +00:00
Viewed
</label>
2019-12-22 19:52:51 +00:00
</div>
2022-10-15 23:01:01 +00:00
<div class="d2h-file-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
2019-12-22 19:52:51 +00:00
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-info"></td>
<td class="d2h-info">
<div class="d2h-code-line">@@ -1 +1 @@</div>
2019-12-22 19:52:51 +00:00
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del d2h-change">
<div class="line-num1">1</div>
<div class="line-num2"></div>
2019-12-22 19:52:51 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"><del>test</del></span>
2019-12-22 19:52:51 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-ins d2h-change">
<div class="line-num1"></div>
<div class="line-num2">1</div>
2019-12-22 19:52:51 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-ins d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">+</span>
<span class="d2h-code-line-ctn"><ins>test1</ins></span>
2019-12-22 19:52:51 +00:00
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>"
`);
2016-04-25 16:12:27 +00:00
});
2019-12-29 22:31:32 +00:00
it('should generate pretty diff with files summary', () => {
2019-10-13 18:21:19 +00:00
const result = html(diffExample1, { drawFileList: true });
2019-12-22 19:52:51 +00:00
expect(result).toMatchInlineSnapshot(`
2022-10-15 23:01:01 +00:00
"<div class="d2h-file-list-wrapper">
<div class="d2h-file-list-header">
<span class="d2h-file-list-title">Files changed (1)</span>
<a class="d2h-file-switch d2h-hide">hide</a>
<a class="d2h-file-switch d2h-show">show</a>
2019-12-22 19:52:51 +00:00
</div>
2022-10-15 23:01:01 +00:00
<ol class="d2h-file-list">
<li class="d2h-file-list-line">
<span class="d2h-file-name-wrapper">
<svg aria-hidden="true" class="d2h-icon d2h-changed" height="16" title="modified" version="1.1"
viewBox="0 0 14 16" width="14">
<path d="M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM4 8c0-1.66 1.34-3 3-3s3 1.34 3 3-1.34 3-3 3-3-1.34-3-3z"></path>
</svg> <a href="#d2h-675094" class="d2h-file-name">sample</a>
<span class="d2h-file-stats">
<span class="d2h-lines-added">+1</span>
<span class="d2h-lines-deleted">-1</span>
2019-12-22 19:52:51 +00:00
</span>
</span>
</li>
</ol>
2022-10-15 23:01:01 +00:00
</div><div class="d2h-wrapper">
<div id="d2h-675094" class="d2h-file-wrapper" data-lang="">
<div class="d2h-file-header">
<span class="d2h-file-name-wrapper">
<svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">
<path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>
</svg> <span class="d2h-file-name">sample</span>
<span class="d2h-tag d2h-changed d2h-changed-tag">CHANGED</span></span>
<label class="d2h-file-collapse">
<input class="d2h-file-collapse-input" type="checkbox" name="viewed" value="viewed">
2021-01-23 15:07:14 +00:00
Viewed
</label>
2019-12-22 19:52:51 +00:00
</div>
2022-10-15 23:01:01 +00:00
<div class="d2h-file-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
2019-12-22 19:52:51 +00:00
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-info"></td>
<td class="d2h-info">
<div class="d2h-code-line">@@ -1 +1 @@</div>
2019-12-22 19:52:51 +00:00
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del d2h-change">
<div class="line-num1">1</div>
<div class="line-num2"></div>
2019-12-22 19:52:51 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"><del>test</del></span>
2019-12-22 19:52:51 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-ins d2h-change">
<div class="line-num1"></div>
<div class="line-num2">1</div>
2019-12-22 19:52:51 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-ins d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">+</span>
<span class="d2h-code-line-ctn"><ins>test1</ins></span>
2019-12-22 19:52:51 +00:00
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>"
`);
2016-04-25 16:12:27 +00:00
});
2019-12-29 22:31:32 +00:00
it('should generate pretty side by side html from diff', () => {
2019-10-21 22:37:42 +00:00
const result = html(diffExample1, { outputFormat: OutputFormatType.SIDE_BY_SIDE, drawFileList: false });
2019-12-22 19:52:51 +00:00
expect(result).toMatchInlineSnapshot(`
2022-10-15 23:01:01 +00:00
"<div class="d2h-wrapper">
<div id="d2h-675094" class="d2h-file-wrapper" data-lang="">
<div class="d2h-file-header">
<span class="d2h-file-name-wrapper">
<svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">
<path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>
</svg> <span class="d2h-file-name">sample</span>
<span class="d2h-tag d2h-changed d2h-changed-tag">CHANGED</span></span>
<label class="d2h-file-collapse">
<input class="d2h-file-collapse-input" type="checkbox" name="viewed" value="viewed">
2021-01-23 15:07:14 +00:00
Viewed
</label>
2019-12-22 19:52:51 +00:00
</div>
2022-10-15 23:01:01 +00:00
<div class="d2h-files-diff">
<div class="d2h-file-side-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
2019-12-22 19:52:51 +00:00
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-side-linenumber d2h-info"></td>
<td class="d2h-info">
<div class="d2h-code-side-line">@@ -1 +1 @@</div>
2019-12-22 19:52:51 +00:00
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-side-linenumber d2h-del d2h-change">
2019-12-22 19:52:51 +00:00
1
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del d2h-change">
<div class="d2h-code-side-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"><del>test</del></span>
2019-12-22 19:52:51 +00:00
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
2022-10-15 23:01:01 +00:00
<div class="d2h-file-side-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
2019-12-22 19:52:51 +00:00
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-side-linenumber d2h-info"></td>
<td class="d2h-info">
2023-01-20 22:27:44 +00:00
<div class="d2h-code-side-line">&nbsp;</div>
2019-12-22 19:52:51 +00:00
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-side-linenumber d2h-ins d2h-change">
2019-12-22 19:52:51 +00:00
1
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-ins d2h-change">
<div class="d2h-code-side-line">
<span class="d2h-code-line-prefix">+</span>
<span class="d2h-code-line-ctn"><ins>test1</ins></span>
2019-12-22 19:52:51 +00:00
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>"
`);
2016-04-25 16:12:27 +00:00
});
2019-12-29 22:31:32 +00:00
it('should generate pretty side by side html from json', () => {
2019-10-21 22:37:42 +00:00
const result = html(jsonExample1, { outputFormat: OutputFormatType.SIDE_BY_SIDE, drawFileList: false });
2019-12-22 19:52:51 +00:00
expect(result).toMatchInlineSnapshot(`
2022-10-15 23:01:01 +00:00
"<div class="d2h-wrapper">
<div id="d2h-675094" class="d2h-file-wrapper" data-lang="">
<div class="d2h-file-header">
<span class="d2h-file-name-wrapper">
<svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">
<path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>
</svg> <span class="d2h-file-name">sample</span>
<span class="d2h-tag d2h-changed d2h-changed-tag">CHANGED</span></span>
<label class="d2h-file-collapse">
<input class="d2h-file-collapse-input" type="checkbox" name="viewed" value="viewed">
2021-01-23 15:07:14 +00:00
Viewed
</label>
2019-12-22 19:52:51 +00:00
</div>
2022-10-15 23:01:01 +00:00
<div class="d2h-files-diff">
<div class="d2h-file-side-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
2019-12-22 19:52:51 +00:00
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-side-linenumber d2h-info"></td>
<td class="d2h-info">
<div class="d2h-code-side-line">@@ -1 +1 @@</div>
2019-12-22 19:52:51 +00:00
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-side-linenumber d2h-del d2h-change">
2019-12-22 19:52:51 +00:00
1
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del d2h-change">
<div class="d2h-code-side-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"><del>test</del></span>
2019-12-22 19:52:51 +00:00
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
2022-10-15 23:01:01 +00:00
<div class="d2h-file-side-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
2019-12-22 19:52:51 +00:00
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-side-linenumber d2h-info"></td>
<td class="d2h-info">
2023-01-20 22:27:44 +00:00
<div class="d2h-code-side-line">&nbsp;</div>
2019-12-22 19:52:51 +00:00
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-side-linenumber d2h-ins d2h-change">
2019-12-22 19:52:51 +00:00
1
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-ins d2h-change">
<div class="d2h-code-side-line">
<span class="d2h-code-line-prefix">+</span>
<span class="d2h-code-line-ctn"><ins>test1</ins></span>
2019-12-22 19:52:51 +00:00
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>"
`);
2016-04-25 16:12:27 +00:00
});
2019-12-29 22:31:32 +00:00
it('should generate pretty side by side html from diff 2', () => {
2019-10-21 22:37:42 +00:00
const result = html(diffExample1, { outputFormat: OutputFormatType.SIDE_BY_SIDE, drawFileList: true });
2019-12-22 19:52:51 +00:00
expect(result).toMatchInlineSnapshot(`
2022-10-15 23:01:01 +00:00
"<div class="d2h-file-list-wrapper">
<div class="d2h-file-list-header">
<span class="d2h-file-list-title">Files changed (1)</span>
<a class="d2h-file-switch d2h-hide">hide</a>
<a class="d2h-file-switch d2h-show">show</a>
2019-12-22 19:52:51 +00:00
</div>
2022-10-15 23:01:01 +00:00
<ol class="d2h-file-list">
<li class="d2h-file-list-line">
<span class="d2h-file-name-wrapper">
<svg aria-hidden="true" class="d2h-icon d2h-changed" height="16" title="modified" version="1.1"
viewBox="0 0 14 16" width="14">
<path d="M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM4 8c0-1.66 1.34-3 3-3s3 1.34 3 3-1.34 3-3 3-3-1.34-3-3z"></path>
</svg> <a href="#d2h-675094" class="d2h-file-name">sample</a>
<span class="d2h-file-stats">
<span class="d2h-lines-added">+1</span>
<span class="d2h-lines-deleted">-1</span>
2019-12-22 19:52:51 +00:00
</span>
</span>
</li>
</ol>
2022-10-15 23:01:01 +00:00
</div><div class="d2h-wrapper">
<div id="d2h-675094" class="d2h-file-wrapper" data-lang="">
<div class="d2h-file-header">
<span class="d2h-file-name-wrapper">
<svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">
<path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>
</svg> <span class="d2h-file-name">sample</span>
<span class="d2h-tag d2h-changed d2h-changed-tag">CHANGED</span></span>
<label class="d2h-file-collapse">
<input class="d2h-file-collapse-input" type="checkbox" name="viewed" value="viewed">
2021-01-23 15:07:14 +00:00
Viewed
</label>
2019-12-22 19:52:51 +00:00
</div>
2022-10-15 23:01:01 +00:00
<div class="d2h-files-diff">
<div class="d2h-file-side-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
2019-12-22 19:52:51 +00:00
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-side-linenumber d2h-info"></td>
<td class="d2h-info">
<div class="d2h-code-side-line">@@ -1 +1 @@</div>
2019-12-22 19:52:51 +00:00
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-side-linenumber d2h-del d2h-change">
2019-12-22 19:52:51 +00:00
1
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del d2h-change">
<div class="d2h-code-side-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"><del>test</del></span>
2019-12-22 19:52:51 +00:00
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
2022-10-15 23:01:01 +00:00
<div class="d2h-file-side-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
2019-12-22 19:52:51 +00:00
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-side-linenumber d2h-info"></td>
<td class="d2h-info">
2023-01-20 22:27:44 +00:00
<div class="d2h-code-side-line">&nbsp;</div>
2019-12-22 19:52:51 +00:00
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-side-linenumber d2h-ins d2h-change">
2019-12-22 19:52:51 +00:00
1
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-ins d2h-change">
<div class="d2h-code-side-line">
<span class="d2h-code-line-prefix">+</span>
<span class="d2h-code-line-ctn"><ins>test1</ins></span>
2019-12-22 19:52:51 +00:00
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>"
`);
2016-04-25 16:12:27 +00:00
});
2017-03-17 23:57:09 +00:00
2019-12-29 22:31:32 +00:00
it('should generate pretty side by side html from diff with html on headers', () => {
const diffExample2 =
2019-12-29 22:31:32 +00:00
'diff --git a/CHANGELOG.md b/CHANGELOG.md\n' +
'index fc3e3f4..b486d10 100644\n' +
'--- a/CHANGELOG.md\n' +
'+++ b/CHANGELOG.md\n' +
'@@ -1,7 +1,6 @@\n' +
' # Change Log\n' +
' All notable changes to this project will be documented in this file.\n' +
' This project adheres to [Semantic Versioning](http://semver.org/).\n' +
2017-03-17 23:57:09 +00:00
'-$a="<table><tr><td>Use the following format for additions: ` - VERSION: [feature/patch (if applicable)] Short description of change. Links to relevant issues/PRs.`\n' +
' $a="<table><tr><td>\n' +
2019-12-29 22:31:32 +00:00
' $a="<table><tr><td>- 1.1.9: Fix around ubuntu\'s inability to cache promises. [#877](https://github.com/FredrikNoren/ungit/pull/878)\n' +
' - 1.1.8:\n' +
'@@ -11,7 +10,7 @@ $a=&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;- 1.1.9: Fix around ubuntu&#x27;s inability to cache promises. [#8\n' +
' - 1.1.7:\n' +
' - Fix diff flickering issue and optimization [#865](https://github.com/FredrikNoren/ungit/pull/865)\n' +
' - Fix credential dialog issue [#864](https://github.com/FredrikNoren/ungit/pull/864)\n' +
'- - Fix HEAD branch order when redraw [#858](https://github.com/FredrikNoren/ungit/issues/858)\n' +
'+4 - Fix HEAD branch order when redraw [#858](https://github.com/FredrikNoren/ungit/issues/858)\n' +
' - 1.1.6: Fix path auto complete [#861](https://github.com/FredrikNoren/ungit/issues/861)\n' +
2017-03-17 23:57:09 +00:00
' - 1.1.5: Update "Toggle all" button after commit or changing selected files [#859](https://github.com/FredrikNoren/ungit/issues/859)\n' +
2019-12-29 22:31:32 +00:00
' - 1.1.4: [patch] Promise refactoring\n' +
' \n';
2019-10-13 18:21:19 +00:00
const result = html(diffExample2, { drawFileList: false });
2019-12-22 19:52:51 +00:00
expect(result).toMatchInlineSnapshot(`
2022-10-15 23:01:01 +00:00
"<div class="d2h-wrapper">
<div id="d2h-211439" class="d2h-file-wrapper" data-lang="md">
<div class="d2h-file-header">
<span class="d2h-file-name-wrapper">
<svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">
<path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>
</svg> <span class="d2h-file-name">CHANGELOG.md</span>
<span class="d2h-tag d2h-changed d2h-changed-tag">CHANGED</span></span>
<label class="d2h-file-collapse">
<input class="d2h-file-collapse-input" type="checkbox" name="viewed" value="viewed">
2021-01-23 15:07:14 +00:00
Viewed
</label>
</div>
2022-10-15 23:01:01 +00:00
<div class="d2h-file-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
2021-01-23 15:07:14 +00:00
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-info"></td>
<td class="d2h-info">
<div class="d2h-code-line">@@ -1,7 +1,6 @@</div>
2021-01-23 15:07:14 +00:00
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">1</div>
<div class="line-num2">1</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn"># Change Log</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">2</div>
<div class="line-num2">2</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn">All notable changes to this project will be documented in this file.</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">3</div>
<div class="line-num2">3</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn">This project adheres to [Semantic Versioning](http:&#x2F;&#x2F;semver.org&#x2F;).</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del">
<div class="line-num1">4</div>
<div class="line-num2"></div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn">$a=&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;Use the following format for additions: \` - VERSION: [feature&#x2F;patch (if applicable)] Short description of change. Links to relevant issues&#x2F;PRs.\`</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">5</div>
<div class="line-num2">4</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn">$a=&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">6</div>
<div class="line-num2">5</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn">$a=&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;- 1.1.9: Fix around ubuntu&#x27;s inability to cache promises. [#877](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;pull&#x2F;878)</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">7</div>
<div class="line-num2">6</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn">- 1.1.8:</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr>
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-info"></td>
<td class="d2h-info">
<div class="d2h-code-line">@@ -11,7 +10,7 @@ $a=&amp;quot;&amp;lt;table&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;- 1.1.9: Fix around ubuntu&amp;#x27;s inability to cache promises. [#8</div>
2021-01-23 15:07:14 +00:00
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">11</div>
<div class="line-num2">10</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn">- 1.1.7:</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">12</div>
<div class="line-num2">11</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn"> - Fix diff flickering issue and optimization [#865](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;pull&#x2F;865)</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">13</div>
<div class="line-num2">12</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn"> - Fix credential dialog issue [#864](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;pull&#x2F;864)</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del d2h-change">
<div class="line-num1">14</div>
<div class="line-num2"></div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"> - Fix HEAD branch order when redraw [#858](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;issues&#x2F;858)</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-ins d2h-change">
<div class="line-num1"></div>
<div class="line-num2">13</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-ins d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">+</span>
<span class="d2h-code-line-ctn"><ins>4</ins> - Fix HEAD branch order when redraw [#858](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;issues&#x2F;858)</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">15</div>
<div class="line-num2">14</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn">- 1.1.6: Fix path auto complete [#861](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;issues&#x2F;861)</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">16</div>
<div class="line-num2">15</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn">- 1.1.5: Update &quot;Toggle all&quot; button after commit or changing selected files [#859](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;issues&#x2F;859)</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">17</div>
<div class="line-num2">16</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn">- 1.1.4: [patch] Promise refactoring</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">18</div>
<div class="line-num2">17</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn"><br></span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
2020-02-09 17:02:44 +00:00
</div>
2021-01-23 15:07:14 +00:00
</div>"
`);
2017-03-17 23:57:09 +00:00
});
it('should generate html correctly without escaping twice', () => {
const diff =
'--- src/index.html\n' +
'+++ src/index.html\n' +
'@@ -1,2 +1,2 @@\n' +
'-<!-- commented code -->\n' +
'-</div>\n' +
'+<html>\n' +
'+<body>';
const result = html(diff);
expect(result).toMatchInlineSnapshot(`
2022-10-15 23:01:01 +00:00
"<div class="d2h-file-list-wrapper">
<div class="d2h-file-list-header">
<span class="d2h-file-list-title">Files changed (1)</span>
<a class="d2h-file-switch d2h-hide">hide</a>
<a class="d2h-file-switch d2h-show">show</a>
</div>
2022-10-15 23:01:01 +00:00
<ol class="d2h-file-list">
<li class="d2h-file-list-line">
<span class="d2h-file-name-wrapper">
<svg aria-hidden="true" class="d2h-icon d2h-changed" height="16" title="modified" version="1.1"
viewBox="0 0 14 16" width="14">
<path d="M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM4 8c0-1.66 1.34-3 3-3s3 1.34 3 3-1.34 3-3 3-3-1.34-3-3z"></path>
</svg> <a href="#d2h-597266" class="d2h-file-name">src/index.html</a>
<span class="d2h-file-stats">
<span class="d2h-lines-added">+2</span>
<span class="d2h-lines-deleted">-2</span>
</span>
</span>
</li>
</ol>
2022-10-15 23:01:01 +00:00
</div><div class="d2h-wrapper">
<div id="d2h-597266" class="d2h-file-wrapper" data-lang="html">
<div class="d2h-file-header">
<span class="d2h-file-name-wrapper">
<svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">
<path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>
</svg> <span class="d2h-file-name">src/index.html</span>
<span class="d2h-tag d2h-changed d2h-changed-tag">CHANGED</span></span>
<label class="d2h-file-collapse">
<input class="d2h-file-collapse-input" type="checkbox" name="viewed" value="viewed">
2021-01-23 15:07:14 +00:00
Viewed
</label>
</div>
2022-10-15 23:01:01 +00:00
<div class="d2h-file-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-info"></td>
<td class="d2h-info">
<div class="d2h-code-line">@@ -1,2 +1,2 @@</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del d2h-change">
<div class="line-num1">1</div>
<div class="line-num2"></div>
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"><del>&lt;!-- commented code --&gt;</del></span>
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del d2h-change">
<div class="line-num1">2</div>
<div class="line-num2"></div>
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"><del>&lt;&#x2F;div</del>&gt;</span>
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-ins d2h-change">
<div class="line-num1"></div>
<div class="line-num2">1</div>
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-ins d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">+</span>
<span class="d2h-code-line-ctn"><ins>&lt;html&gt;</ins></span>
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-ins d2h-change">
<div class="line-num1"></div>
<div class="line-num2">2</div>
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-ins d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">+</span>
<span class="d2h-code-line-ctn"><ins>&lt;body</ins>&gt;</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>"
`);
});
it('should escape html correctly', () => {
const diff = fs.readFileSync('src/__tests__/diffs/bad-escaping.diff', 'utf-8');
const result = html(diff);
/* eslint-disable no-irregular-whitespace */
expect(result).toMatchInlineSnapshot(`
2022-10-15 23:01:01 +00:00
"<div class="d2h-file-list-wrapper">
<div class="d2h-file-list-header">
<span class="d2h-file-list-title">Files changed (1)</span>
<a class="d2h-file-switch d2h-hide">hide</a>
<a class="d2h-file-switch d2h-show">show</a>
2021-01-23 15:07:14 +00:00
</div>
2022-10-15 23:01:01 +00:00
<ol class="d2h-file-list">
<li class="d2h-file-list-line">
<span class="d2h-file-name-wrapper">
<svg aria-hidden="true" class="d2h-icon d2h-changed" height="16" title="modified" version="1.1"
viewBox="0 0 14 16" width="14">
<path d="M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM4 8c0-1.66 1.34-3 3-3s3 1.34 3 3-1.34 3-3 3-3-1.34-3-3z"></path>
</svg> <a href="#d2h-719103" class="d2h-file-name">web/assets/javascripts/application.js</a>
<span class="d2h-file-stats">
<span class="d2h-lines-added">+3</span>
<span class="d2h-lines-deleted">-8</span>
</span>
2021-01-23 15:07:14 +00:00
</span>
</li>
</ol>
2022-10-15 23:01:01 +00:00
</div><div class="d2h-wrapper">
<div id="d2h-719103" class="d2h-file-wrapper" data-lang="js">
<div class="d2h-file-header">
<span class="d2h-file-name-wrapper">
<svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">
<path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>
</svg> <span class="d2h-file-name">web/assets/javascripts/application.js</span>
<span class="d2h-tag d2h-changed d2h-changed-tag">CHANGED</span></span>
<label class="d2h-file-collapse">
<input class="d2h-file-collapse-input" type="checkbox" name="viewed" value="viewed">
2021-01-23 15:07:14 +00:00
Viewed
</label>
</div>
2022-10-15 23:01:01 +00:00
<div class="d2h-file-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
2021-01-23 15:07:14 +00:00
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-info"></td>
<td class="d2h-info">
<div class="d2h-code-line">@@ -1,5 +1,5 @@</div>
2021-01-23 15:07:14 +00:00
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del d2h-change">
<div class="line-num1">1</div>
<div class="line-num2"></div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn">&#x2F;*! jQuery v1.<del>8</del>.<del>2</del> <del>jquery.com</del> | jquery.org&#x2F;license *&#x2F;</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del d2h-change">
<div class="line-num1">2</div>
<div class="line-num2"></div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn">(function(a,b){function G(a){var b=F[a]={};return p.each(a.split(s),function(a,c){b[c]=!0}),b}function J(a,c,d){if(d===b&amp;&amp;a.nodeType===1){var e=&quot;data-&quot;+c.replace(I,&quot;-$1&quot;).toLowerCase();d=a.getAttribute(e);if(typeof d==&quot;string&quot;){try{d=d===&quot;true&quot;?!0:d===&quot;false&quot;?!1:d===&quot;null&quot;?null:+d+&quot;&quot;===d?+d:H.test(d)?p.parseJSON(d):d}catch(f){}p.data(a,c,d)}else d=b}return d}function K(a){var b;for(b in a){if(b===&quot;data&quot;&amp;&amp;p.isEmptyObject(a[b]))continue;if(b!==&quot;toJSON&quot;)return!1}return!0}function ba(){return!1}function bb(){return!0}function bh(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function bi(a,b){do a=a[b];while(a&amp;&amp;a.nodeType!==1);return a}function bj(a,b,c){b=b||0;if(p.isFunction(b))return p.grep(a,function(a,d){var e=!!b.call(a,d,a);return e===c});if(b.nodeType)return p.grep(a,function(a,d){return a===b===c});if(typeof b==&quot;string&quot;){var d=p.grep(a,function(a){return a.nodeType===1});if(be.test(b))return p.filter(b,d,!c);b=p.filter(b,d)}return p.grep(a,function(a,d){return p.inArray(a,b)&gt;=0===c})}function bk(a){var b=bl.split(&quot;|&quot;),c=a.createDocumentFragment();if(c.createElement)while(b.length)c.createElement(b.pop());return c}function bC(a,b){return a.getElementsByTagName(b)[0]||a.appendChild(a.ownerDocument.createElement(b))}function bD(a,b){if(b.nodeType!==1||!p.hasData(a))return;var c,d,e,f=p._data(a),g=p._data(b,f),h=f.events;if(h){delete g.handle,g.events={};for(c in h)for(d=0,e=h[c].length;d&lt;e;d++)p.event.add(b,c,h[c][d])}g.data&amp;&amp;(g.data=p.extend({},g.data))}function bE(a,b){var c;if(b.nodeType!==1)return;b.clearAttributes&amp;&amp;b.clearAttributes(),b.mergeAttributes&amp;&amp;b.mergeAttributes(a),c=b.nodeName.toLowerCase(),c===&quot;object&quot;?(b.parentNode&amp;&amp;(b.outerHTML=a.outerHTML),p.support.html5Clone&amp;&amp;a.innerHTML&amp;&amp;!p.trim(b.innerHTML)&amp;&amp;(b.innerHTML=a.innerHTML)):c===&quot;input&quot;&amp;&amp;bv.test(a.type)?(b.defaultChecked=b.checked=a.checked,b.value!==a.value&amp;&amp;(b.value=a.value)):c===&quot;option&quot;?b.selected=a.defaultSelected:c===&quot;input&quot;||c===&quot;textarea&quot;?b.defaultValue=a.defaultValue:c===&quot;script&quot;&amp;&amp;b.text!==a.text&amp;&amp;(b.text=a.text),b.removeAttribute(p.expando)}function bF(a){return typeof a.getElementsByTagName!=&quot;undefined&quot;?a.getElementsByTagName(&quot;*&quot;):typeof a.querySelectorAll!=&quot;undefined&quot;?a.querySelectorAll(&quot;*&quot;):[]}function bG(a){bv.test(a.type)&amp;&amp;(a.defaultChecked=a.checked)}function bY(a,b){if(b in a)return b;var c=b.charAt(0).toUpperCase()+b.slice(1),d=b,e=bW.length;while(e--){b=bW[e]+c;if(b in a)return b}return d}function bZ(a,b){return a=b||a,p.css(a,&quot;display&quot;)===&quot;none&quot;||!p.contains(a.ownerDocument,a)}function b$(a,b){var c,d,e=[],f=0,g=a.length;for(;f&lt;g;f++){c=a[f];if(!c.style)continue;e[f]=p._data(c,&quot;olddisplay&quot;),b?(!e[f]&amp;&amp;c.style.display===&quot;none&quot;&amp;&amp;(c.style.display=&quot;&quot;),c.style.display===&quot;&quot;&amp;&amp;bZ(c)&amp;&amp;(e[f]=p._data(c,&quot;olddisplay&quot;,cc(c.nodeName)))):(d=bH(c,&quot;display&quot;),!e[f]&amp;&amp;d!==&quot;none&quot;&amp;&amp;p._data(c,&quot;olddisplay&quot;,d))}for(f=0;f&lt;g;f++){c=a[f];if(!c.style)continue;if(!b||c.style.display===&quot;none&quot;||c.style.display===&quot;&quot;)c.style.display=b?e[f]||&quot;&quot;:&quot;none&quot;}return a}function b_(a,b,c){var d=bP.exec(b);return d?Math.max(0,d[1]-(c||0))+(d[2]||&quot;px&quot;):b}function ca(a,b,c,d){var e=c===(d?&quot;border&quot;:&quot;content&quot;)?4:b===&quot;width&quot;?1:0,f=0;for(;e&lt;4;e+=2)c===&quot;margin&quot;&amp;&amp;(f+=p.css(a,c+bV[e],!0)),d?(c===&quot;content&quot;&amp;&amp;(f-=parseFloat(bH(a,&quot;padding&quot;+bV[e]))||0),c!==&quot;margin&quot;&amp;&amp;(f-=parseFloat(bH(a,&quot;border&quot;+bV[e]+&quot;Width&quot;))||0)):(f+=parseFloat(bH(a,&quot;padding&quot;+bV[e]))||0,c!==&quot;padding&quot;&am
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-ins d2h-change">
<div class="line-num1"></div>
<div class="line-num2">1</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-ins d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">+</span>
<span class="d2h-code-line-ctn">&#x2F;*! jQuery v1.<ins>12</ins>.<ins>4</ins> <ins>|</ins> <ins>(c) jQuery Foundation </ins>| jquery.org&#x2F;license *&#x2F;</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-ins d2h-change">
<div class="line-num1"></div>
<div class="line-num2">2</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-ins d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">+</span>
<span class="d2h-code-line-ctn">!function(a,b){&quot;object&quot;==typeof module&amp;&amp;&quot;object&quot;==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error(&quot;jQuery requires a window with a document&quot;);return b(a)}:b(a)}(&quot;undefined&quot;!=typeof window?window:this,function(a,b){var c=[],d=a.document,e=c.slice,f=c.concat,g=c.push,h=c.indexOf,i={},j=i.toString,k=i.hasOwnProperty,l={},m=&quot;1.12.4&quot;,n=function(a,b){return new n.fn.init(a,b)},o=&#x2F;^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$&#x2F;g,p=&#x2F;^-ms-&#x2F;,q=&#x2F;-([\\da-z])&#x2F;gi,r=function(a,b){return b.toUpperCase()};n.fn=n.prototype={jquery:m,constructor:n,selector:&quot;&quot;,length:0,toArray:function(){return e.call(this)},get:function(a){return null!=a?0&gt;a?this[a+this.length]:this[a]:e.call(this)},pushStack:function(a){var b=n.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a){return n.each(this,a)},map:function(a){return this.pushStack(n.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(e.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0&gt;a?b:0);return this.pushStack(c&gt;=0&amp;&amp;b&gt;c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor()},push:g,sort:c.sort,splice:c.splice},n.extend=n.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for(&quot;boolean&quot;==typeof g&amp;&amp;(j=g,g=arguments[h]||{},h++),&quot;object&quot;==typeof g||n.isFunction(g)||(g={}),h===i&amp;&amp;(g=this,h--);i&gt;h;h++)if(null!=(e=arguments[h]))for(d in e)a=g[d],c=e[d],g!==c&amp;&amp;(j&amp;&amp;c&amp;&amp;(n.isPlainObject(c)||(b=n.isArray(c)))?(b?(b=!1,f=a&amp;&amp;n.isArray(a)?a:[]):f=a&amp;&amp;n.isPlainObject(a)?a:{},g[d]=n.extend(j,f,c)):void 0!==c&amp;&amp;(g[d]=c));return g},n.extend({expando:&quot;jQuery&quot;+(m+Math.random()).replace(&#x2F;\\D&#x2F;g,&quot;&quot;),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return&quot;function&quot;===n.type(a)},isArray:Array.isArray||function(a){return&quot;array&quot;===n.type(a)},isWindow:function(a){return null!=a&amp;&amp;a==a.window},isNumeric:function(a){var b=a&amp;&amp;a.toString();return!n.isArray(a)&amp;&amp;b-parseFloat(b)+1&gt;=0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},isPlainObject:function(a){var b;if(!a||&quot;object&quot;!==n.type(a)||a.nodeType||n.isWindow(a))return!1;try{if(a.constructor&amp;&amp;!k.call(a,&quot;constructor&quot;)&amp;&amp;!k.call(a.constructor.prototype,&quot;isPrototypeOf&quot;))return!1}catch(c){return!1}if(!l.ownFirst)for(b in a)return k.call(a,b);for(b in a);return void 0===b||k.call(a,b)},type:function(a){return null==a?a+&quot;&quot;:&quot;object&quot;==typeof a||&quot;function&quot;==typeof a?i[j.call(a)]||&quot;object&quot;:typeof a},globalEval:function(b){b&amp;&amp;n.trim(b)&amp;&amp;(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(p,&quot;ms-&quot;).replace(q,r)},nodeName:function(a,b){return a.nodeName&amp;&amp;a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b){var c,d=0;if(s(a)){for(c=a.length;c&gt;d;d++)if(b.call(a[d],d,a[d])===!1)break}else for(d in a)if(b.call(a[d],d,a[d])===!1)break;return a},trim:function(a){return null==a?&quot;&quot;:(a+&quot;&quot;).replace(o,&quot;&quot;)},makeArray:function(a,b){var c=b||[];return null!=a&amp;&amp;(s(Object(a))?n.merge(c,&quot;string&quot;==typeof a?[a]:a):g.call(c,a)),c},inArray:function(a,b,c){var d;if(b){if(h)return h.call(b,a,c);for(d=b.length,c=c?0&gt;c?Math.max(0,d+c):c:0;d&gt;c;c++)if(c in b&amp;&amp;b[c]===a)return c}return-1},merge:function(a,b){var c=+b.length,d=0,e=a.length;while(c&gt;d)a[e++]=b[d++];if(c!==c)while(void 0!==b[d])a[e++]=b[d++];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g&gt;f;f++)d=!b(a[f],f),d!==h&amp;&amp;e.push(a[f]);return e},map:function
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">3</div>
<div class="line-num2">3</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn"><br></span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">4</div>
<div class="line-num2">4</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn">&#x2F;* timeago.js - https:&#x2F;&#x2F;github.com&#x2F;hustcc&#x2F;timeago.js *&#x2F;</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">5</div>
<div class="line-num2">5</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn">!function(e,t){&quot;object&quot;==typeof module&amp;&amp;module.exports?module.exports=t(e):e.timeago=t(e)}(&quot;undefined&quot;!=typeof window?window:this,function(){function e(e){return e instanceof Date?e:isNaN(e)?&#x2F;^\\d+$&#x2F;.test(e)?new Date(t(e,10)):(e=(e||&quot;&quot;).trim().replace(&#x2F;\\.\\d+&#x2F;,&quot;&quot;).replace(&#x2F;-&#x2F;,&quot;&#x2F;&quot;).replace(&#x2F;-&#x2F;,&quot;&#x2F;&quot;).replace(&#x2F;T&#x2F;,&quot; &quot;).replace(&#x2F;Z&#x2F;,&quot; UTC&quot;).replace(&#x2F;([\\+\\-]\\d\\d)\\:?(\\d\\d)&#x2F;,&quot; $1$2&quot;),new Date(e)):new Date(t(e))}function t(e){return parseInt(e)}function n(e,n,r){n=d[n]?n:d[r]?r:&quot;en&quot;;var i=0;for(agoin=e&lt;0?1:0,e=Math.abs(e);e&gt;=l[i]&amp;&amp;i&lt;p;i++)e&#x2F;=l[i];return e=t(e),i*=2,e&gt;(0===i?9:1)&amp;&amp;(i+=1),d[n](e,i)[agoin].replace(&quot;%s&quot;,e)}function r(t,n){return n=n?e(n):new Date,(n-e(t))&#x2F;1e3}function i(e){for(var t=1,n=0,r=e;e&gt;=l[n]&amp;&amp;n&lt;p;n++)e&#x2F;=l[n],t*=l[n];return r%=t,r=r?t-r:t,Math.ceil(r)}function o(e){return e.getAttribute?e.getAttribute(_):e.attr?e.attr(_):void 0}function u(e,t){function u(o,c,f,s){var d=r(c,e);o.innerHTML=n(d,f,t),a[&quot;k&quot;+s]=setTimeout(function(){u(o,c,f,s)},1e3*i(d))}var a={};return t||(t=&quot;en&quot;),this.format=function(i,o){return n(r(i,e),o,t)},this.render=function(e,t){void 0===e.length&amp;&amp;(e=[e]);for(var n=0;n&lt;e.length;n++)u(e[n],o(e[n]),t,++c)},this.cancel=function(){for(var e in a)clearTimeout(a[e]);a={}},this.setLocale=function(e){t=e},this}function a(e,t){return new u(e,t)}var c=0,f=&quot;second_minute_hour_day_week_month_year&quot;.split(&quot;_&quot;),s=&quot;_分钟_小时_天_周_月_年&quot;.split(&quot;_&quot;),d={en:function(e,t){if(0===t)return[&quot;just now&quot;,&quot;right now&quot;];var n=f[parseInt(t&#x2F;2)];return e&gt;1&amp;&amp;(n+=&quot;s&quot;),[e+&quot; &quot;+n+&quot; ago&quot;,&quot;in &quot;+e+&quot; &quot;+n]},zh_CN:function(e,t){if(0===t)return[&quot;&quot;,&quot;&quot;];var n=s[parseInt(t&#x2F;2)];return[e+n+&quot;&quot;,e+n+&quot;&quot;]}},l=[60,60,24,7,365&#x2F;7&#x2F;12,12],p=6,_=&quot;datetime&quot;;return a.register=function(e,t){d[e]=t},a});</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr>
<tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-info"></td>
<td class="d2h-info">
<div class="d2h-code-line">@@ -24,12 +24,7 @@ $(function() {</div>
2021-01-23 15:07:14 +00:00
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">24</div>
<div class="line-num2">24</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn"> }</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">25</div>
<div class="line-num2">25</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn"><br></span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">26</div>
<div class="line-num2">26</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn"> $(document).on(&#x27;click&#x27;, &#x27;.check_all&#x27;, function() {</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del d2h-change">
<div class="line-num1">27</div>
<div class="line-num2"></div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"> <del>var checked </del>= $(this).<del>attr</del>(&#x27;checked&#x27;);</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del">
<div class="line-num1">28</div>
<div class="line-num2"></div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"> if (checked == &#x27;checked&#x27;) {</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del">
<div class="line-num1">29</div>
<div class="line-num2"></div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"> $(&#x27;input[type=checkbox]&#x27;, $(this).closest(&#x27;table&#x27;)).attr(&#x27;checked&#x27;, checked);</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del">
<div class="line-num1">30</div>
<div class="line-num2"></div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"> } else {</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del">
<div class="line-num1">31</div>
<div class="line-num2"></div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"> $(&#x27;input[type=checkbox]&#x27;, $(this).closest(&#x27;table&#x27;)).removeAttr(&#x27;checked&#x27;);</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-del">
<div class="line-num1">32</div>
<div class="line-num2"></div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-del">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">-</span>
<span class="d2h-code-line-ctn"> }</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-ins d2h-change">
<div class="line-num1"></div>
<div class="line-num2">27</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-ins d2h-change">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">+</span>
<span class="d2h-code-line-ctn"> <ins>$(&#x27;input[type</ins>=<ins>checkbox]&#x27;,</ins> $(this).<ins>closest</ins>(&#x27;<ins>table&#x27;)).prop(&#x27;</ins>checked&#x27;<ins>, this.checked</ins>);</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">33</div>
<div class="line-num2">28</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn"> });</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">34</div>
<div class="line-num2">29</div>
2021-01-23 15:07:14 +00:00
</td>
2022-10-15 23:01:01 +00:00
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn"><br></span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr><tr>
2022-10-15 23:01:01 +00:00
<td class="d2h-code-linenumber d2h-cntx">
<div class="line-num1">35</div>
<div class="line-num2">30</div>
</td>
<td class="d2h-cntx">
<div class="d2h-code-line">
<span class="d2h-code-line-prefix">&nbsp;</span>
<span class="d2h-code-line-ctn"> $(document).on(&quot;click&quot;, &quot;[data-confirm]&quot;, function() {</span>
2021-01-23 15:07:14 +00:00
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>"
`);
/* eslint-enable no-irregular-whitespace */
});
});
});