我是靠谱客的博主 贪玩黄豆,最近开发中收集的这篇文章主要介绍如何在自己搭建的hexo博客上发布文章,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1.选择一款Markdown编译器编写文章(以下步骤以csdn为例);
2.编写文章:注册账号登录进去,点击:头像-管理博客,进入文章管理页面,点击左上角的“Markdown编辑器”;
3.导出文章:文章写好后,在“管理博客”页面点击进入目标文章,点击顶部的“导出选项”,即可将文章导出到本地;

在这里插入图片描述
4.将导出的.md文件复制到hexo博客文件下的/source/_posts文件内;
5.复制完成后,用编译器打开这个文件,在第一行加上title

---
title: 我的第一篇博客
---

:这一步用来给文章命名,不按这个格式写的话,在hexo博客上就会显示这个文章没有名字
在这里插入图片描述
6.命名结束完成后,在/source/_posts文件内鼠标右键点击空白处,选择Git Bash Here

  • 输入 hexo g (完整命令为hexo generate),用于生成静态文件;
  • 然后输入 hexo s(完整命令为hexo server),用于启动服务器,主要用来本地预览;完成后 打开浏览器输入 http://localhost:4000,会发现多了你刚写的那篇博客;
  • 最后输入hexo d(hexo deploy),用于将本地文件发布到github等git仓库上;

7.文章发布完成
8.注意:每次对hexo博客上的博客.md文件进行更改后都要重复步骤6,这样更改的内容才能在hexo博客上显示。

最后

以上就是贪玩黄豆为你收集整理的如何在自己搭建的hexo博客上发布文章的全部内容,希望文章能够帮你解决如何在自己搭建的hexo博客上发布文章所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(68)

相关文章

用Github Pages+Hexo搭建博客之(四)创建一篇新文章/草稿(创建&预览&发布)/页面(关于,标签,分类,归档,自定义) #模板(Scaffold) #文件名称&博客标题【置顶】【专栏】用Github Pages+Hexo搭建博客>关于布局(Layout)1.创建一篇新文章hexo new <title>2.草稿:创建&预览&发布3.页面:关于,标签,分类,归档,自定义>关于模板(Scaffold)&自定义>关于文件名称&博客标题
用Github Pages+Hexo搭建博客之(四)创建一篇新文章/草稿(创建&预览&发布)/页面(关于,标签,分类,归档,自定义) #模板(Scaffold) #文件名称&博客标题【置顶】【专栏】用Github Pages+Hexo搭建博客>关于布局(Layout)1.创建一篇新文章hexo new 2.草稿:创建&预览&发布3.页面:关于,标签,分类,归档,自定义>关于模板(Scaffold)&自定义>关于文件名称&博客标题</a></h5> </div> <div class="col-sm-3 col-xs-6"> <a href="/article/k-p-k_13_u_23_o_18_f3_12__23_g5.html" class="img-zoom"> <div class="embed-responsive embed-responsive-4by3"> <img src="/uploads/reation/bcimg8.png" alt="如何在自己搭建的hexo博客上发布文章" class="embed-responsive-item"> </div> </a> <h5 class="text-center"><a href="/article/k-p-k_13_u_23_o_18_f3_12__23_g5.html">如何在自己搭建的hexo博客上发布文章</a></h5> </div> <div class="col-sm-3 col-xs-6"> <a href="/article/k-p-k_13_u_23_o_18_f3_12__23_kw.html" class="img-zoom"> <div class="embed-responsive embed-responsive-4by3"> <img src="/uploads/reation/bcimg9.png" alt="计算机语言属于人类意识的客观内容,2010考研政治马克思主义哲学精选多选题(附答案)..." class="embed-responsive-item"> </div> </a> <h5 class="text-center"><a href="/article/k-p-k_13_u_23_o_18_f3_12__23_kw.html">计算机语言属于人类意识的客观内容,2010考研政治马克思主义哲学精选多选题(附答案)...</a></h5> </div> <div class="col-sm-3 col-xs-6"> <a href="/article/k-p-k_13_u_23_o_18_f3_12__23_kx.html" class="img-zoom"> <div class="embed-responsive embed-responsive-4by3"> <img src="/uploads/reation/bcimg10.png" alt="数学哲学与科学哲学和计算机科学的能动作用,数学哲学与科学哲学和计算机科学的能动作用.doc..." class="embed-responsive-item"> </div> </a> <h5 class="text-center"><a href="/article/k-p-k_13_u_23_o_18_f3_12__23_kx.html">数学哲学与科学哲学和计算机科学的能动作用,数学哲学与科学哲学和计算机科学的能动作用.doc...</a></h5> </div> <div class="col-sm-3 col-xs-6"> <a href="/article/k-p-k_13_u_23_o_18_f3_12__23_ky.html" class="img-zoom"> <div class="embed-responsive embed-responsive-4by3"> <img src="/uploads/reation/bcimg11.png" alt="数学哲学与科学哲学和计算机科学的能动作用,数学哲学与科学哲学和计算机科学的能动作用论文.doc..." class="embed-responsive-item"> </div> </a> <h5 class="text-center"><a href="/article/k-p-k_13_u_23_o_18_f3_12__23_ky.html">数学哲学与科学哲学和计算机科学的能动作用,数学哲学与科学哲学和计算机科学的能动作用论文.doc...</a></h5> </div> <!-- E 相关文章 --> </div> </div> <div class="clearfix"></div> </div> </div> <div class="panel panel-default" id="comments"> <div class="panel-heading"> <h3 class="panel-title">评论列表<small>共有 <span>0</span> 条评论</small></h3> </div> <div class="panel-body"> <div id="comment-container"> <!-- S 发表评论 --> <div id="postcomment"> <h3>发表评论 <a href="javascript:;"> <small>取消回复</small> </a></h3> <form action="/comment/post.html" method="post" id="postform"> <input type="hidden" name="__token__" value="d58ee1672f631de6581cb0033c46cbec" /> <input type="hidden" name="type" value="archives"/> <input type="hidden" name="artid" value="427889"/> <input type="hidden" name="pid" id="pid" value="0"/> <div class="form-group"> <textarea name="content" class="form-control" disabled placeholder="请登录后再发表评论" id="commentcontent" cols="6" rows="5" tabindex="4"></textarea> </div> <div class="form-group"> <a href="/index/user/login.html" class="btn btn-primary">登录</a> <a href="/index/user/register.html" class="btn btn-outline-primary">注册新账号</a> </div> </form> </div> <!-- E 发表评论 --> </div> </div> </div> </main> <aside class="col-xs-12 col-md-4"> <!--@formatter:off--> <!-- S 关于作者 --> <div class="panel panel-default about-author no-padding" data-id="108546" itemProp="author" itemscope="" itemType="http://schema.org/Person"> <meta itemProp="name" content="贪玩黄豆"/> <meta itemProp="image" content="/assets/img/avatar.png"/> <meta itemProp="url" content="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2.html"/> <div class="panel-body no-padding"> <div class="author-card"> <div class="author-head" style="background-image:url('/assets/img/author-head.jpeg');"></div> <div class="author-avatar"> <a href="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2.html"> <img src="/assets/img/avatar.png"> </a> </div> <div class="author-basic"> <div class="author-nickname"> <a href="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2.html">贪玩黄豆</a> </div> <span class="text-muted"></span> </div> <div class="row author-statistics"> <div class="col-xs-4"> <div class="statistics-text">文章</div> <div class="statistics-nums"><a href="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2.html">7</a></div> </div> <div class="col-xs-4"> <div class="statistics-text">资源</div> <div class="statistics-nums"><a href="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2.html?type=soft">0</a></div> </div> <div class="col-xs-4"> <div class="statistics-text">加入时间</div> <div class="statistics-nums">3年前</div> </div> </div> </div> </div> </div> <!-- E 关于作者 --> <!--@formatter:on--> <div class="panel panel-blockimg"> </div> <!-- S 热门文章 --> <div class="panel panel-default hot-article"> <div class="panel-heading"> <h3 class="panel-title">热门文章</h3> </div> <div class="panel-body"> <div class="media media-number"> <div class="media-left"> <span class="num tag">1</span> </div> <div class="media-body"> <a class="link-dark" href="/article/k-p-k_14_ujo_26_fy_14__7__14_0.html" title="C++实现LeetCode(96.独一无二的二叉搜索树)">C++实现LeetCode(96.独一无二的二叉搜索树)</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">2</span> </div> <div class="media-body"> <a class="link-dark" href="/article/k-p-k_14_uzo_10_f4_13__23__14_w.html" title="Spring Boot整合Mybatis">Spring Boot整合Mybatis</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">3</span> </div> <div class="media-body"> <a class="link-dark" href="/article/k-p-k_14_uzogfx_14__23_c3.html" title="野指针——奇妙比喻(编恋爱小故事)一. 野指针">野指针——奇妙比喻(编恋爱小故事)一. 野指针</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">4</span> </div> <div class="media-body"> <a class="link-dark" href="/article/k-p-k_13_u_23_o_26_fy_13_j_26_y.html" title="PHP中冒号、endif、endwhile、endfor这些都是什么">PHP中冒号、endif、endwhile、endfor这些都是什么</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">5</span> </div> <div class="media-body"> <a class="link-dark" href="/article/k-p-k_13_u_23_o_26_fz_14__7__6_4.html" title="《python生物信息学数据管理》解读——前言">《python生物信息学数据管理》解读——前言</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">6</span> </div> <div class="media-body"> <a class="link-dark" href="/article/k-p-k_13_u_23_o_18_f3_12__23_g5.html" title="如何在自己搭建的hexo博客上发布文章">如何在自己搭建的hexo博客上发布文章</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">7</span> </div> <div class="media-body"> <a class="link-dark" href="/article/k-p-k_13_u_7_o_10_fw_14_z_2_w.html" title="多臂机测试, AB测试专治选择困难症——bandit算法     赌博机算法">多臂机测试, AB测试专治选择困难症——bandit算法     赌博机算法</a> </div> </div> </div> </div> <!-- E 热门文章 --> <!-- S 热门资讯 --> <div class="panel panel-default hot-article"> <div class="panel-heading"> <h3 class="panel-title">推荐资讯</h3> </div> <div class="panel-body"> <div class="media media-number"> <div class="media-left"> <span class="num tag">1</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_uzo_26_fw_13_j_18__27_.html" title="女饲养员徒手将大棕熊按倒在地:庆祝一周岁生日 是正常的互动">女饲养员徒手将大棕熊按倒在地:庆祝一周岁生日 是正常的互动</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">2</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_uzo_26_fw_13_j_22__27_.html" title="韩国小狗与遇难家人告别全程安静:已被收养 开始新生活">韩国小狗与遇难家人告别全程安静:已被收养 开始新生活</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">3</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_uzo_26_fw_13_j_26__27_.html" title="9名家人全部遇难!韩国小狗布丁被收养 曾每天在村里苦等 吃泡菜维生">9名家人全部遇难!韩国小狗布丁被收养 曾每天在村里苦等 吃泡菜维生</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">4</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_uzo_26_fw_13__7_k_27_.html" title="AOKZOE A1X掌机预热:锐龙AI 9 HX 370、配OCulink接口">AOKZOE A1X掌机预热:锐龙AI 9 HX 370、配OCulink接口</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">5</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_uzo_26_fw_13__7_g_27_.html" title="4o-mini只有8B,o1也才300B!微软论文意外曝光GPT核心机密">4o-mini只有8B,o1也才300B!微软论文意外曝光GPT核心机密</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">6</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_uzo_26_fw_13__7_c_27_.html" title="《鱿鱼游戏》称霸全球播放量榜首 导演直言拍续集是为了钱">《鱿鱼游戏》称霸全球播放量榜首 导演直言拍续集是为了钱</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">7</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_uzo_26_fw_13__7__2__27_.html" title="99元!小米变焦支架自拍杆2发布:一键释放三脚架 蓝牙遥控变焦小米变焦支架自拍杆 2 闪亮登场,售价仅 99 元">99元!小米变焦支架自拍杆2发布:一键释放三脚架 蓝牙遥控变焦小米变焦支架自拍杆 2 闪亮登场,售价仅 99 元</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">8</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_uzo_26_fw_13__7__6__27_.html" title="赚钱是检验AI的标准">赚钱是检验AI的标准</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">9</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_uzo_26_fw_13__7__10__27_.html" title="电影《东极岛》杀青:耗时6年打造的大片《东极岛》扬帆起航,海上史诗震撼来袭">电影《东极岛》杀青:耗时6年打造的大片《东极岛》扬帆起航,海上史诗震撼来袭</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">10</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_uzo_26_fw_13__7__14__27_.html" title="健身教练带娃四个月变潦草小狗:被孩子熬得精神恍惚">健身教练带娃四个月变潦草小狗:被孩子熬得精神恍惚</a> </div> </div> </div> </div> <!-- E 热门资讯 --> <div class="panel panel-blockimg"> <a href="https://www.aliyun.com/daily-act/ecs/activity_selection?userCode=2qwpuaqd" rel="nofollow" title="推荐企业服务器" target="_blank"> <img src="/uploads/store/aliyun-sidebar.png" class="img-responsive" alt=""> </a> </div> <!-- S 热门标签 --> <div class="panel panel-default hot-tags"> <div class="panel-heading"> <h3 class="panel-title">热门标签</h3> </div> <div class="panel-body"> <div class="tags"> <a href="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2/category/k-p-k_14_u_7_o_2_f2_14__23_gx.html" class="tag"> <span>python编程</span></a> <a href="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2/category/k-p-k_14_ujo_14_fw_14_zk0.html" class="tag"> <span>打印外设</span></a> <a href="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2/category/k-p-k_14_ujogfw_14__23__18_0.html" class="tag"> <span>JavaScript</span></a> <a href="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2/category/k-p-k_13_u_23_o_6_f2_12__7_c0.html" class="tag"> <span>C语言</span></a> <a href="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2/category/k-p-k_13_u_7_okf1_13_jg1.html" class="tag"> <span>Mybatis</span></a> <a href="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2/category/k-p-k_13_ujo_10_f4_13__7__6_4.html" class="tag"> <span>PHP</span></a> <a href="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2/category/k-p-k_13_ujo_10_f5_14__23_k5.html" class="tag"> <span>python生物信息学数据管理</span></a> <a href="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2/category/k-p-k_13_ujocfy_12__7_k2.html" class="tag"> <span>hexo</span></a> <a href="/u/k-p-k_14_u_7_o_26_f4_13__7__10_2/category/k-p-k_13_uzogfx_13__23__18_z.html" class="tag"> <span>测试</span></a> </div> </div> </div> <!-- E 热门标签 --> <!-- S 推荐下载 --> <div class="panel panel-default recommend-article"> <div class="panel-heading"> <h3 class="panel-title">推荐下载</h3> </div> <div class="panel-body"> <div class="media media-number"> <div class="media-left"> <span class="num tag">1</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fz_12__10__27__27_.html" title="古龙风云录|中字-国语|Build.14142398-重要更新-狂雷陨落-剑破苍穹+DLC+修改器|解压即玩">古龙风云录|中字-国语|Build.14142398-重要更新-狂雷陨落-剑破苍穹+DLC+修改器|解压即玩</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">2</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fz_13__10__27__27_.html" title="1012部SWITCH作品合集(阿里云盘|)">1012部SWITCH作品合集(阿里云盘|)</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">3</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_f0_14__26__27__27_.html" title="三国真龙传|官方中文|Build.15084242-重要更新-古剑掠影-龙啸九天|解压即玩">三国真龙传|官方中文|Build.15084242-重要更新-古剑掠影-龙啸九天|解压即玩</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">4</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fz_12__26__27__27_.html" title="超级机器人大战系列 (T/V/X) 港版 中文 整合版 XCI">超级机器人大战系列 (T/V/X) 港版 中文 整合版 XCI</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">5</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fz_13__26__27__27_.html" title="3DS中文游戏全集CIA(官中+汉化)(275个打包下载)">3DS中文游戏全集CIA(官中+汉化)(275个打包下载)</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">6</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fz_13_w_27__27_.html" title="PS3中文 游戏全集(官中+汉化)(257个)">PS3中文 游戏全集(官中+汉化)(257个)</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">7</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_f0_14__10__27__27_.html" title="Clash for windows版本">Clash for windows版本</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">8</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_f0_14_w_27__27_.html" title="AE或PR 启动不了桌面弹出 Crash缺失 文件">AE或PR 启动不了桌面弹出 Crash缺失 文件</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">9</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fz_13_g_27__27_.html" title="PSV中文 游戏全集(官中+汉化)(479个)">PSV中文 游戏全集(官中+汉化)(479个)</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">10</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_f0_14_g_27__27_.html" title="After Effects 2018版软件下载">After Effects 2018版软件下载</a> </div> </div> </div> </div> <!-- E 推荐下载 --> <div class="panel panel-blockimg"> <a href="/" target="_blank"><img src="/uploads/store/enterprisehost.png" class="img-responsive"/></a> </div> <div class="panel panel-blockimg"> <!-- You may also like --> </div> </aside> </div> </div> </main> <footer> <!-- S 底部版权 --> <div id="footer"> <div class="container"> <div class="row footer-inner"> <div class="col-xs-12"> <div class="pull-left"> <p>网站内容,均来自于用户原创和互联网,若有侵犯到您的权益请联系我们,核实删除。</p> <p>本站为非营利性网站,靠谱客的资源均来自网络收集整理,个人纯属学习交流之用,如有侵犯您的版权请与我联系(wx:kaopuke),我们会马上改正并在下载24小时内删除!</p> <p>Copyright © 2023 All Rights Reserved. <a href="https://beian.miit.gov.cn" rel="nofollow" target="_blank">黔ICP备17011320号-2</a> <a href="https://beian.mps.gov.cn/#/query/webSearch?code=52272602002071" rel="noreferrer" target="_blank">贵公网安备52272602002071</a></p> </div> </div> </div> </div> </div> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?e749fb7b04b857116f3a8b682641b74d"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <!-- E 底部版权 --> </footer> <div id="floatbtn"> <!-- S 浮动按钮 --> <a class="hover" href="/index/user/addarticle.html" target="_blank"> <i class="fa fa-paint-brush fa-lg"></i> <em>立即<br>投稿</em> </a> <div class="floatbtn-item floatbtn-share"> <i class="fa fa-share-alt fa-lg"></i> <div class="floatbtn-wrapper" style="height:50px;top:0"> <div class="social-share" data-initialized="true" data-mode="prepend"> <a href="#" class="social-share-icon icon-weibo" target="_blank"></a> <a href="#" class="social-share-icon icon-qq" target="_blank"></a> <a href="#" class="social-share-icon icon-qzone" target="_blank"></a> <a href="#" class="social-share-icon icon-wechat"></a> </div> </div> </div> <a id="back-to-top" class="hover" href="javascript:;"> <i class="fa fa-reply fa-lg"></i> <em>返回<br>顶部</em> </a> <!-- E 浮动按钮 --> </div> <script type="text/javascript" src="/assets/libs/jquery/dist/jquery.min.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/libs/bootstrap/dist/js/bootstrap.min.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/libs/fastadmin-layer/dist/layer.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/libs/art-template/dist/template-native.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/js/jquery.autocomplete.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/js/swiper.min.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/js/share.min.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/js/cms.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/js/common.js?v=1.0.2"></script> <script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u6850766", container: "_upguagn2t8", async: true }); (window.slotbydup = window.slotbydup || []).push({ id: "u6850838", container: "_12s5gcmjcvx", async: true }); </script> <script type="text/javascript" src="//cpro.baidustatic.com/cpro/ui/cm.js" async="async" defer="defer" ></script> <!-- 复制 --> <script src="/static/tool/clipboard.min.js"></script> <script> //代码高亮溢出显示滚动条 $('.main-content pre').each(function(){ var code = $(this).text(); $(this).wrap('<div class="auto" style="overflow:auto; position:relative;"></div>'); $(this).before('<span class="copyCode">复制代码</span><textarea style="display:none;">'+code+'</textarea>'); $(this).removeAttr("style",""); // $(this).wrap('<pre><code></code></pre>'); }); $('.main-content .codebody').each(function(){ var code = $(this).text(); $(this).wrap('<div class="auto" style="overflow:auto; position:relative;"></div>'); $(this).before('<span class="copyCode">复制代码</span><textarea style="display:none;">'+code+'</textarea>'); // $(this).wrap('<pre><code></code></pre>'); }); function unescapeSpecialChars(str) { return str .replace(/</g, '<') .replace(/>/g, '>') .replace(/&/g, '&') .replace(/ /g, ' ') .replace(/"/g, '"') .replace(/'/g, '\''); } //复制代码 $('.copyCode').on('click',function(){ var txt = $(this).next().html(); txt = unescapeSpecialChars(txt); new ClipboardJS('.copyCode', {text: function() {return txt;}}); layer.msg('复制成功',{time:1000,offset:'100px'}); }); </script> <script> document.addEventListener("DOMContentLoaded", function() { const preElements = document.querySelectorAll("pre"); // 获取所有 <pre> 元素 preElements.forEach(pre => { const codeText = pre.innerHTML.trim(); // 获取代码块的内容 const lines = codeText.split("\n").length; // 计算代码行数 // 创建行号容器 const lineNumbers = document.createElement("div"); lineNumbers.className = 'line-numbers'; // 生成行号内容 let lineNumbersHtml = ''; for (let i = 1; i <= lines; i++) { lineNumbersHtml += i + '<br>'; } // 插入行号容器到 pre 元素中 lineNumbers.innerHTML = lineNumbersHtml; pre.appendChild(lineNumbers); // 保持代码块的格式化 pre.innerHTML = `<div class="line-numbers">${lineNumbersHtml}</div>` + `<div style="padding-left:40px;">${codeText}</div>`; }); }); </script> <style> .copyCode{ position:absolute; right:1px; z-index:999; background:rgba(255,255,255,0.5); border-bottom:1px solid #ddd; padding:2px 8px; font-size:11px !important; border-radius:4px; line-height:24px; cursor:pointer; } .copyCode:hover{ background:#fff; } pre code{ font-family: consolas, Menlo, "PingFang SC", "Microsoft YaHei", monospace; } .hljs { border-radius:4px; padding: 8px !important; } .hljs-ln td { padding: 2px 8px; } .hljs-ln-numbers { text-align: center; color: #abb2bf; background-color: #282c34; border-right: 1px solid #c5c5c5; vertical-align: top; } /* for block of code */ td .hljs-ln-code { padding-left: 5px; } pre { position: relative; padding-left: 5px; /* 为行号留出空间 */ background-color: #f8f9fa; border: 1px solid #e1e1e1; border-radius: 4px; font-size: 14px; line-height: 1.5; overflow-x: auto; } /* 设置行号样式 */ pre .line-numbers { position: absolute; left: 0; top: 0; padding: 10px 10px; background-color: #f1f1f1; border-right: 1px solid #e1e1e1; text-align: right; user-select: none; color: #888; } </style> </body> </html>