Skip to content

Instantly share code, notes, and snippets.

@hogashi
Last active May 23, 2020 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hogashi/58a486cdacfd1218052cadc671f28837 to your computer and use it in GitHub Desktop.
Save hogashi/58a486cdacfd1218052cadc671f28837 to your computer and use it in GitHub Desktop.
github diff content editable each line js
document.styleSheets[0].insertRule('.blob-code-marker:before { border-right: black 1px dotted; }');
linedata = {};
[
...Array.from(document.querySelectorAll('.blob-code-addition')),
...Array.from(document.querySelectorAll('.blob-code-context'))
].forEach(line => {
lineNumber = line.parentNode.querySelector('.blob-num').getAttribute('data-line-number');
marker = line.querySelector('.blob-code-marker');
editor = marker.cloneNode();
marker.style.display = 'none';
editor.style.display = 'inline-block';
editor.style.width = '100%';
editor.innerHTML = marker.innerText
.replace(/&/g, '&')
.replace(/'/g, ''')
.replace(/"/g, '"')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
editor.contentEditable = true;
line.appendChild(editor);
linedata[lineNumber] = { line, marker, editor };
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment