MCPcopy Index your code
hub / github.com/danvk/webdiff / addCharacterDiffs

Function addCharacterDiffs

ts/codediff/char-diffs.ts:83–103  ·  view source on GitHub ↗
(
  beforeText: string,
  beforeHtml: string,
  afterText: string,
  afterHtml: string,
)

Source from the content-addressed store, hash-verified

81}
82
83export function addCharacterDiffs(
84 beforeText: string,
85 beforeHtml: string,
86 afterText: string,
87 afterHtml: string,
88): [string, string] {
89 const codes = computeCharacterDiffs(beforeText, afterText);
90 if (codes == null) {
91 return [beforeHtml, afterHtml];
92 }
93 const [beforeOut, afterOut] = codes;
94
95 // Splice in "insert", "delete" and "replace" tags.
96 // This is made more difficult by the presence of syntax highlighting, which
97 // has its own set of tags. The two can co-exists if we're careful to only
98 // wrap complete (balanced) DOM trees.
99 const beforeMapper = new htmlTextMapper(beforeText, beforeHtml);
100 const afterMapper = new htmlTextMapper(afterText, afterHtml);
101
102 return [codesToHtml(beforeMapper, beforeOut), codesToHtml(afterMapper, afterOut)];
103}
104
105/**
106 * @param {string} line The line to be split

Callers 2

DiffRowFunction · 0.90

Calls 2

computeCharacterDiffsFunction · 0.85
codesToHtmlFunction · 0.85

Tested by

no test coverage detected