{"id":1871,"date":"2024-11-10T11:57:11","date_gmt":"2024-11-10T03:57:11","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1871\/"},"modified":"2024-11-10T11:57:11","modified_gmt":"2024-11-10T03:57:11","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-highlight-js-%e4%b8%ba-html-%e4%bb%a3%e7%a0%81%e6%b7%bb%e5%8a%a0%e8%a1%8c%e5%8f%b7%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1871\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Highlight.js \u4e3a HTML \u4ee3\u7801\u6dfb\u52a0\u884c\u53f7\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173060822633564.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 Highlight.js \u4e3a HTML \u4ee3\u7801\u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 Highlight.js \u4e3a HTML \u4ee3\u7801\u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>highlight.js \u6dfb\u52a0\u884c\u53f7<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 Highlight.js \u7ed9 HTML \u6e90\u4ee3\u7801\u7740\u8272\u7684\u8fc7\u7a0b\u4e2d\uff0c\u8981\u589e\u52a0\u884c\u53f7\uff0c\u9700\u8981\u6df1\u5165\u7406\u89e3\u5b98\u65b9\u6587\u6863\u4e2d\u5bf9\u884c\u53f7\u7684\u63cf\u8ff0\u3002<\/p>\n<p>\u6839\u636e\u5b98\u65b9\u63cf\u8ff0\uff0c\u5728\u4ee3\u7801\u5757\u4e2d\u6dfb\u52a0 CSS \u7c7b\u540d &#8220;has-numbering&#8221;\uff0c\u5c06\u4ea7\u751f\u884c\u53f7\u3002\u4f46\u4ece\u95ee\u9898\u4e2d\u63d0\u4f9b\u7684\u4ee3\u7801\u6765\u770b\uff0c\u8fd9\u4e00\u6b65\u88ab\u9057\u6f0f\u4e86\u3002<\/p>\n<p>\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>&lt;pre class=\"brush:php;toolbar:false\"&gt;&lt;code class=\"language-html has-numbering\"&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;title&gt;\u884c\u53f7&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;p&gt;\u6d4b\u8bd5\u9875\u9762&lt;\/p&gt;&lt;p&gt;&lt;span&gt;\u7acb\u5373\u5b66\u4e60&lt;\/span&gt;\u201c&lt;a href=\"https:\/\/pan.quark.cn\/s\/cb6835dc7db1\" style=\"text-decoration: underline !important; color: blue; font-weight: bolder;\" rel=\"nofollow\" target=\"_blank\"&gt;\u524d\u7aef\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09&lt;\/a&gt;\u201d\uff1b&lt;\/p&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n&lt;\/code&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd8\u9700\u8981\u52a0\u5165\u989d\u5916\u7684 JavaScript \u4ee3\u7801\u6765\u52a8\u6001\u751f\u6210\u884c\u53f7\uff1a<\/p>\n<pre>hljs.highlightAll();\n$(function () {\n    $('pre code').each(function () {\n        var lines = $(this).text().split('\n').length - 1;\n        var $numbering = $('&lt;\/i&gt;').addClass('pre-numbering');\n        $(this)\n            .parent()\n            .append($numbering);\n        for (i = 1; i &lt;= lines; i++) {\n            $numbering.append($('&lt;i&gt;').text(i));\n        }\n    });\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 Highlight.js \u4e3a HTML \u4ee3\u7801\u6dfb\u52a0\u884c\u53f7\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>highlight.js \u6dfb\u52a0\u884c\u53f7 \u5728\u4f7f\u7528 Highlight.js \u7ed9 HTML \u6e90\u4ee3\u7801\u7740\u8272\u7684\u8fc7\u7a0b\u4e2d\uff0c\u8981\u589e\u52a0\u884c\u53f7\uff0c\u9700\u8981\u6df1\u5165\u7406\u89e3\u5b98\u65b9\u6587\u6863\u4e2d\u5bf9\u884c\u53f7\u7684\u63cf\u8ff0\u3002 \u6839\u636e\u5b98\u65b9\u63cf\u8ff0\uff0c\u5728\u4ee3\u7801\u5757\u4e2d\u6dfb\u52a0 CSS \u7c7b\u540d &#8220;has-numbering&#8221;\uff0c\u5c06\u4ea7\u751f\u884c\u53f7\u3002\u4f46\u4ece\u95ee\u9898\u4e2d\u63d0\u4f9b\u7684\u4ee3\u7801\u6765\u770b\uff0c\u8fd9\u4e00\u6b65\u88ab\u9057\u6f0f\u4e86\u3002 \u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a &lt;pre class=&#8221;brush:php;toolbar:false&#8221;&gt;&lt;code class=&#8221;language-html has-numbering&#8221;&gt; &lt;!DOCTYPE html&gt; &lt;html lang=&#8221;en&#8221;&gt; &lt;head&gt; &lt;meta charset=&#8221;UTF-8&#8243;&gt; &lt;title&gt;\u884c\u53f7&lt;\/title&gt; &lt;\/head&gt; &lt;body&gt; &lt;p&gt;\u6d4b\u8bd5\u9875\u9762&lt;\/p&gt;&lt;p&gt;&lt;span&gt;\u7acb\u5373\u5b66\u4e60&lt;\/span&gt;\u201c&lt;a href=&#8221;https:\/\/pan.quark.cn\/s\/cb6835dc7db1&#8243; style=&#8221;text-decoration: underline !important; color: blue; font-weight: bolder;&#8221; rel=&#8221;nofollow&#8221; target=&#8221;_blank&#8221;&gt;\u524d\u7aef\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09&lt;\/a&gt;\u201d\uff1b&lt;\/p&gt; &lt;\/body&gt; &lt;\/html&gt; &lt;\/code&gt; \u767b\u5f55\u540e\u590d\u5236 \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd8\u9700\u8981\u52a0\u5165\u989d\u5916\u7684 JavaScript \u4ee3\u7801\u6765\u52a8\u6001\u751f\u6210\u884c\u53f7\uff1a hljs.highlightAll(); $(function () { $(&#8216;pre code&#8217;).each(function () { var lines = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1871","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=1871"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1871\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}