Google에서 직접 호스팅하는 Google의 prettify.js 및 prettify.css 파일을 사용하고 있습니다. 이것은 <pre>
또는 <code>
태그 안에 소스 코드 스 니펫을 강조하는 javascript 및 css 스크립트입니다. 문서는 여기에서 찾을 수 있습니다 : https://github.com/google/code-prettify/blob/master/docs/getting_started.mdprettyPrint() 함수가 내부에로드되지 않음 <script> 태그
스크립트를 초기화하려면 다음과 같이 호출 할 수 있습니다. <body onload="prettyPrint();">
잘 작동합니다. 내 페이지의 모든 <body>
태그에이 속성을 추가하지 않으
대신 내가 (설명하기가 조금 긴 이유)는 <body>
내부 <script>
태그에서 호출 할. 그러나 이것은 효과가 없습니다.
<body onload="prettyPrint();">
을 통해 함수를 호출하는 경우는했지만 자바 스크립트 콘솔에서 오류가없는 것처럼 코드가 강조 점점되지
<body>
<script type="text/javascript">
prettyPrint();
//document.write('doing something');//this line prints
</script>
...
및 라인 'doing something'
인쇄입니다 : 여기
<script>
태그에서이 함수를 어떻게 호출 할 수 있습니까?
편집
심지어이 인쇄되어 있지만 여전히 구문 강조하기되지 않은 : 그래서
<body>
<script type="text/javascript">
if(window.prettyPrint){
prettyPrint();
document.write('doing something');//this line prints
}
</script>
...
처리 된 내용 만 인쇄 할 수 있습니다. 신체 본문 내용이 처리되기 전에 본문 시작 부분의 스크립트 태그가 실행됩니다. –