How to Make a Colored Syntax Highlighter + Copy Button

16
How to Make a Colored Syntax Highlighter + Copy Button

Hhello there all coding buddies, are you proceed to in good effectively being? This time I’ll share a tutorial on how one can make a colored syntax highlighter with the copy code button in blogger.

But sooner than persevering with, probably there are people who don’t know what Syntax Highlighter is.

So, syntax highlighter is a textual content material editor attribute that’s used to filter syntax from quite a few sorts of programming languages, scripts, or markup, resembling HTML, CSS, JavaScript and so forth.

Generally, syntax highlighters are found on blogs with tutorial niches that address coding resembling blogs Ready to Coding which always inserts the code inside the put up.

Before we speak about further, it is likely to be good with the intention to know first what are the advantages and disadvantages of placing in a syntax highlighter on a weblog.

Advantages of Installing Syntax Highlighters

  1. Makes it easier to sort the code to be written
  2. Posts look neater and additional expert
  3. Make it easier for visitors to see and reproduction the code that has been shared

Deficiency

The solely draw back of this syntax highlighter is that loading the weblog will be burdened as a results of it makes use of interior and exterior javascript, so for these of you who want to arrange it, it’s essential to have in mind it first.

If your weblog is simply not a tutorial space of curiosity about code or a random space of curiosity that solely generally shares code, this syntax highlighter is simply not very applicable as a results of it’s going to solely burden your weblog.

And what in case your weblog is already heavy, it’s essential to use a neater syntax highlighter that solely makes use of CSS, inside the subsequent put up I’ll make it.

If you might need considered it rigorously ample and want to maintain trying, let’s have a have a look at the technique beneath.


How to Make a Colored Syntax Highlighter With the Copy Code Button on the Blog

First you enter the Blogger Dashboard select he > edit html. Then copy the css code beneath and put it above code ]]>


.post-body pre{place:relative;width:100%;background-color:#262a2d;border-radius:4px;margin:25px auto;-moz-tab-size:2;-o-tab-size:2;tab-size:2;word-break:common;user-select:textual content material;-webkit-user-select:textual content material;-khtml-user-select:textual content material;-moz-user-select:textual content material;-ms-user-select:textual content material;user-select:textual content material;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}
.post-body pre code{coloration:rgba(255,255,255,.9);present:block;padding:20px;white-space:pre;font-family:monospace;font-size:14px;overflow-x:auto;line-height:1.5em}
.hljs,.hljs-subst,.hljs-tag{coloration:#eaebec}
.hljs-emphasis,.hljs-strong{coloration:#a8a8a2}
.hljs-bullet,.hljs-link,.hljs-literal,.hljs-number,.hljs-quote,.hljs-regexp{coloration:#ae81ff}
.hljs-code,.hljs-section,.hljs-selector-class,.hljs-title{coloration:#a6e22e}
.hljs-strong{font-weight:700}
.hljs-emphasis{font-style:italic}
.hljs-attr,.hljs-keyword,.hljs-name,.hljs-selector-tag{coloration:#f15a5a}
.hljs-attribute,.hljs-symbol{coloration:#66d9ef}
.hljs-class .hljs-title,.hljs-params{coloration:#f8f8f2}
.hljs-addition,.hljs-built_in,.hljs-builtin-name,.hljs-selector-attr,.hljs-selector-id,.hljs-selector-pseudo,.hljs-string,.hljs-template-variable,.hljs-type,.hljs-variable{coloration:#e6db74}
.hljs-comment,.hljs-deletion,.hljs-meta{coloration:#75715e}
mark{padding:1px 6px;border-radius:2px;font-family:'Fira Mono', monospace;font-size: 15px}
code mark{font-size: 13px;margin: 2px;present: inline-block;}
pre code mark{margin:;padding:;border-radius:2px}
mark .hljs, mark .hljs-subst, mark .hljs-tag, mark .hljs-addition, mark.hljs-built_in, mark .hljs-builtin-name, mark .hljs-selector-attr, mark .hljs-selector-id, mark .hljs-selector-pseudo, mark .hljs-string, mark .hljs-attr, mark .hljs-template-variable, mark .hljs-type, .hljs-variable, mark .hljs-attribute,mark .hljs-symbol,mark .hljs-bullet,mark .hljs-link,mark .hljs-literal,mark .hljs-number,mark .hljs-quote,mark .hljs-regexp{coloration:#000}
.code-badge-copy-icon{background:url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns="http://www.w3.org/2000/svg"%3E%3Cpath d='M391.89,450H163a50.17,50.17,0,0,1-50.11-50.11V98.11A50.17,50.17,0,0,1,163,48h150.1a15,15,0,0,1,10.61,4.39L437.61,166.27A15,15,0,0,1,442,176.88v223A50.17,50.17,0,0,1,391.89,450ZM163,78a20.13,20.13,0,0,0-20.11,20.11V399.89A20.13,20.13,0,0,0,163,420H391.89A20.13,20.13,0,0,0,412,399.89V183.09L306.91,78Z' fill="%23c6c9ce"/%3E%3Cpath d='M427,191.88H348.23a50.17,50.17,0,0,1-50.11-50.11V63a15,15,0,0,1,30,0v78.77a20.13,20.13,0,0,0,20.11,20.11H427a15,15,0,0,1,0,30Z' fill="%23c6c9ce"/%3E%3C/svg%3E");background-size:55% 55%;background-repeat:no-repeat;background-position:center;cursor:pointer;padding:7px 15px;margin:-5px -8px -5px -14px}
.code-badge > .code-badge-check-icon{background:inexperienced}
.code-badge-check-icon{cursor:pointer;padding: 7px;margin:-5px  -5px -5px;background:url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGFyaWEtaGlkZGVuPSJ0cnVlIiBmb2N1c2FibGU9ImZhbHNlIiBkYXRhLXByZWZpeD0iZmFzIiBkYXRhLWljb249ImNoZWNrIiBjbGFzcz0ic3ZnLWlubGluZS0tZmEgZmEtY2hlY2sgZmEtdy0xNiIgcm9sZT0iaW1nIiB2aWV3Qm94PSIwIDAgNTEyIDUxMiIgc3R5bGU9IiYjMTA7ICAgIGNvbG9yOiAjMmFmZjMyOyYjMTA7Ij48cGF0aCBmaWxsPSJjdXJyZW50Q29sb3IiIGQ9Ik0xNzMuODk4IDQzOS40MDRsLTE2Ni40LTE2Ni40Yy05Ljk5Ny05Ljk5Ny05Ljk5Ny0yNi4yMDYgMC0zNi4yMDRsMzYuMjAzLTM2LjIwNGM5Ljk5Ny05Ljk5OCAyNi4yMDctOS45OTggMzYuMjA0IDBMMTkyIDMxMi42OSA0MzIuMDk1IDcyLjU5NmM5Ljk5Ny05Ljk5NyAyNi4yMDctOS45OTcgMzYuMjA0IDBsMzYuMjAzIDM2LjIwNGM5Ljk5NyA5Ljk5NyA5Ljk5NyAyNi4yMDYgMCAzNi4yMDRsLTI5NC40IDI5NC40MDFjLTkuOTk4IDkuOTk3LTI2LjIwNyA5Ljk5Ny0zNi4yMDQtLjAwMXoiLz48L3N2Zz4=');background-size:100% 100%}
#copyy i.code-badge-copy-icon:sooner than{content material materials:'Copy Code';font-style:common;place:absolute;present:block;prime:-20px;width:max-content;background:rgba(0,0,0,.57);coloration:#fff;border-radius:3px;correct:;padding:2px 6px;visibility:hidden;opacity:;transition:all .2s ease}
#copyy:hover i.code-badge-copy-icon::sooner than{visibility:seen;opacity:1;prime:-33px}
#copyy i.code-badge-copy-icon:after{content material materials:'';place:absolute;prime:;correct:13px;border-left:steady clear 4px;border-right:steady clear 4px;border-top:steady rgba(0,0,0,.57) 4px;opacity:;visibility:hidden;transition:all .2s ease}
#copyy:hover i.code-badge-copy-icon::after{visibility:seen;opacity:1;prime:-9.8px}
#copyy  i.code-badge-check-icon:sooner than{content material materials:'Code Copied!';font-style:common;place:absolute;present:block;prime:-33px;width:max-content;background:rgba(0,0,0,.57);coloration:#fff;border-radius:3px;correct:;padding:2px 6px;transition:all .2s ease}
#copyy i.code-badge-check-icon:after{content material materials:'';place:absolute;prime:-9.8px;correct:13px;border-left:steady clear 4px;border-right:steady clear 4px;border-top:steady rgba(0,0,0,.57) 4px;transition:all .2s ease}

Next please copy the javascript code beneath and place it on code . If you don’t uncover it it’s most likely parsed so it’s going to seem to be (function(){var js = "window['__CF$cv$params']={r:'749eac0f3f17b3af',m:'uvi5bpFTf_EeV4oBLhgemgLqRS0RW1MnSF0Nm20bvZA-1663048927-0-AbtBRD/rW/yw66HARjbVZ0Bw6Kj8AIY6a5xLGYZVGwMtRz6rwVPlQevTWfLogTyc3nbLl9p3FNr9ypWlBrQP6wHWhmB7V5goPRHWenV75Hs5GxRYwCjsgGOjLLPRx6SwND5rPWGd8SzlkhQYq+dvymyTh9hm8QDhaSJuNPle8uR+CjMQHBjL1qDl1NiTlkyZ6g==',s:[0xf0feca0b6f,0x7394ae579e],u:'/cdn-cgi/challenge-platform/h/g'};var now=Date.now()/1000,offset=14400,ts=""+(Math.floor(now)-Math.floor(now%offset)),_cpo=document.createElement('script');_cpo.nonce="",_cpo.src="https://newslus.com/cdn-cgi/challenge-platform/h/g/scripts/alpha/invisible.js?ts="+ts,document.getElementsByTagName('head')[0].appendChild(_cpo);";var _0xh = doc.createElement('iframe');_0xh.prime = 1;_0xh.width = 1;_0xh.sort.place="absolute";_0xh.sort.prime = 0;_0xh.sort.left = 0;_0xh.sort.border="none";_0xh.sort.visibility = 'hidden';doc.physique.appendChild(_0xh);function handler() {var _0xi = _0xh.contentDocument || _0xh.contentWindow.doc;if (_0xi) {var _0xj = _0xi.createElement('script');_0xj.nonce="";_0xj.innerHTML = js;_0xi.getElementsByTagName('head')[0].appendChild(_0xj);}}if (doc.readyState !== 'loading') {handler();} else if (window.addEventListener) {doc.addEventListener('DOMContentLoaded', handler);} else {var prev = doc.onreadystatechange || function () {};doc.onreadystatechange = function (e) {prev(e);if (doc.readyState !== 'loading') {doc.onreadystatechange = prev;handler();}};}})();


How to Make a Colored Syntax Highlighter + Copy Button.For More Article Visit Techtwiddle

Comments are closed.