Global

Methods

(async) WMd2html(fpIn, fpOut, optopt) → {Promise}

Description:
  • Markdown檔轉Html檔

Source:
Example
import w from 'wsemi'
import WMd2html from './src/WMd2html.mjs'
//import WMd2html from 'w-md2html/src/WMd2html.mjs'
//import WMd2html from 'w-md2html'

async function test() {

    let fpIn = `./test/report.md`
    let fpOut = `./test/report.html`
    let opt = {
        imgWidthMax: '500px',
        funProcFpOut: (msg) => {
            console.log('msg', msg)
            return msg.fpOut
        },
    }

    let r = await WMd2html(fpIn, fpOut, opt)
    console.log(r)
    // => ok

    w.fsDeleteFile(fpOut)

}
test()
    .catch((err) => {
        console.log('catch', err)
    })
Parameters:
Name Type Attributes Default Description
fpIn String

輸入來源Markdown檔位置字串

fpOut String

輸入轉出Html檔位置字串

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
tableBorderColor String <optional>
'#666'

輸入表格邊框顏色 (CSS color)

fontFamilies Array.<string> <optional>
['Microsoft JhengHei','Avenir','Helvetica','Arial','sans-serif']

輸入內文字型優先順序列表

fontSizeUnit String <optional>
'pt'

輸入字型大小單位字串,可使用例如'pt'、'px'等,預設'pt'

fontSizeScale Number <optional>
1

輸入字型大小縮放倍率數字,預設1

fontSizeDef Number | String <optional>

輸入內文字型大小數字或字串,預設為12,自動轉字型為12*fontSizeScale+fontSizeUnit

fontSizeH1 Number | String <optional>

輸入h1字型大小數字或字串,預設為20,自動轉字型為20*fontSizeScale+fontSizeUnit

fontSizeH2 Number | String <optional>

輸入h2字型大小數字或字串,預設為16,自動轉字型為16*fontSizeScale+fontSizeUnit

fontSizeH3 Number | String <optional>

輸入h3字型大小數字或字串,預設為14,自動轉字型為14*fontSizeScale+fontSizeUnit

fontSizeH4 Number | String <optional>

輸入h4字型大小數字或字串,預設為12,自動轉字型為12*fontSizeScale+fontSizeUnit

fontSizeH5 Number | String <optional>

輸入h5字型大小數字或字串,預設為12,自動轉字型為12*fontSizeScale+fontSizeUnit

fontSizeH6 Number | String <optional>

輸入h6字型大小數字或字串,預設為12,自動轉字型為12*fontSizeScale+fontSizeUnit

fontSizeP Number | String <optional>

輸入p字型大小數字或字串,預設為12,自動轉字型為12*fontSizeScale+fontSizeUnit

fontSizeTab Number | String <optional>

輸入表格文字字型大小數字或字串,預設為11,自動轉字型為11*fontSizeScale+fontSizeUnit

fontSizeCode Number | String <optional>

輸入程式碼區塊字型大小數字或字串,預設為10,自動轉字型為10*fontSizeScale+fontSizeUnit

textAlignH1 String <optional>
'left'

輸入h1對齊方式,可使用'left'、'center'、'right',預設'left'

textAlignH2 String <optional>
'left'

輸入h2對齊方式,可使用'left'、'center'、'right',預設'left'

textAlignH3 String <optional>
'left'

輸入h3對齊方式,可使用'left'、'center'、'right',預設'left'

textAlignH4 String <optional>
'left'

輸入h4對齊方式,可使用'left'、'center'、'right',預設'left'

textAlignH5 String <optional>
'left'

輸入h5對齊方式,可使用'left'、'center'、'right',預設'left'

textAlignH6 String <optional>
'left'

輸入h6對齊方式,可使用'left'、'center'、'right',預設'left'

imgWidthMax Number | String <optional>
null

輸入圖片樣式給予最大寬度,可輸入數字500單位為px,或是字串例如'100%',預設null

htmlTemp String <optional>
null

輸入模板字串,其內須取代{title}與{html},預設null

imgConvertToBase64 Boolean <optional>
true

輸入圖片是否自動轉Base64布林值,預設true

funProcFpOut function <optional>
null

輸入處理輸出檔名函數,函數會傳入{fpOut,pretitle},分別為原始輸出檔位置與提取Markdown內pretitle區文字,預設null

Returns:

回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息

Type
Promise

(async) md2html(md, optopt) → {Promise}

Description:
  • Markdown轉Html

Source:
Example
let markdown = `...`
md2html(markdown,{mergeStyle:true})
    .then((res)=>{
        console.log(res)
        ele.innerHTML = res.html
    })
    .catch((err)=>{
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
md String

輸入Markdown字串

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
tableBorderColor String <optional>
'#666'

輸入表格邊框顏色 (CSS color)

fontFamilies Array.<string> <optional>
['Microsoft JhengHei','Avenir','Helvetica','Arial','sans-serif']

輸入內文字型優先順序列表

fontSizeUnit String <optional>
'pt'

輸入字型大小單位字串,可使用例如'pt'、'px'等,預設'pt'

fontSizeScale Number <optional>
1

輸入字型大小縮放倍率數字,預設1

fontSizeDef Number | String <optional>

輸入內文字型大小數字或字串,預設為12,自動轉字型為12*fontSizeScale+fontSizeUnit

fontSizeH1 Number | String <optional>

輸入h1字型大小數字或字串,預設為20,自動轉字型為20*fontSizeScale+fontSizeUnit

fontSizeH2 Number | String <optional>

輸入h2字型大小數字或字串,預設為16,自動轉字型為16*fontSizeScale+fontSizeUnit

fontSizeH3 Number | String <optional>

輸入h3字型大小數字或字串,預設為14,自動轉字型為14*fontSizeScale+fontSizeUnit

fontSizeH4 Number | String <optional>

輸入h4字型大小數字或字串,預設為12,自動轉字型為12*fontSizeScale+fontSizeUnit

fontSizeH5 Number | String <optional>

輸入h5字型大小數字或字串,預設為12,自動轉字型為12*fontSizeScale+fontSizeUnit

fontSizeH6 Number | String <optional>

輸入h6字型大小數字或字串,預設為12,自動轉字型為12*fontSizeScale+fontSizeUnit

fontSizeP Number | String <optional>

輸入p字型大小數字或字串,預設為12,自動轉字型為12*fontSizeScale+fontSizeUnit

fontSizeTab Number | String <optional>

輸入表格文字字型大小數字或字串,預設為11,自動轉字型為11*fontSizeScale+fontSizeUnit

fontSizeCode Number | String <optional>

輸入程式碼區塊字型大小數字或字串,預設為10,自動轉字型為10*fontSizeScale+fontSizeUnit

textAlignH1 String <optional>
'left'

輸入h1對齊方式,可使用'left'、'center'、'right',預設'left'

textAlignH2 String <optional>
'left'

輸入h2對齊方式,可使用'left'、'center'、'right',預設'left'

textAlignH3 String <optional>
'left'

輸入h3對齊方式,可使用'left'、'center'、'right',預設'left'

textAlignH4 String <optional>
'left'

輸入h4對齊方式,可使用'left'、'center'、'right',預設'left'

textAlignH5 String <optional>
'left'

輸入h5對齊方式,可使用'left'、'center'、'right',預設'left'

textAlignH6 String <optional>
'left'

輸入h6對齊方式,可使用'left'、'center'、'right',預設'left'

imgWidthMax Number | String <optional>
null

輸入圖片樣式給予最大寬度,可輸入數字500單位為px,或是字串例如'100%',預設null

funWalkTokens function <optional>
null

輸入marked轉換時的walkTokens函數,可執行進階處理,預設null

mergeStyle Boolean <optional>
false

輸入是否將style放入html內布林值,預設false

Returns:

回傳Promise,resolve回傳轉換後物件,包含html、styleSrcs、styleDef,reject回傳錯誤訊息

Type
Promise