-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support to display diff code in a prettier way with [diff2html](https://diff2html.xyz/). ![image](https://github.com/alshedivat/al-folio/assets/31376482/5f93b09c-3850-499a-999b-cb0ae13fddae) It displays code like [in this example](https://diff2html.xyz/demo.html). --------- Signed-off-by: George Araújo <george.gcac@gmail.com>
- Loading branch information
1 parent
8e93db5
commit ef84782
Showing
8 changed files
with
540 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{% if page.code_diff %} | ||
<!-- diff2html doesn't go well with Bootstrap Table --> | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/diff2html@3.4.47/bundles/js/diff2html-ui.min.js" | ||
integrity="sha256-eU2TVHX633T1o/bTQp6iIJByYJEtZThhF9bKz/DcbbY=" | ||
crossorigin="anonymous" | ||
></script> | ||
<script> | ||
let theme = localStorage.getItem('theme'); | ||
/* Create echarts chart as another node and hide the code block, appending the echarts node after it | ||
this is done to enable retrieving the code again when changing theme between light/dark */ | ||
document.querySelectorAll('pre>code.language-diff2html').forEach((elem) => { | ||
const textData = elem.textContent; | ||
const backup = elem.parentElement; | ||
backup.classList.add('unloaded'); | ||
/* create diff node */ | ||
let diffElement = document.createElement('div'); | ||
diffElement.classList.add('diff2html'); | ||
backup.after(diffElement); | ||
const configuration = { colorScheme: theme, drawFileList: true, highlight: true, matching: 'lines' }; | ||
const diff2htmlUi = new Diff2HtmlUI(diffElement, textData, configuration); | ||
diff2htmlUi.draw(); | ||
}); | ||
</script> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.