修改 Markdown.here 基本渲染 CSS ,一鍵搞定微信公衆平臺文章編輯

和程序猿呆久了以後的一個表現就是:不想機械複製粘貼,若是可以搞幾行代碼,或者運行幾個腳本,真是甚好。本文的部分方法,仍是諸位程序猿教的O(∩_∩)O。javascript

Why Markdown

首先,Markdown 大法好。php

其次,由於想到你們在這裏寫文章都用 markdown,妹紙就想着,微信公衆平臺上的文章用 markdown格式是否是更有利於咱們程序猿哥哥閱讀呢(別誇我貼心?我是來求關注的css

Next

打開 Chrome ,搜關鍵詞:微信、markdownjava

萬能的某乎上找到了這麼一個話題「如何排版微信公衆平臺的文章?」。nginx

下載了 Markdown.here 插件進行編輯測試。git

測試報告

將文章複製到微信後臺,快捷鍵 Ctrl+Alt+M,Markdown 格式就一鍵搞定了,賽高。可是針對手機端的屏幕,顯示就出現如下問題:程序員

  1. 字體: 一級標題和正文文字都偏大 2 pxgithub

  2. 代碼顏色太單調:代碼前加了高亮標識,但因沒註明是 javascript/ruby or other languages,所有都是黑色的,閱讀體驗很很差web

  3. 相似於「值的類型 type」中 type 沒法用紅色標出來chrome

因此一陣高興以後妹紙的心裏又奔潰了,原本就是爲了偷懶找了插件,但出現上述問題以後,又要進行手動複製粘貼,不開森,因而又墨跡了一下子,竟發現 Markdown.here 插件居然能夠修改。

插件修改路徑: Chrome → 設置 → 擴展程序 → markdown.here → 選項 → 基本渲染 CSS

解決方式

問題1:字體大小

首先修改的是標題大小,分別將一級標題修改成 20 px;二級標題修改成 18 px

h1, h2, h3, h4, h5, h6 {
  margin: 1.3em 0 1em;
  padding: 0;
  font-weight: bold;
}

h1 {
  font-size: 20px;
  border-bottom: 1px solid #ddd;
}

h2 {
  font-size: 18px;
  border-bottom: 1px solid #eee;
}

h3 {
  font-size: 16px;
}

h4 {
  font-size: 16px;
}

h5 {
  font-size: 16px;
}

h6 {
  font-size: 16px;
  color: #777;
}

可是想到正文內容應該修改成 14 px;又在內容最後加了一句,固然這也是某位程序猿哥哥告訴個人:

p {
  font-size: 14px;
};

一番修改以後,仍出現如下問題:

  • 以後的文字,依舊是 16 px;

妹子又開始騷擾某濤程序員,獲得的解決方法是在 li 後面加入 font-size :

li {
  margin: 0.5em 0;
  font-size: 14px;
};

終於完美解決了問題 1

問題2:語法高亮

接下來解決代碼高亮問題,雖然選擇了語法高亮的主題,可是複製到微信平臺以後,全是黑色的,和小螞蟻同樣,代碼閱讀體驗很是很差,改了幾個主題以後,仍是不行,心裏有 1W 頭草泥馬奔過,後來在研究基本渲染 CSS 的時候,發現解決方案很簡單:

在三個 ``` 以後加上 「javascript」或者「ruby」或者「其餘語言」便可,本來黑色的代碼,就會變成下圖所示:

圖片描述

問題3:「值的類型 type」中 type 沒法用紅色標出來

這個問題研究了一天,終於被傻傻的我搞定了,直接在「基本渲染 CSS」中加上這一句便可

p code {
  color: rgb(217, 33, 66);
};

授人與魚不如授人以漁,下圖爲諸位提供查找途徑,這樣子之後遇到相似的事情,就均可以輕鬆解決了~

路徑:找到這一東西對應的元素,發現是在 p code中的 color,而後在 CSS 中添加語句。

圖片描述

有感而發

寫了這麼一大段教程,有些語法可能還不是很好= =,但倒是讓工做變得更便捷。
但其實最簡單的解決途徑是:找個程序員男票?

妹子其實還遇到一個問題,就是選擇用空 4 格高亮代碼的,在微信上生成 markdown 以後,代碼是沒法高亮的,請問這個該如何解決?須要加個判斷麼?

如下爲「基本渲染 CSS」初始化內容

/*
 * NOTE:
 * - The use of browser-specific styles (-moz-, -webkit-) should be avoided.
 *   If used, they may not render correctly for people reading the email in
 *   a different browser than the one from which the email was sent.
 * - The use of state-dependent styles (like a:hover) don't work because they
 *   don't match at the time the styles are made explicit. (In email, styles
 *   must be explicitly applied to all elements -- stylesheets get stripped.)
 */

/* This is the overall wrapper, it should be treated as the `body` section. */
.markdown-here-wrapper {
}

/* To add site specific rules, you can use the `data-md-url` attribute that we
   add to the wrapper element. Note that rules like this are used depending
   on the URL you're *sending* from, not the URL where the recipient views it.
*/
/* .markdown-here-wrapper[data-md-url*="mail.yahoo."] ul { color: red; } */

pre, code {
  font-size: 0.85em;
  font-family: Consolas, Inconsolata, Courier, monospace;
}

code {
  margin: 0 0.15em;
  padding: 0 0.3em;
  white-space: pre-wrap;
  border: 1px solid #EAEAEA;
  background-color: #F8F8F8;
  border-radius: 3px;
  display: inline; /* added to fix Yahoo block display of inline code */
}

pre {
  font-size: 1em;
  line-height: 1.2em;
}

pre code {
  white-space: pre;
  overflow: auto; /* fixes issue #70: Firefox/Thunderbird: Code blocks with horizontal scroll would have bad background colour */
  border-radius: 3px;
  border: 1px solid #CCC;
  padding: 0.5em 0.7em;
  display: block !important; /* added to counteract the Yahoo-specific `code` rule; without this, code blocks in Blogger are broken */
}

/* In edit mode, Wordpress uses a `* { font: ...;} rule+style that makes highlighted
code look non-monospace. This rule will override it. */
.markdown-here-wrapper[data-md-url*="wordpress."] code span {
  font: inherit;
}

/* Wordpress adds a grey background to `pre` elements that doesn't go well with
our syntax highlighting. */
.markdown-here-wrapper[data-md-url*="wordpress."] pre {
  background-color: transparent;
}

/* This spacing has been tweaked to closely match Gmail+Chrome "paragraph" (two line breaks) spacing.
Note that we only use a top margin and not a bottom margin -- this prevents the
"blank line" look at the top of the email (issue #243).
*/
p {
  /* !important is needed here because Hotmail/Outlook.com uses !important to
     kill the margin in <p>. We need this to win. */
  margin: 0 0 1.2em 0 !important;
}

table, pre, dl, blockquote, q, ul, ol {
  margin: 1.2em 0;
}

ul, ol {
  padding-left: 2em;
}

li {
  margin: 0.5em 0;
}

/* Space paragraphs in a list the same as the list itself. */
li p {
  /* Needs !important to override rule above. */
  margin: 0.5em 0 !important;
}

/* Smaller spacing for sub-lists */
ul ul, ul ol, ol ul, ol ol {
  margin: 0;
  padding-left: 1em;
}

/* Use Roman numerals for sub-ordered-lists. (Like Github.) */
ol ol, ul ol {
  list-style-type: lower-roman;
}

/* Use letters for sub-sub-ordered lists. (Like Github.) */
ul ul ol, ul ol ol, ol ul ol, ol ol ol {
  list-style-type: lower-alpha;
}

dl {
  padding: 0;
}

dl dt {
  font-size: 1em;
  font-weight: bold;
  font-style: italic;
}

dl dd {
  margin: 0 0 1em;
  padding: 0 1em;
}

blockquote, q {
  border-left: 4px solid #DDD;
  padding: 0 1em;
  color: #777;
  quotes: none;
}

blockquote::before, blockquote::after, q::before, q::after {
  content: none;
}

h1, h2, h3, h4, h5, h6 {
  margin: 1.3em 0 1em;
  padding: 0;
  font-weight: bold;
}

h1 {
  font-size: 1.6em;
  border-bottom: 1px solid #ddd;
}

h2 {
  font-size: 1.4em;
  border-bottom: 1px solid #eee;
}

h3 {
  font-size: 1.3em;
}

h4 {
  font-size: 1.2em;
}

h5 {
  font-size: 1em;
}

h6 {
  font-size: 1em;
  color: #777;
}

table {
  padding: 0;
  border-collapse: collapse;
  border-spacing: 0;
  font-size: 1em;
  font: inherit;
  border: 0;
}

tbody {
  margin: 0;
  padding: 0;
  border: 0;
}

table tr {
  border: 0;
  border-top: 1px solid #CCC;
  background-color: white;
  margin: 0;
  padding: 0;
}

table tr:nth-child(2n) {
  background-color: #F8F8F8;
}

table tr th, table tr td {
  font-size: 1em;
  border: 1px solid #CCC;
  margin: 0;
  padding: 0.5em 1em;
}

table tr th {
 font-weight: bold;
  background-color: #F0F0F0;
}

last, but not the least

謝謝閱讀,之後能夠在 SegmentFault 微信留言,教妹子編(xue)微(dai)信(ma)哦,這樣子就會有更多好玩的功能和你們互動了。

圖片描述

ps

當前在用版本的基本渲染 CSS

.markdown-here-wrapper {
}
 
/* To add site specific rules, you can use the `data-md-url` attribute that we
   add to the wrapper element. Note that rules like this are used depending
   on the URL you're *sending* from, not the URL where the recipient views it.
*/
/* .markdown-here-wrapper[data-md-url*="mail.yahoo."] ul { color: red; } */


/* In edit mode, Wordpress uses a `* { font: ...;} rule+style that makes highlighted
code look non-monospace. This rule will override it. */
.markdown-here-wrapper[data-md-url*="wordpress."] code span {
  font: inherit;
}
 
/* Wordpress adds a grey background to `pre` elements that doesn't go well with
our syntax highlighting. */
.markdown-here-wrapper[data-md-url*="wordpress."] pre {
  background-color: transparent;
}
 
/* This spacing has been tweaked to closely match Gmail+Chrome "paragraph" (two line breaks) spacing.
Note that we only use a top margin and not a bottom margin -- this prevents the
"blank line" look at the top of the email (issue #243).
*/

p {
  /* !important is needed here because Hotmail/Outlook.com uses !important to
     kill the margin in <p>. We need this to win. */
  margin: 0 0 1.5em 0 !important;
  font-size: 15px;
}

pre {
  padding: 10px;
  line-height: 1em;
  box-sizing: border-box; 
  background-color: #F8F8F8;
  margin: 0px 0px 1.5em !important;
  color: #333;
  word-wrap: break-word!important;
  overflow: auto;
}
 
pre code {
  line-height: 1.75em;
    white-space: pre;
    box-sizing: border-box; 
    font-size: 14px;
    font-family: monospace;
    background: none;
 
};

 
table, dl, blockquote, q, ul, ol {
  margin: 1.2em 0;
}
 
ul, ol {
  padding-left: 2em;
  font-size: 15px;
  padding-bottom: 1em;
}
 
li {
  margin: 0.5em 0;
   font-size: 15px;
}
li code{
  font-size: 15px;
  line-height: 1.75em;
  font-family: monospace; 
  color: rgb(199, 37, 78);
  background-color: rgb(249, 242, 244);
  padding: 3px 5px;
  max-width: 100% !important;
}
 
/* Space paragraphs in a list the same as the list itself. */
li p {
  /* Needs !important to override rule above. */
  margin: 0.5em 0 !important; 
};
 
/* Smaller spacing for sub-lists */
ul ul, ul ol, ol ul, ol ol {
  margin: 0;
  padding-left: 1em;
}
 
/* Use Roman numerals for sub-ordered-lists. (Like Github.) */
ol ol, ul ol {
  list-style-type: lower-roman;
}
 
/* Use letters for sub-sub-ordered lists. (Like Github.) */
ul ul ol, ul ol ol, ol ul ol, ol ol ol {
  list-style-type: lower-alpha;
}
 
p code {
    font-size:15px;
    line-height: 1.75em;
    max-width: 100%!important;
    font-family: monospace;
    color: #c7254e;
    background-color: #f9f2f4;
    padding-left:5px;
    padding-right:5px;
    padding-top:3px;
    padding-bottom:3px;
};
 
dl {
  padding: 0;
}
 
dl dt {
  font-size: 15px;
  font-weight: bold;
  font-style: italic;
}
 
dl dd {
  margin: 0 0 1em;
  padding: 0 1em;
}
 
blockquote, q {
  border-left: 2px solid #009a61;
  background: #f6f6f6;
  color: #555;
  quotes: none;
  line-height: 1.6;
  word-wrap: break-word;
    padding-bottom:1px;
    padding-top:20px;
    margin: 1.5em 0;


}


 
h1, h2, h3, h4, h5, h6 {
  margin: 1.3em 0 1em;
  padding: 0;
  font-weight: bold;

}
 
h1 {
  font-size: 20px;
  border-bottom: 1px solid #ddd;
}
 
h2 {
  font-size: 20px;
  border-bottom: 1px solid #eee;
}
 
h3 {
  font-size: 18px;
}
 
h4 {
  font-size: 16px;
}
 
h5 {
  font-size: 16px;
}
 
h6 {
  font-size: 16px;
  color: #777;
}
 
table {
  padding: 0;
  border-collapse: collapse;
  border-spacing: 0;
  font-size:15px ;
  font: inherit;
  border: 0;
}
 
tbody {
  margin: 0;
  padding: 0;
  border: 0;
}
 
table tr {
  border: 0;
  border-top: 1px solid #CCC;
  background-color: white;
  margin: 0;
  padding: 0;
}

 
table tr th, table tr td {
  font-size: 15px;
  border: 1px solid #CCC;
  margin: 0;
  padding: 0.5em 1em;
}
 
table tr th {
 font-weight: bold;
  background-color: #F0F0F0;
}

當前在用版的語法高亮 CSS

/*

github.com style (c) Vasily Polovnyov <vast@whiteants.net>

*/

.hljs {
  display: block;
  overflow-x: auto;
  padding: 0.5em;
  color: #657b83;
  -webkit-text-size-adjust: none;
}

.hljs-comment,
.hljs-template_comment,
.hljs-pi,
.hljs-doctype,
.diff .hljs-header,
.hljs-javadoc {
  color: #93a1a1;
  font-style: italic;
}


.hljs-keyword,
.hljs-addition,
.method,
.css .rule .hljs-keyword,
.hljs-winutils,
.javascript .hljs-title,
.nginx .hljs-title,
.hljs-subst,
.hljs-request,
.hljs-status {
  color: #859900;
  font-weight: bold;
}


.hljs-command,
.hljs-phpdoc,
.hljs-tag,
.hljs-number,
.hljs-regexp,
.hljs-string,
.hljs-hexcolor,
.hljs-tag .hljs-value,
.hljs-rules .hljs-value,
.tex .hljs-formula,
.hljs-link_url,
.ruby .hljs-constant {
  color: #2aa198;
}



.hljs-dartdoc {
  color: #d14;
}

.hljs-literal{
   color: #657b83;
}

.hljs-title,
.hljs-localvars,
.hljs-identifier,
.hljs-chunk,
.hljs-id,
.hljs-decorator,
.hljs-built_in,
.vhdl .hljs-literal,
.css .hljs-function,
.scss .hljs-preprocessor {
  color: #268bd2;
  font-weight: bold;
}

.javascript .hljs-title,
.hljs-list .hljs-keyword,
.hljs-subst {
  font-weight: normal;
}


.tex .hljs-command {
  color: #458;
  font-weight: bold;
}

.hljs-tag .hljs-title,
.hljs-rules .hljs-property,
.django .hljs-tag .hljs-keyword {
  color: #000080;
  font-weight: normal;
}

.hljs-attribute,
.hljs-variable,
.hljs-constant,
.hljs-class .hljs-title,
.hljs-type,
.hljs-parent,
.haskell .hljs-type,
.hljs-link_reference,
.smalltalk .hljs-number,
.lisp .hljs-body {
  color: #b58900;
}


.hljs-symbol,
.ruby .hljs-symbol .hljs-string,
.lisp .hljs-keyword,
.clojure .hljs-keyword,
.scheme .hljs-keyword,
.tex .hljs-special,
.hljs-prompt {
  color: #990073;
}


.hljs-preprocessor,
.hljs-pragma,
.hljs-shebang,
.hljs-cdata {
  color: #999;
  font-weight: bold;
}

.hljs-deletion {
  background: #fdd;
}


.diff .hljs-change {
  background: #0086b3;
}
相關文章
相關標籤/搜索