How to replace content of javascript syntax highlighter?

夙愿已清 提交于 2019-12-11 08:37:43

问题


I'm using a javascript syntax highlighter (http://alexgorbatchev.com/SyntaxHighlighter/). I think this one is very famous.

in my js, I use ajax to get code samples and then initialize syntax highlighter. When I call the same ajax call with a different parameter, it returns a different code sample. The problem is that I can't replace syntax highlighter's content. I looked up its API list, but I can't find an API to update or replace its content.

Please advise me.


回答1:


Just empty the wrapper element, put the new content inside, and then run syntax highlighter on that new code.

There shouldn't be any memory issues. Afaik, Syntax Highlighter simply creates a DOM structure (a table with DIV's, etc.) based on your code block. When you remove that table from the DOM (for instance wrapper.innerHTML = '';), all those elements are garbage collected.



来源:https://stackoverflow.com/questions/7761867/how-to-replace-content-of-javascript-syntax-highlighter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!