跳到主要內容

StackEdit 自定 CSS 匯出 HTML Template

StackEdit 自定 CSS 匯出 HTML Template

StackEdit 是一個所見即所得的線上 Markdown 編輯器,在先前的文章已有許多的介紹。身為程式設計在寫筆記的時候更是需要像這樣的工具,讓我們更能聚焦在內容上並且能運用 highlight.js 來標註程式碼。


檔案分享的方法

Google 雲端硬碟、Dropbox

我們更可以將筆記透過 StackEdit 直接發佈至 Google Blogger 上,或是儲存在自己的 Google 雲端硬碟、Dropbox 等等的位置。

Gist、StackEdit Viewer

如果需要將資料分享給其他沒有安裝 Markdown Viewer 的人,除了使用上述的方法,我們也可以將檔案發佈至 Gist ,或是將我們的 Markdown 檔案放至網路,透過 StackEdit 的 Viewer 將網址引入直接使用瀏覽器觀看。Ex:Here

https://stackedit.io/viewer#!url=[放置 Markdown 檔案的 URL 位址]

PDF

StackEdit 的 PDF 功能是需要透過雲端的轉換(透過 Pondoc + LaTex 實踐),對於這個部分的功能是贊助者項目,如果覺得 StackEdit 好用,很建議大家贊助讓他們可以更長久的經營。另外一個方式,是利用 StackEdit Viewer + Chrome Browser 來實踐。

  1. 開啓 Chrome Browser
  2. 開啓 StackEdit Viewer:Menu –> StackEdit Viewer
  3. 在 Viewer 模式下開啓列印
  4. 選擇 「Save as PDF」

HTML

另外一種跨平臺支援的方式是使用 HTML,只要是有瀏覽器都可以觀看,而且透過 CSS 可以改變成我們自己想要變化的風格。也是今天主要想和大家分享的方法。


使用自定的 CSS 匯出 HTML 檔案

StackEdit 匯出 HTML 的方式所匯出的檔案是很陽春白白靜靜的檔案,無論字型還是區塊安排都會有一點點的悲劇。還好,它還提供了一個以自定 Template 來匯出 HTML 的方式,讓我們有機會透過自定的 CSS 檔來完整個 HTML 檔的佈局。

自定的方式需要準備兩個主要的內容,HTML TemplateMarkdown CSS

HTML Template

我的 HTML Template 如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= documentTitle %></title>

<link rel="stylesheet" type="text/css" href="***[user define css file url]***">

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/styles/monokai_sublime.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/highlight.min.js"></script>

<!--
To use prettify.js uncomment this part and comment the previous script
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?skin=desert"></script>
-->

</head>
<body><%= documentHTML %></body>
</html>

請以上面的 Template 的內容取代 StackEdit Default template 的設定。這份 Template 使用 Highlight.js 作為程式碼標註,如果想使用 Google 的 Code-prettify(prettify.js)只要交換註解的部分即可。

Note:
1. 將 ***[user define css file url]*** 的內容取代為自己 CSS 的 URL位址。
2. 上述 Template 在 highlight.js 的部分是使用 sublime monokai 的顏色主題。

Default template 的設定:

  1. Menu –> Settings
  2. Settings 對話視窗 –> Advance

    enter image description here

  3. Advance –> Default template

    enter image description here

Markdown CSS

我自定的 CSS 檔內容如下,歡迎複製存檔後傳至自己的網路空間(我是放在 Google 雲端硬碟中),在 Template 中設定好路徑即可。

/* 
 * Copyright 2015 ninthday.
 * Version: 1.2
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Some content is copyrighted by Twitter, Inc., and also released under an
 * Apache License; these sections are noted in the source.
 * 
 * The CSS is based on this template:
 * http://pacinispace.blogspot.tw/2013/07/write-in-markdown-stackedit-with-custom.html
 *[(Copyright 2013 Alex Pacini unless otherwise noted.
 * Licensed under the Apache License, Version 2.0 (the "License");]
 * http://kevinburke.bitbucket.org/markdowncss/
 *[(Copyright 2011 Kevin Burke unless otherwise noted.
 * Licensed under the Apache License, Version 2.0 (the "License");]
 * Then it was extended to cover the Markdown Extra and applied some light changes.
 */
html{
    font-size: 62.5%;
}
body{
    margin: 0 auto;
    /*font-family: Georgia, Palatino, serif;*/
    font-family: Arial, "文泉驛正黑", "WenQuanYi Zen Hei", "儷黑 Pro", "LiHei Pro", "微軟正黑體", "Microsoft JhengHei", sans-serif;
    color: #444444;
    line-height: 1.3;
    max-width: 960px;
    padding: 30px;
    font-size: 1.6rpm;
}

h1, h2, h3, h4 {
    color: #111111;
    font-weight: 400;
}
h1, h2, h3, h4, h5, p {
    margin-bottom: 24px;
    padding: 0;
}
h1 {
    font-size: 4.8rem;
}
h2 {
    font-size: 3.6rem;
    /* The bottom margin is small. It's designed to be used with gray meta text
     * below a post title. */
    margin: 24px 0 6px;
}
h3 {
    font-size: 2.8rem;
}
h4 {
    font-size: 2.4rem;
}
h5 {
    font-size: 2rem;
}
a {
    color: #0099ff;
    margin: 0;
    padding: 0;
    vertical-align: baseline;
    text-decoration: none;
}
img[alt=banner] {
    width: 100%;
    height: 100%;
    margin-left: -10%;
}
a:hover {
    text-decoration: none;
    color: #ff6600;
}
a:visited {
    color: purple;
    text-decoration: none;
}
ul, ol {
    margin-top: 0;
    margin-bottom: 1.1em;
}
li {
    line-height: 2.4rem;
}
li ul, li ol {
    margin-left: 1.2rem;
}

p, ul, ol {
    font-size: 1.6rem;
    line-height: 1.5;
    max-width: 800px;
}

pre {
    border-radius: 4px;
    padding: 10px 24px;
    max-width: 800px;
    white-space: pre-wrap;
}

pre code {
    line-height: 1.7;
    font-size: 14px;
    font-family: "Source Code Pro", Consolas, monospace;
}

pre code, pre.prettyprint code{
    background-color:transparent !important;
}

pre.prettyprint {
    background: #23241f;
}

code {
    border-radius: 4px;
    font-size: 1.6rem;
    color: #3f3f3f;
    padding: 2px 4px;
    background-color: rgba(128,128,128,0.09);
}

aside {
    display: block;
    float: right;
    width: 390px;
}

blockquote {
    border-left: 10px solid #eee;
    padding: 15px 20px;
    margin-left:0;
    background-color: rgba(128,128,128,0.06);
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px;
}

blockquote cite {
    font-size:14px;
    line-height:20px;
    color:#bfbfbf;
}
blockquote cite:before {
    content: '\2014 \00A0';
}

blockquote p {  
    color: #666;
    margin:0 0 1.1rem;
}

blockquote p:last-child,
blockquote ul:last-child,
blockquote ol:last-child{
    margin-bottom:0;
}

hr{
    margin-top:21px;
    margin-bottom:21px;
    border:0;
    border-top:1px solid rgba(128,128,128,0.3)
}

dt {
  font-weight: bold;
}

dt, dd {
    margin-top: 5px; 
    margin-bottom: 10px;
    font-size: 1.6rem;
}

dd {
    margin-left: 40px;
}

table {
    margin-bottom: 20px;
    max-width: 100%;
    background-color: transparent;
    border-collapse: collapse;
    font-size: 1.6rem;
}

table th,
table td {
    padding: 10px;
    line-height: 20px;
    text-align: left;
    vertical-align: top;
    border-top: 1px solid #dddddd;
}

table th {
    font-weight: bold;
}

table thead th {
    vertical-align: bottom;
}

table caption + thead tr:first-child th,
table caption + thead tr:first-child td,
table colgroup + thead tr:first-child th,
table colgroup + thead tr:first-child td,
table thead:first-child tr:first-child th,
table thead:first-child tr:first-child td {
    border-top: 0;
}

table tbody + tbody {
    border-top: 2px solid #dddddd;
}

.footnote {
    vertical-align: top;
    position: relative;
    top: -0.5em;
    font-size: 0.8rem;
}

.tooltip li {
    line-height: 1.4;
}

.toc ul {
    list-style-type: none;
    margin-bottom: 1.1rem;
}

.sequence-diagram,
.flow-chart{
    text-align:center;
    margin-bottom:1.1rem
}

.sequence-diagram text,
.flow-chart text{
    font-size:15px !important;
    font-family:"Source Sans Pro",sans-serif !important;
}

.sequence-diagram [fill="#ffffff"],
.flow-chart [fill="#ffffff"]{
    fill:#f8f8f8;
}

.sequence-diagram [stroke="#000000"],
.flow-chart [stroke="#000000"]{
    stroke:#3f3f3f;
}

.sequence-diagram text[stroke="#000000"],
.flow-chart text[stroke="#000000"]{
    stroke:none;
}

.sequence-diagram [fill="#000"],
.flow-chart [fill="#000"],
.sequence-diagram [fill="#000000"],
.flow-chart [fill="#000000"],
.sequence-diagram [fill="black"],
.flow-chart [fill="black"]{
    fill:#3f3f3f;
}

Note:
這個 Markdown CSS 是參考 Pacini’s Space 文章,再做了不少的修改。

  • 修改加強了對於中文的設定
  • 整個系統單位使用 rem 的方式取代 px
  • 調整相關 Highligh.js 顯示設定
  • UML 圖形跑版的調整
  • 補上 dt, dd 設定
  • Note 區塊的寬度限制
  • 分割線的顏色比重與寬度限制
  • 將 pre code 的設定獨立

StackEdit 的 Hello! 文件,在套用我的 Markdown CSS 後的樣子(Live Preview)。原先 Pacini 的版本

留言

這個網誌中的熱門文章

Word的合併列印如何出現「千分位」符號

今天樓下的同事突然問我一個問題,合併列印的時候如何顯示「千分位符號」(逗號),就是12 , 300。在Excel我們可以很容易的為儲存格裡的數字加上千分位的標記,但是儲存格實際儲存的還是只有數字,那個千分位符號是Excel給我們看的一種「格式」。 當我們在Word裡使用Excel做好的報表來合併列印的時候,Word會最真實的將這個數字欄位給讀出來,呈現在合併列印的欄位數值裡,無論在Excel理事不是有設定千分位符號,在Word合併列印後卻沒有出現,所以我們同樣的必須給他加上格式。 Word裡加上格式並不如Excel裡按一下就完成,加上逗號的千分位格式方法如後: 1.在Word裡插入合併列印的欄位變數。 2.在變數上按滑鼠右鍵,選擇「切換功能變數代碼」(也可以直接按Alt+F9),變數會由 經費 >> 變成 { MERGEFIELD "經費" } 。 3.加上格式就是把 { MERGEFIELD "經費" } 在}前加入數字格式參數 /##,###,會成為 { MERGEFIELD "經費" /# ##,### }(這裡指定五位數,以此類推) #:這個格式項目會指定要在結果中顯示的必要位數;如果結果不含該位數的數字,則 Word 會顯示一個空格。 0:這個格式項目會指定要在結果中顯示的必要位數;如果結果不含該位數的數字,則 Word 會顯示 0 (零)。 4.預覽內容,就可以發現千分位(逗號)出現,如果數值有零的話,最好可以換成 /# ##,## 0 ,避免空格出現。 數字格式參數請參考 Microsoft Office Online 。

使用 Stackedit 發佈至 Blogger

使用 StackEdit 發佈至 Blogger 目前部落格裡新的文章幾乎都是在 StackEdit 上使用 Markdown 來完成撰寫,是一個舒適的撰寫體驗,也更能讓自己專注在文章的撰寫,不用去調整版面上的細節。StackEdit 除了可以將文本直接存在 Google Drive 上,圖形直接嵌入引用 Google+ 相簿,讓整個寫作的流程都是在雲端上完成,另外一個我喜歡的優點,是能夠直接將寫好的文章發佈到自己的部落格上。 發佈至 Blogger 部落格 將文章發佈至 Blogger 上的方法非常簡單,在 StackEdit 的左上角開啓左邊的功能列,拉開 Publish 項目並點選 Blogger,如下圖: 第一次使用時會導引至 Google 的授權頁,回到彈出的對話視窗,填寫好 Blogger 的 URL 內容。新發佈不用填寫 POST ID,這個是未來若需要更新內容的時候使用的。 按下「OK」後就完成發佈的動作,發佈完成後,在 StackEdit 該篇文章的右上角會出現 Blogger 的 Icon。 部落格的樣本改造 文章發佈至 Blogger 後有的模板會有小小的問題,如果我們使用 Markdown 時沒有寫入圖片的最大寬度,插入的圖片若比較大就會造成圖形突破樣板的驚嚇感。 這個可以透過自己改造Blogger 模板內容的 CSS,將圖片最大限制在某個數值。簡單一點的方式,是選擇現在 Blogger 中就已經有限制圖片大小的佈景主題。 程式碼高亮標識 StackEdit 的程式區塊是有支援程式碼高亮標識(Highlight)的功能,預設是使用 Highlight.js 的函式庫,也可以使用 Google prettify。Highlight.js 目前已經支援 118 種的程式語法自動偵測。還有 54 種的 Style 可以選擇。但是發佈至 Blogger 後因模板沒有相關的引入,所以程式碼區塊就和一般的文字一樣,沒有區塊和程式碼標識的區別。 我們可以透過修改 Blogger 的樣板的樣式,引入 Highlight.js 的函式庫與樣式。進入 Blogger 的後臺管理頁面,在左方的選單中選擇 範本 ,然後右方選 編輯 HTML ,開啓樣板的 HTML 編輯畫面。 我們可以在 Highlight.js ...

SSH tunnel 方式連結限制區域的伺服器

SSH tunnel 方式連結限制區域的伺服器 自從進了前公司,好久沒有時間好好的更新部落格內容了。近期離開待了將近兩年的公司,和好朋友一起創立了新的新創公司,一起在農業上用技術來幫助返鄉的青小農,希望讓用更有溫度的數據來降低青農們的門檻。 新的開始新的期待,希望自己能繼續保持赤子熱忱,把研究過的方法記錄下來分享。 在這個資安即國安的時代(嗯…那是政府的口號),大部分的伺服器都會有許多的安全設定,無論是更新的規則或是防火牆的限制等等。會限制在某個網段甚至是某個 IP 才能進行連線某些服務,對於常常喜歡加入文青到咖啡廳 Out coding 的宅宅,還是要想辦法鑽回去連線伺服器。 如果在限制區域中有一臺能對外開放連線的 SSH 機器,我們便能夠使用 SSH Tunnel 的方式橋接回去,透過通道連結到目標伺服器。說穿了其實這臺對外的機器就是跳板,我們可以利用這個跳板以類似 Port forwarding 的方式,將遠端伺服器的 IP 與 Port 對應至本機的一組位址與 Port。 Linux 下的連接方式 大部分的 Unix-Like 系統都有內建 SSH 的 Client 指令,我們只需要在 terminal 下指令就可以達到目的。 指令如下: $ ssh - N -f - L LOCAL_PORT :DEST_HOST :DEST_HOST_PORT SSH_USER @SSH_SERVER_IP SSH 參數說明 -N : 連接後不執行任何的遠端指令 -f : 連線後在背景執行 -L port:host:hostport: 在 Client 與 Server 建立一組 secure tunneling LOCAL_PORT :本機連接埠 DEST_HOST :目標連線伺服器位址 DEST_HOST_PORT :目標連線伺服器埠號 SSH_USER@SSH_SERVER_IP :做爲跳板的機器連線 Example: $ ssh -N -f -L 33890 :192 .168 .1 .100 :5022 username @ 168.95.1.1 上述的例子,會透過 168.95.1.1 這臺跳板機器,將限制區域內 192.168.1.100,Port...