<input type="hidden" name="keyword" value="<?php echo $result->highlight_keywords ?>">
<div class="sec_main">
<?phh echo $result->content?>
</div><!-- section main end -->
<js>
<script src="/static/js/jquery.mark.min.js"></script>
<script>
$(function() {
var keyword = $("input[name='keyword']").val()
var options = {
"className": "match"
}
$(".sec_main").mark(keyword,options)
})
</script>
高亮文字的样式设置
<css>
.match{
color:red
}
marked.js是一个用JavaScript写的功能齐全的Markdown解析器和编译器。可以非常方便的在线编译Markdown代码为HTML并直接显示,并且支持完全的自定义各种格式。使用案例:
var marked = require('marked')console.log(marked('I am using __markdown__.'))// Outputs: <p>I am using <strong>markdown</strong>.</p>
var marked = require('marked')marked.setOptions({renderer: new marked.Renderer(),gfm: true,tables: true,breaks: false,pedantic: false,sanitize: false,smartLists: true,smartypants: false})console.log(marked('I am using __markdown__.'))
<!doctype html><html><head> <meta charset="utf-8"/> <title>Marked in the browser</title> <script src="lib/marked.js"></script></head><body> <div id="content"></div> <script> document.getElementById('content').innerHTML =marked('# Marked in browser\n\nRendered by **marked**.') </script></body></html>