博客園markdown編輯器代碼折疊


博客園設置里申請js權限。作用到側邊欄就可以,其他地方也行。只適配的markdown編輯器,與其他界面美化代碼一起使用可能會出現bug。

<script type="text/javascript">
		$(document).ready(function () {
			var pres = $("pre");
			for (var i = 0; i < pres.length; i++) {
				$(pres[i]).attr('id', 'pre' + i);
				$(pres[i]).children('code').hide();
				$(pres[i]).prepend('<button id="btn'+ i +'" onclick="view_code(\'pre'+ i +'\');">view code</button>');
			}
		});
		function view_code (id) {
			var btn_text =  document.getElementById(id).children[0].innerText;
			var style;
			var status;
			if(btn_text == 'view code') {
				style = '""';
				status = 'hide code';
			} else {
				style = 'display: none;';
				status = 'view code';
			}
			document.getElementById(id).children[0].innerText = status;
			document.getElementById(id).children[1].style = style;
		}
</script>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM