2015/05/24

Google Blogger PrettyPrint 설정

SyntaxyHighlighter 이거 겨우 설정을 해뒀더니 모바일에서는 적용도 되지 않을 뿐더러 완전 모양빠지게 나와서 다시 찾은 대안이 google PrettyPrint. 근데 템플릿에 적용 해뒀더니 페이지별로 조회는 잘 되는데 페이지 전체 목록에서 볼 때는 RowBackgroundColor가 구림. 그래서.. 필요한 페이지는 직접 아래 소스를 직접 입력한다. 그럼 모바일에서도 적용 되고 템플릿 변경해도 따로 작업하지 않아도 된다.

<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?autoload=true&skin=sons-of-obsidian&lang=html" defer="defer"></script>
skin style(소문자로 적어야 제대로 적용된다)
language list

사용법
before

<pre class="prettyprint lang-java linenums">
package test;

public class Test {
public static main(String...args) {
System.out.println("Hello world");
}
}
</pre>
after
  1.  
  2. package test;
  3. public class Test {
  4. public static main(String...args) {
  5. System.out.println("Hello world");
  6. }
  7. }


before

<?prettify lang=java linenums=40?> <!-- linenumber를 40부터 시작 -->
<pre class="prettyprint">
package test;

public class Test {
public static main(String...args) {
System.out.println("Hello world");
}
}
</pre>
after
  1.  
  2. package test;
  3. public class Test {
  4. public static main(String...args) {
  5. System.out.println("Hello world");
  6. }
  7. }
더 자세한 설명은 아래 링크에서 확인
https://code.google.com/p/google-code-prettify/
Github으로 이사 갔음.
https://github.com/google/code-prettify

2015/05/23

Google Blogger SyntaxHighlighter 설정

블로그 만들 때 마다 계속 까먹어서 저장해두기로 한다.
출처 : http://anshnote.blogspot.kr/2011/07/syntax-highlighter-blogger.html

수정해야할 포인트는 총 3군데.

1. CSS 추가
수정 위치 : 내 블로그 > 템플릿 > 맞춤설정 > 고급 > CSS 추가 > 맞춤 CSS 추가
아래 소스를 그대로 Copy & Paste 후에 블로그에 적용
  1. {
  2. font-family: "Consolas", "Courier New", Courier, mono, serif;
  3. font-size: 12px;
  4. background-color: #E7E5DC;
  5. width: 99%;
  6. overflow: auto;
  7. margin: 18px 0 18px 0 !important;
  8. padding-top: 1px; /* adds a little border on top when controls are hidden */
  9. }
  10. /* clear styles */
  11. .dp-highlighter ol,
  12. .dp-highlighter ol li,
  13. .dp-highlighter ol li span
  14. {
  15. margin: 0;
  16. padding: 0;
  17. border: none;
  18. }
  19. .dp-highlighter a,
  20. .dp-highlighter a:hover
  21. {
  22. background: none;
  23. border: none;
  24. padding: 0;
  25. margin: 0;
  26. }
  27. .dp-highlighter .bar
  28. {
  29. padding-left: 45px;
  30. }
  31. .dp-highlighter.collapsed .bar,
  32. .dp-highlighter.nogutter .bar
  33. {
  34. padding-left: 0px;
  35. }
  36. .dp-highlighter ol
  37. {
  38. list-style: decimal; /* for ie */
  39. background-color: #fff;
  40. margin: 0px 0px 1px 45px !important; /* 1px bottom margin seems to fix occasional Firefox scrolling */
  41. padding: 0px;
  42. color: #5C5C5C;
  43. }
  44. .dp-highlighter.nogutter ol,
  45. .dp-highlighter.nogutter ol li
  46. {
  47. list-style: none !important;
  48. margin-left: 0px !important;
  49. }
  50. .dp-highlighter ol li,
  51. .dp-highlighter .columns div
  52. {
  53. list-style: decimal-leading-zero; /* better look for others, override cascade from OL */
  54. list-style-position: outside !important;
  55. border-left: 3px solid #6CE26C;
  56. background-color: #F8F8F8;
  57. color: #5C5C5C;
  58. padding: 0 3px 0 10px !important;
  59. margin: 0 !important;
  60. line-height: 14px;
  61. }
  62. .dp-highlighter.nogutter ol li,
  63. .dp-highlighter.nogutter .columns div
  64. {
  65. border: 0;
  66. }
  67. .dp-highlighter .columns
  68. {
  69. background-color: #F8F8F8;
  70. color: gray;
  71. overflow: hidden;
  72. width: 100%;
  73. }
  74. .dp-highlighter .columns div
  75. {
  76. padding-bottom: 5px;
  77. }
  78. .dp-highlighter ol li.alt
  79. {
  80. background-color: #FFF;
  81. color: inherit;
  82. }
  83. .dp-highlighter ol li span
  84. {
  85. color: black;
  86. background-color: inherit;
  87. }
  88. /* Adjust some properties when collapsed */
  89. .dp-highlighter.collapsed ol
  90. {
  91. margin: 0px;
  92. }
  93. .dp-highlighter.collapsed ol li
  94. {
  95. display: none;
  96. }
  97. /* Additional modifications when in print-view */
  98. .dp-highlighter.printing
  99. {
  100. border: none;
  101. }
  102. .dp-highlighter.printing .tools
  103. {
  104. display: none !important;
  105. }
  106. .dp-highlighter.printing li
  107. {
  108. display: list-item !important;
  109. }
  110. /* Styles for the tools */
  111. .dp-highlighter .tools
  112. {
  113. padding: 3px 8px 3px 10px;
  114. font: 9px Verdana, Geneva, Arial, Helvetica, sans-serif;
  115. color: silver;
  116. background-color: #f8f8f8;
  117. padding-bottom: 10px;
  118. border-left: 3px solid #6CE26C;
  119. }
  120. .dp-highlighter.nogutter .tools
  121. {
  122. border-left: 0;
  123. }
  124. .dp-highlighter.collapsed .tools
  125. {
  126. border-bottom: 0;
  127. }
  128. .dp-highlighter .tools a
  129. {
  130. font-size: 9px;
  131. color: #a0a0a0;
  132. background-color: inherit;
  133. text-decoration: none;
  134. margin-right: 10px;
  135. }
  136. .dp-highlighter .tools a:hover
  137. {
  138. color: red;
  139. background-color: inherit;
  140. text-decoration: underline;
  141. }
  142. /* About dialog styles */
  143. .dp-about { background-color: #fff; color: #333; margin: 0px; padding: 0px; }
  144. .dp-about table { width: 100%; height: 100%; font-size: 11px; font-family: Tahoma, Verdana, Arial, sans-serif !important; }
  145. .dp-about td { padding: 10px; vertical-align: top; }
  146. .dp-about .copy { border-bottom: 1px solid #ACA899; height: 95%; }
  147. .dp-about .title { color: red; background-color: inherit; font-weight: bold; }
  148. .dp-about .para { margin: 0 0 4px 0; }
  149. .dp-about .footer { background-color: #ECEADB; color: #333; border-top: 1px solid #fff; text-align: right; }
  150. .dp-about .close { font-size: 11px; font-family: Tahoma, Verdana, Arial, sans-serif !important; background-color: #ECEADB; color: #333; width: 60px; height: 22px; }
  151. /* Language specific styles */
  152. .dp-highlighter .comment, .dp-highlighter .comments { color: #008200; background-color: inherit; }
  153. .dp-highlighter .string { color: blue; background-color: inherit; }
  154. .dp-highlighter .keyword { color: #069; font-weight: bold; background-color: inherit; }
  155. .dp-highlighter .preprocessor { color: gray; background-color: inherit; }

2. 템플릿 수정
수정 위치 : 내 블로그 > 템플릿 > HTML 편집
a : </head> 태그를 찾아서 바로 앞에 아래의 소스 그대로 Copy & Paste
  1. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shCore.js" type="text/javascript"></script>
  2. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCSharp.js" type="text/javascript"></script>
  3. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushPhp.js" type="text/javascript"></script>
  4. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushJScript.js" type="text/javascript"></script>
  5. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushJava.js" type="text/javascript"></script>
  6. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushVb.js" type="text/javascript"></script>
  7. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushSql.js" type="text/javascript"></script>
  8. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushXml.js" type="text/javascript"></script>
  9. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushDelphi.js" type="text/javascript"></script>
  10. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushPython.js" type="text/javascript"></script>
  11. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushRuby.js" type="text/javascript"></script>
  12. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCss.js" type="text/javascript"></script>
  13. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCpp.js" type="text/javascript"></script>
  14. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushScala.js" type="text/javascript"></script>
  15. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushGroovy.js" type="text/javascript"></script>
  16. <script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushBash.js" type="text/javascript"></scriptf>

b : </body> 태그를 찾아서 바로 앞에 아래의 소스를 그대로 Copy & Paste
  1. <script type="text/javascript">
  2. dp.SyntaxHighlighter.BloggerMode();
  3. dp.SyntaxHighlighter.HighlightAll('code');
  4. </script>

수정은 끝. 하지만 템플릿을 변경하게 되면 다시 해줘야 하므로 까먹지 말자.
그럼 이제 사용하려면
  1. <pre>
  2. package test;
  3.  
  4. public class Test {
  5. public static main(String...args) {
  6. System.out.println("Hello world");
  7. }
  8. }
  9. </pre>

혹은
  1. <textarea class="java" name="code">
  2. package test;
  3.  
  4. public class Test {
  5. public static main(String...args) {
  6. System.out.println("Hello world");
  7. }
  8. }
  9. </textarea>
지원 언어 및 추가 사용법
https://code.google.com/p/syntaxhighlighter/wiki/Usage

하지만 정작 이 글이 google-code-prettify로 작성되었다는 건 함정

2015/05/22

test

  1.  
  2. #include
  3. main()
  4. {
  5. printf("Hello World");
  6. return;
  7. }
  1.  
  2. package test;
  3.  
  4. public class Test {
  5. public static main(String...args) {
  6. System.out.println("Hello world");
  7. }
  8. }