Skip to content

Commit

Permalink
fixes yairEO#858 - missing parts in code examples syntax highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
Yair Even Or authored and Yair Even Or committed Jul 13, 2021
1 parent caf9000 commit 60c9ca8
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,28 +168,19 @@
if( isIE ) return;

function removeLast(s, r){
s = s.split(r)
return s.slice(0,-1).join(r) + s.pop()
s = s.split(r)
return s.slice(0,-1).join(r) + s.pop()
}

setTimeout(function(){
var jsCode = document.querySelector("[data-name='"+ codeScriptName +"']").innerHTML;

// cleanup closure wraper
jsCode = jsCode.replace("(function(){", "").trim();
jsCode = removeLast(jsCode, "})()")

// escape angled brackets between two _ESCAPE_START_ and _ESCAPE_END_ comments
let textsToEscape = jsCode.match(new RegExp("// _ESCAPE_START_([^]*?)// _ESCAPE_END_", 'mg'));
if (textsToEscape) {
textsToEscape.forEach(function(textToEscape){
jsCode = jsCode.replace(textToEscape, textToEscape.replace(/</g, "&lt" )
.replace(/>/g, "&gt" )
.replace("// _ESCAPE_START_", "")
.replace("// _ESCAPE_END_", "")
.trim());
});
}
jsCode = removeLast(jsCode, "})()").replace(/</g, "&lt" )
.replace(/>/g, "&gt" )
.trim();

currentScript.insertAdjacentHTML('afterend', "<pre class='language-js'><code>" + jsCode + "</code></pre>");
}, 500);
}
Expand Down Expand Up @@ -1807,7 +1798,6 @@ <h3>JAVASCRIPT</h3>
templates : {
tag : function(tagData){
try{
// _ESCAPE_START_
return `<tag title='${tagData.value}' contenteditable='false' spellcheck="false" class='tagify__tag ${tagData.class ? tagData.class : ""}' ${this.getAttributes(tagData)}>
<x title='remove tag' class='tagify__tag__removeBtn'></x>
<div>
Expand All @@ -1817,20 +1807,17 @@ <h3>JAVASCRIPT</h3>
<span class='tagify__tag-text'>${tagData.value}</span>
</div>
</tag>`
// _ESCAPE_END_
}
catch(err){}
},

dropdownItem : function(tagData){
try{
// _ESCAPE_START_
return `<div class='tagify__dropdown__item ${tagData.class ? tagData.class : ""}' tagifySuggestionIdx="${tagData.tagifySuggestionIdx}">
<img onerror="this.style.visibility = 'hidden'"
src='https://lipis.github.io/flag-icon-css/flags/4x3/${tagData.code.toLowerCase()}.svg'>
src='https://lipis.github.io/flag-icon-css/flags/4x3/${tagData.code.toLowerCase()}.svg'>
<span>${tagData.value}</span>
</div>`
// _ESCAPE_END_
}
catch(err){}
}
Expand Down Expand Up @@ -2207,14 +2194,16 @@ <h3>JAVASCRIPT</h3>
$('.tags-jquery--removeAllBtn').on('click', jqTagify.removeAllTags.bind(jqTagify))
})()
</script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/themes/prism.min.css">
<script src='https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/prism.min.js'></script>
<script>
window.Prism = window.Prism || {};
window.Prism.manual = true;
setTimeout(function(){
Prism.highlightAll();
}, 500)
</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism.min.css">
<script src='https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js'></script>


<script src='https://unpkg.com/@yaireo/knobs'></script>
<script>
Expand Down

0 comments on commit 60c9ca8

Please sign in to comment.