估计很多人都是这样,平常工作在github,等到有成果要发布,又要写微信公众号。
github用Markdown,微信公众号,至少截止今天,还是沿用富文本的方式。不是说富文本不好,但每次精心撰写的内容,重新排一遍版,还真是怪烦的。
如果在github是使用jekyll相对会容易一点,在页面上拷贝、到微信粘贴一下,大多内容都会差不多。否则就只好转换成html显示在浏览器,然后再拷贝粘贴。
Markdown转换成html大多人都会,有很多所见即所得的工具软件,比如Marked2,不过多数都是收费的。其实用免费的工具包就不错,比如pandoc。在Mac安装pandoc很容易:

brew install pandoc

重点是,pandoc直接转换出来的文本,因为只有正文部分,所以格式失真比较多,中文部分因为没有matedata说明,干脆就是乱码,所以要有比较好的html头和尾的配合会比较好。这里整理了一个我正在使用的:

    <!DOCTYPE html>  <html lang="en"><head><meta charset="utf-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /><title>test</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style id="mkstylesheet">body{-webkit-font-smoothing:antialiased;font-family:"Helvetica Neue",Helvetica,Arial,Verdana,sans-serif;margin:30px 0 0;padding:0;background:#fff}#wrapper{padding:20px}li{font-size:110%}li li{font-size:100%}li p{font-size:100%;margin:.5em 0}h1{color:#000}h2{color:#111}h3{color:#111;margin:0}h4{color:#111}h5{color:#111}h6{font-size:1em;line-height:1.5em;margin:1.5em 0}body,p,td,div{color:#111;font-family:"Helvetica Neue",Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word}a{color:#0d6ea1;text-decoration:none;-webkit-transition:color .2s ease-in-out;-moz-transition:color .2s ease-in-out;-o-transition:color .2s ease-in-out;-ms-transition:color .2s ease-in-out;transition:color .2s ease-in-out}a:hover{color:#3593d9}body{font-size:15px;line-height:21px;margin:0 auto}h1{font-size:37px;line-height:42px;margin-top:42px;margin-bottom:21px}h2{font-size:27px;line-height:42px;margin-top:42px;margin-bottom:21px}h3{font-size:20px;line-height:21px;margin-top:21px;margin-bottom:21px}h4{font-size:20px;line-height:21px;margin-top:21px;margin-bottom:21px}p,ul,ol,pre,table,blockquote{margin-top:21px;margin-bottom:21px}hr{border:1px solid;margin:-1px 0}ul ul,ol ol,ul ol,ol ul{margin-top:0;margin-bottom:0}b,strong,em,small,code{line-height:1}.footnote{color:#0d6ea1;font-size:.8em;vertical-align:super}abbr,acronym{border-bottom:1px dotted #aaa}#wrapper img{max-width:100%;height:auto}dd{font-size:1em;margin-bottom:1em}li>p:first-child{margin:0}ul,ol{padding-left:1.5em}#wrapper ol{list-style-position:inside}ul ul,ul ol{margin-bottom:.4em}caption,col,colgroup,table,tbody,td,tfoot,th,thead,tr{border-spacing:0}table{border:1px solid rgba(0,0,0,0.25);border-collapse:collapse;display:table;empty-cells:hide;margin:-1px 0 1.3125em;padding:0;table-layout:fixed}caption{display:table-caption;font-weight:700}col{display:table-column}colgroup{display:table-column-group}tbody{display:table-row-group}tfoot{display:table-footer-group}thead{display:table-header-group}td,th{display:table-cell}tr{display:table-row}table th,table td{font-size:1.1em;line-height:1.3;padding:.5em 1em 0}table thead{background:rgba(0,0,0,0.15);border:1px solid rgba(0,0,0,0.15);border-bottom:1px solid rgba(0,0,0,0.2)}table tbody{background:rgba(0,0,0,0.05)}table tfoot{background:rgba(0,0,0,0.15);border:1px solid rgba(0,0,0,0.15);border-top:1px solid rgba(0,0,0,0.2)}figure{display:inline-block;overflow:hidden;position:relative;margin:1em 0 2em}figcaption{font-style:italic;text-align:center;background:white;color:#666}.poetry pre{display:block;font-family:Georgia,Garamond,serif !important;font-size:110% !important;font-style:italic;line-height:1.6em;margin-left:1em}.poetry pre code{font-family:Georgia,Garamond,serif !important;word-break:break-all;word-break:break-word;-webkit-hyphens:auto;-moz-hyphens:auto;hyphens:auto;white-space:pre-wrap}blockquote p{font-size:110%;font-style:italic;line-height:1.6em}sup,sub,a.footnote{font-size:1.4ex;height:0;line-height:1;position:relative;vertical-align:super}sub{vertical-align:sub;top:-1px}p,h5{font-size:1.1429em;line-height:1.3125em;margin:1.3125em 0}dt,th{font-weight:700}table tr:nth-child(odd),table th:nth-child(odd),table td:nth-child(odd){background:rgba(255,255,255,0.06)}table tr:nth-child(even),table td:nth-child(even){background:rgba(200,200,200,0.25)}@media print{img,table,figure{page-break-inside:avoid}#wrapper{background:#fff;color:#303030;padding:10px;position:relative;text-indent:0}}@media screen{.inverted{background:#252a2a}.inverted #wrapper{background:#252a2a;color:#eee}.inverted hr{border-color:#333f40 !important}.inverted p,.inverted td,.inverted li,.inverted h1,.inverted h2,.inverted h3,.inverted h4,.inverted h5,.inverted h6,.inverted th,.inverted .math,.inverted caption,.inverted dt,.inverted dd{color:#eee}.inverted pre{background:#ccc;color:#111}.inverted table{background:none}.inverted table tr:nth-child(odd),.inverted table td:nth-child(odd){background:none}.inverted a{color:#acd1d5}::selection{background:rgba(157,193,200,0.5)}h1::selection{background-color:rgba(45,156,208,0.3)}h2::selection{background-color:rgba(90,182,224,0.3)}h3::selection,h4::selection,h5::selection,h6::selection,li::selection,ol::selection{background-color:rgba(133,201,232,0.3)}code::selection{background-color:rgba(0,0,0,0.7);color:#eee}code span::selection{background-color:rgba(0,0,0,0.7) !important;color:#eee !important}a::selection{background-color:rgba(255,230,102,0.2)}.inverted a::selection{background-color:rgba(255,230,102,0.6)}td::selection,th::selection,caption::selection{background-color:rgba(180,237,95,0.5)}}#mkreplaced-toc{list-style-position:inside;padding:0;margin:0 0 0 1rem;list-style-type:none}#mkreplaced-toc li::before{content:''}#mkreplaced-toc li{font-size:1rem;line-height:1.25;font-weight:normal}#mkreplaced-toc li ul{font-size:1.3rem;font-weight:300;padding:.5rem 0;margin:0 0 0 1rem}#mkreplaced-toc li.missing{list-style-type:none !important}#mkreplaced-toc.max-1 ul,#mkreplaced-toc.max1 ul{display:none}#mkreplaced-toc.max-2 ul ul,#mkreplaced-toc.max2 ul ul{display:none}#mkreplaced-toc.max-3 ul ul ul,#mkreplaced-toc.max3 ul ul ul{display:none}#mkreplaced-toc.max-4 ul ul ul ul,#mkreplaced-toc.max4 ul ul ul ul{display:none}#mkreplaced-toc.max-5 ul ul ul ul ul,#mkreplaced-toc.max5 ul ul ul ul ul{display:none}.rtl{direction:rtl;text-align:right}@media print{body{background:white;line-height:1.4}html,body,#wrapper{max-width:100%;width:100%;-webkit-text-size-adjust:none;-webkit-perspective:none !important;box-sizing:border-box;width:auto;border:0;margin:0;padding:0;float:none;-moz-box-shadow:none !important;-webkit-box-shadow:none !important;box-shadow:none !important}mark{background:transparent !important}h1,h2,h3,h4,h5,h6{page-break-after:avoid}p,h2,h3{orphans:3;widows:3}section{page-break-before:avoid}pre>code{white-space:pre;word-break:break-word}#generated-toc,#firstdiff,#toc-title,#mkdocumentprogress,#mkincludechart,#mkprogressbar1,#mkprogressbar2,.mkscrollmeter,#alllinks,.popup{display:none !important}.suppressprintlinks a{color:inherit !important;text-decoration:none !important;border-bottom:none !important;cursor:default !important}.hrefafterlinktext #wrapper a:link:after,.hrefafterlinktext #wrapper a:visited:after{content:" (" attr(href) ") ";font-size:90%;opacity:0.9}.nocodebreak pre{page-break-inside:avoid}img,table,figure{page-break-inside:avoid}.breakfootnotes .footnotes{page-break-before:always}.breakfootnotes .footnotes hr{display:none}#mktoctitle{display:block}#print-title{display:block;border-bottom:solid 1px #666}#wrapper pre{white-space:pre;white-space:pre-wrap;word-wrap:break-word}#wrapper #generated-toc-clone,#wrapper #mkreplaced-toc{display:block}.task-list .task-list-item{list-style-type:none !important}.task-list .gh-complete.task-list-item .task-list-item-checkbox:before{content:'\2713';background:#838387}.task-list .task-list-item-checkbox{-webkit-appearance:none;position:relative}.task-list .task-list-item-checkbox:before{content:' ';border:solid 1px #aaa;width:1em;height:1em;display:block;border-radius:2px;left:-20px;top:-.75em;color:white;font-weight:bold;line-height:1;text-align:center;position:absolute}}#wrapper #generated-toc-clone,#wrapper #mkreplaced-toc,#wrapper #generated-toc-clone ul,#wrapper #mkreplaced-toc ul{list-style-position:inside}#wrapper #generated-toc-clone li.missing,#wrapper #mkreplaced-toc li.missing{list-style-type: none!important}#wrapper #generated-toc-clone,#wrapper #mkreplaced-toc{list-style-type: upper-roman}#wrapper #generated-toc-clone>li>ul,#wrapper #mkreplaced-toc>li>ul {list-style-type: decimal}#wrapper #generated-toc-clone>li>ul>li>ul,#wrapper #mkreplaced-toc>li>ul>li>ul{list-style-type: decimal-leading-zero}#wrapper #generated-toc-clone>li>ul>li>ul>li>ul,#wrapper #mkreplaced-toc>li>ul>li>ul>li>ul{list-style-type: lower-greek}#wrapper #generated-toc-clone>li>ul>li>ul>li>ul>li>ul,#wrapper #mkreplaced-toc>li>ul>li>ul>li>ul>li>ul{list-style-type: disc}#wrapper #generated-toc-clone>li>ul>li>ul>li>ul>li>ul>li>ul,#wrapper #mkreplaced-toc>li>ul>li>ul>li>ul>li>ul>li>ul{list-style-type: square}#wrapper #generated-toc-clone,#wrapper #mkreplaced-toc{list-style-position:outside!important;margin-left:2rem;}</style><style id="mkprintstyles">@media print{#wrapper #generated-toc-clone,#generated-toc{display:none!important}html,body,#wrapper{font-size:10pt!important}}</style></head><body class="normal firstload"><div id="wrapper">
    </div>
<script>(function(factory){if(typeof define==="function"&&define.amd){define("bidi_helpers",[],factory)}else{window.bidi_helpers=factory()}})(function(){var module={};module.Dir={RTL:-1,UNKNOWN:0,LTR:1};module.Format={LRE:"\u202A",RLE:"\u202B",PDF:"\u202C",LRM:"\u200E",RLM:"\u200F"};module.ltrChars_="A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF\u2C00-\uFB1C\uFE00-\uFE6F\uFEFD-\uFFFF";module.rtlChars_="\u0591-\u07FF\uFB1D-\uFDFF\uFE70-\uFEFC";module.ltrDirCheckRe_=new RegExp("^[^"+module.rtlChars_+"]*["+module.ltrChars_+"]");module.ltrCharReg_=new RegExp("["+module.ltrChars_+"]");module.hasAnyLtr=function(text){return module.ltrCharReg_.test(text)};module.rtlDirCheckRe_=new RegExp("^[^"+module.ltrChars_+"]*["+module.rtlChars_+"]");module.rtlRe=module.rtlDirCheckRe_;module.isRtlText=function(text){return module.rtlDirCheckRe_.test(text)};module.isLtrText=function(text){return module.ltrDirCheckRe_.test(text)};module.isRequiredLtrRe_=/^http:\/\/.*/;module.hasNumeralsRe_=/\d/;module.estimateDirection=function(text,detectionThreshold){var rtlCount=0;var totalCount=0;var hasWeaklyLtr=false;var tokens=text.split(/\s+/);for(var i=0;i<tokens.length;i++){var token=tokens[i];if(module.isRtlText(token)){rtlCount++;totalCount++}else{if(module.isRequiredLtrRe_.test(token)){hasWeaklyLtr=true}else{if(module.hasAnyLtr(token)){totalCount++}else{if(module.hasNumeralsRe_.test(token)){hasWeaklyLtr=true}}}}}return totalCount==0?(hasWeaklyLtr?module.Dir.LTR:module.Dir.UNKNOWN):(rtlCount/totalCount>detectionThreshold?module.Dir.RTL:module.Dir.LTR)};return module});(function(factory){if(typeof define==="function"&&define.amd){define("bidiweb",["bidi_helpers"],factory)}else{window.bidiweb=factory(bidi_helpers)}})(function(bidi_helpers){var module={};var IProcessor={makeRtl:function(element){},makeLtr:function(element){}};var css_processor=function(classes){return{makeRtl:function(element){element.classList.add(classes.rtl)},makeLtr:function(element){element.classList.add(classes.ltr)}}};var style_processor=function(falign){return{makeRtl:function(element){element.style.direction="rtl";if(falign){element.style.textAlign="right"}},makeLtr:function(element){element.style.direction="ltr";if(falign){element.style.textAlign="left"}}}};module.processors={css:css_processor,style:style_processor};var nodeListMock=function(node){var list=[node];list.item=function(i){return list[i]};return list};module.process=function(query,processor){var elements;if(query instanceof NodeList){elements=query}else{if(query instanceof Node){elements=nodeListMock(query)}else{elements=document.querySelectorAll(query)}}module.process_elements(elements,processor);return elements};module.process_elements=function(elements,processor){for(var index=0;index<elements.length;index++){var element=elements.item(index);var text=element.textContent||element.value||element.placeholder||"";var dir=bidi_helpers.estimateDirection(text,0.4);if(dir==bidi_helpers.Dir.RTL){processor.makeRtl(element)}else{if(dir==bidi_helpers.Dir.LTR){processor.makeLtr(element)}}}};module.process_css=function(query,classes){var proc=module.processors.css(classes);return module.process(query,proc)};module.process_style=function(query,falign){var proc=module.processors.style(falign);return module.process(query,proc)};module.style=function(query){return module.process_style(query,true)};module.css=function(query){return module.process_css(query,{rtl:"rtl",ltr:"ltr"})};module.htmlToElement=function(html){var container=document.createElement("div");container.innerHTML=html;return container};module.html_css=function(html){var container=module.htmlToElement(html);var nodes=container.querySelectorAll("*");module.css(nodes);return container.innerHTML};module.html_style=function(html){var container=module.htmlToElement(html);var nodes=container.querySelectorAll("*");module.style(nodes);return container.innerHTML};return module});</script></body>
</html>

把上面两段html的内容分别保存为_markdown_head.html和_markdown_foot.html。然后转换的时候使用下面命令行(建议你直接保存成bash脚本比如说叫md2html.sh):

#!/bin/sh
pandoc -B ~/html_t/_markdown_head.html -A ~/html_t/_markdown_foot.html  $1 -o $2

以后转换的时候直接运行./md2html.sh abc.md abc.html就可以了。这样方式转换的html文件,可以直接在浏览器中打开,然后全选、拷贝,到微信公众号的后台粘贴,预览一下看看,失真很小,感觉比jekyll转换成的页面失真都会小很多。

转载于:https://www.cnblogs.com/andrewwang/p/8536462.html

小技巧,把Markdown文本发布到微信公众号文章相关推荐

  1. Markdown懒办法排版微信公众号文章

    懒人的烦恼 写微信公众号的人群里面,不乏十分勤奋者.看看他们使用的排版工具,便知道为了排版一篇文章,他们要耗费多少辛劳了. 请注意,他们是一个标题.一个段落.一个引言这样的用样式模板插入内容.这样排版 ...

  2. Markdown两键排版微信公众号文章

    目前已知最简单的微信公众号文章插图与排版方法.零基础图文教程.教会了也不收费哦. :-P 痛点 前些日子,我写了一篇<Markdown懒办法排版微信公众号文章>,很受读者欢迎.简书平台上该 ...

  3. php公众号批量推送,微信公众号文章如何批量发送给指定的用户

    微信公众号文章如何批量发送给指定的用户 导读:小编根据大家的需要整理了一份关于<微信公众号文章如何批量发送给指定的用户>的内容,具体内容:微信公众号的文章群发的时候,会发给所有的用户,但是 ...

  4. 【简易方法】Markdown 格式 的文章发布到微信公众号

    [简易方法]Markdown 格式 的文章发布到微信公众号 1 关于Markdown Markdown 是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档. Markdown 语言在 2 ...

  5. 如何将 Markdown 格式文章快速发布到微信公众号

    如果你和我一样,平时习惯使用 Markdown 写作,当我们想把文章发布到微信公众号或知乎等平台时,就会发现挺麻烦的,尤其是排版方面,因为它们并不支持 Markdown 格式. 那有没有简单高效的办法 ...

  6. 用Markdown,3分钟搞定微信公众号文章排版!

    用Markdown,3分钟搞定微信公众号文章排版! 还在使用第三方编辑器排版微信公众号文章?OUT了!只要你掌握本文推荐的3大操作流程,就可以熟练.高效的做好微信公众号文章排版,3分钟搞定!并且可以一 ...

  7. 小麦苗微信公众号文章链接地址

    小麦苗微信公众号文章链接地址 小麦苗的微信公众号文章链接地址 201609 发布日期 文章标题 链接地址 2016-09-30 2016-09-29 2016-09-28 2016-09-27 201 ...

  8. Markdown排版微信公众号文章

    前言 更多精彩微信关注:随心下(Suixinxia007) 大家知道,CSDN博客可以采用Markdown来写一篇文章,易于上手而且排版效果很赞,而发布微信公众号文章却不支持Markdown文件,一般 ...

  9. 微信小程序如何跳转到微信公众号文章,小程序如何关联公众号或订阅号

    微信小程序如何跳转到微信公众号文章,小程序如何关联公众号或订阅号 前置条件 公众号最高管理权限(或能与最高权限管理者配合操作) 小程序开发权限或最高管理权限 小程序方面 根据官方资料描述,小程序中展示 ...

最新文章

  1. 现代浏览器博物馆_云旅游!Tableau 为你揭秘纽约现代艺术博物馆的珍贵馆藏
  2. Ocelot中文文档-缓存
  3. 安装labelImg(win10,macOS)
  4. create-react-app应用的入口定义
  5. c语言 bcd码 16进制字符串 原理,ASCII码、HEX、字符、BCD 等等 基础知识思考
  6. git缓冲区查看_git原理学习记录:从基本指令到背后原理,实现一个简单的git
  7. C#学习笔记(十八):数据结构和泛型
  8. OpenCV3历程(4)——寻找直线的十字交叉点
  9. Activity5概述
  10. RT-Thread:RW007-连接WIFI
  11. CDCAS: A Novel Cloud Data Center Security Auditing System
  12. qlikview连接mysql_QlikView安装
  13. Access violation reading location 0x000000XX
  14. 调整物料的存货科目代码,会不会造成存货系统和总账对账不平?
  15. Qt中鼠标滑过控件由箭头变成手型QWidget::setCusor()
  16. System.InvalidOperationException: Timeout expired. Max Size Pool connections.
  17. python程序设计与算法基础第二版课后答案_python算法与程序设计基础答案
  18. python anaconda下载包_Anaconda下载 10.0.15063.0
  19. nginx配置及基本优化
  20. hackthebox-Toxic writeup

热门文章

  1. THRESH控制网桥netfilter规则执行流程
  2. 如何挑选高防服务器?
  3. wps带阴影的边框怎么设置_WPS表格阴影边框如何设置,图文详解如何设置
  4. Sparse R-CNN细节剖析
  5. 为硬件保留内存解决办法
  6. 液压装置状态评估数据集
  7. ArcPy_Mxd输出JPG
  8. 音频相关pcm,增益
  9. 过关检测-Lv3_ 数据结构
  10. Win300英雄服务器不显示,大神为你解决win7系统删除300英雄游戏的解决方案