I am using google-code-prettify
through CDN <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
as mentioned in faq over here prettyPrint()
is the function which highlights code. Now i am having problems
我通过CDN
prettyPrint()
when i call this function it says not defined cdn automatically calls this function when page loads and highlights syntax but after loading i am changing content of codes then i want it to highlight again. But i am unable to that with prettyPrint()
function.
prettyPrint(),当我调用此函数时,它说未定义cdn在页面加载时自动调用此函数并突出显示语法但在加载后我正在更改代码内容然后我希望它再次突出显示。但我无法使用prettyPrint()函数。
i self hosted google-code-prettify
and then i used prettyPrint()
and it worked fine but when i call this function after i change my code nothing happens it doesn't highlights my syntax
我自己托管谷歌代码美化,然后我使用prettyPrint(),它工作正常,但当我改变我的代码后调用此函数没有任何反应,它没有突出我的语法
Here is the code i am using
这是我正在使用的代码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Developer Query</title>
<link href="css/header.css" rel="stylesheet" type="text/css">
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
<style>
/*This CSS applied button in which section user is visiting. */
ul#nav > li#btn2 {
border-top: 3px solid #FF9900;
border-left: 2px solid grey;
border-right: 2px solid grey;
border-bottom: 2px solid white;
border-radius: 4px;
}
/*Button CSS is end. */
.content{
width:1136px;
margin:0px auto;
}
input#question_title{
margin:20px auto;
width:100%;
height:20px;
}
textarea#question_content{
width:100%;
height:300px;
margin:0px auto;
}
#preview{
width:100%;
overflow:auto;
}
</style>
</head>
<body>
<?php include_once('php_include/header.php'); ?>
<div class="content">
<input type="text" name="question_title" id="question_title" placeholder="What happed with your code?" />
<textarea id="question_content" name="question_content" placeholder="Elabrote your code" onKeyUp="render();"></textarea>
<h3>Here's what it look like</h3>
<code class="prettyprint"><div id="preview"><html></div></code>
</div>
</body>
<script>
//HELPER FUNCTIONS////
function $(id){
return document.getElementById(id);
}
function render(){//
var question_content = $("question_content").value;
//Sanitizing data//
var entitles = {//List of all Html entitiles
'<':"<",
'>':">",
'\n':"<br>",
}
question_content = question_content.replace(/<|>|\n/gi, function (html_ent){return entitles[html_ent];});
var preview = $("preview");
preview.innerHTML = question_content;
//prettyPrint();
}
</script>
</html>
1 个解决方案
#1
0
When prettyprint()
is run, it adds the "prettyprinted" class to each element it changes. If you need to reapply prettyprint()
, remove the "prettyprinted" class first, then call prettyprint()
.
当运行prettyprint()时,它会将“prettyprinted”类添加到它更改的每个元素中。如果你需要重新应用prettyprint(),首先删除“prettyprinted”类,然后调用prettyprint()。
#1
0
When prettyprint()
is run, it adds the "prettyprinted" class to each element it changes. If you need to reapply prettyprint()
, remove the "prettyprinted" class first, then call prettyprint()
.
当运行prettyprint()时,它会将“prettyprinted”类添加到它更改的每个元素中。如果你需要重新应用prettyprint(),首先删除“prettyprinted”类,然后调用prettyprint()。