I am writing a tutorial page where I need to highlight different source codes which are in different languages(HTML,CSS, Javascript, jQuery)
Currently, it is highlighting one language if I mentioned the mode:"jQuery"
I want to highlight some portion of code as HTML and some portion as CSS and some portion as jQuery etc.. How can I do that?
My current code:
<link rel="stylesheet" href="codemirror-5.4/lib/codemirror.css">
<script src="codemirror-5.4/lib/codemirror.js"></script>
<script src="codemirror-5.4/mode/xml/xml.js"></script>
<script src="codemirror-5.4/mode/jquery/jquery.js"></script>
<script src="codemirror-5.4/keymap/sublime.js"></script>
<link rel="stylesheet" href="codemirror-5.4/theme/monokai.css">
<script src="codemirror-5.4/mode/htmlmixed.js"></script>
// codemirror function**
<script type="text/javascript">
var areas = document.getElementsByClassName("myTextareaClass");
for(var i = 0; i < areas.length; i++) {
CodeMirror.fromTextArea(areas.item(i), {
mode: "css",
theme: "monokai",
readOnly:true,
});
}
</script>
This is what I want to highlight on the same page
// highlight the code in CSS mode
<textarea class="myTextareaClass">
.fa-check {
color:green;
}
</textarea>
// hight light the code in HTML mode
<textarea class="myTextareaClass">
<div>Sample Div Element</div>
</textarea>
// hight light the code in jQuery mode
<textarea class="myTextareaClass">
$( "div" ).css( "border", "2px solid red" ).add( "p" ).css( "background", "green" );
</textarea>
I can not use auto mode or auto selection since it is not selected by the user to detect. I need to mention the mode may be manually. How can I achieve this using the same function?