mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-07 22:45:23 +02:00
diff highlight
This commit is contained in:
parent
aa7c6b12a6
commit
97a977063c
6 changed files with 1671 additions and 116 deletions
410
public/dist/code-styling.bundle.js
vendored
410
public/dist/code-styling.bundle.js
vendored
File diff suppressed because one or more lines are too long
1
public/dist/code-styling.css
vendored
1
public/dist/code-styling.css
vendored
|
@ -1 +1,2 @@
|
|||
.hljs{display:block;background:#fff;padding:.5em;color:#333;overflow-x:auto}.hljs-comment,.hljs-meta{color:#969896}.hljs-emphasis,.hljs-quote,.hljs-string,.hljs-strong,.hljs-template-variable,.hljs-variable{color:#df5000}.hljs-keyword,.hljs-selector-tag,.hljs-type{color:#a71d5d}.hljs-attribute,.hljs-bullet,.hljs-literal,.hljs-symbol{color:#0086b3}.hljs-name,.hljs-section{color:#63a35c}.hljs-tag{color:#333}.hljs-attr,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-selector-pseudo,.hljs-title{color:#795da3}.hljs-addition{color:#55a532;background-color:#eaffea}.hljs-deletion{color:#bd2c00;background-color:#ffecec}.hljs-link{text-decoration:underline}
|
||||
.diff{width:100%;display:inline-block}.diff-plus{color:green!important;background-color:rgba(0,128,0,.21)}.diff-minus{color:red!important;background-color:rgba(255,0,0,.21)}
|
||||
|
|
373
public/dist/editor.bundle.js
vendored
373
public/dist/editor.bundle.js
vendored
File diff suppressed because one or more lines are too long
963
public/dist/main.bundle.js
vendored
963
public/dist/main.bundle.js
vendored
File diff suppressed because one or more lines are too long
|
@ -4,6 +4,7 @@ import xml from 'highlight.js/lib/languages/xml';
|
|||
import json from 'highlight.js/lib/languages/json';
|
||||
import css from 'highlight.js/lib/languages/css';
|
||||
import style from 'highlight.js/styles/github-gist.css'; // eslint-disable-line no-unused-vars
|
||||
import diffStyles from '../../styles/diff.pcss'; // eslint-disable-line no-unused-vars
|
||||
|
||||
/**
|
||||
* @class CodeStyles
|
||||
|
@ -14,7 +15,7 @@ export default class CodeStyler {
|
|||
* @param {string} selector - CSS selector for code blocks
|
||||
* @param {string[]} languages - list of languages to highlight, see hljs.listLanguages()
|
||||
*/
|
||||
constructor({ selector, languages = ['javascript', 'xml', 'json', 'css'] }) {
|
||||
constructor({selector, languages = ['javascript', 'xml', 'json', 'css']}) {
|
||||
this.codeBlocksSelector = selector;
|
||||
this.languages = languages;
|
||||
this.langsAvailable = {
|
||||
|
@ -47,6 +48,30 @@ export default class CodeStyler {
|
|||
|
||||
Array.from(codeBlocks).forEach(block => {
|
||||
hljs.highlightBlock(block);
|
||||
this.enumNodes(block.firstElementChild)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* kjn
|
||||
* @param node
|
||||
*/
|
||||
enumNodes(node) {
|
||||
while (node) {
|
||||
const diffPlusRegEx = /\n([+].*)/ig;
|
||||
|
||||
if (diffPlusRegEx.test(node.innerHTML)) {
|
||||
node.innerHTML = node.innerHTML.replace(diffPlusRegEx, '\n<span class="diff diff-plus">$1</span>');
|
||||
}
|
||||
|
||||
const diffMinusRegEx = /\n([-].*)/ig;
|
||||
|
||||
if (diffMinusRegEx.test(node.innerHTML)) {
|
||||
node.innerHTML = node.innerHTML.replace(diffMinusRegEx, '\n<span class="diff diff-minus">$1</span>');
|
||||
}
|
||||
|
||||
this.enumNodes(node.firstElementChild);
|
||||
node = node.nextSibling;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
13
src/frontend/styles/diff.pcss
Normal file
13
src/frontend/styles/diff.pcss
Normal file
|
@ -0,0 +1,13 @@
|
|||
.diff {
|
||||
width: 100%;
|
||||
display: inline-block;
|
||||
&-plus {
|
||||
color: green !important;
|
||||
background-color: rgba(0, 128, 0, 0.21);
|
||||
}
|
||||
|
||||
&-minus {
|
||||
color: red !important;
|
||||
background-color: rgba(255, 0, 0, 0.21);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue