跳轉到內容

Rebol 程式設計/build-markup

來自華夏公益教科書,開放的書籍,開放的世界
BUILD-MARKUP content /quiet 

返回標記文字,將 <%tags%> 替換為其計算結果。

BUILD-MARKUP 是一個函式值。

  • content -- (型別:字串檔案 URL)
  • /quiet -- 不在輸出中顯示錯誤。

原始碼

[編輯 | 編輯原始碼]
build-markup: func [
    {Return markup text replacing <%tags%> with their evaluated results.} 
    content [string! file! url!] 
    /quiet "Do not show errors in the output." 
    /local out eval value
][
    content: either string? content [copy content] [read content] 
    out: make string! 126 
    eval: func [val /local tmp] [
        either error? set/any 'tmp try [do val] [
            if not quiet [
                tmp: disarm :tmp 
                append out reform ["***ERROR" tmp/id "in:" val]
            ]
        ] [
            if not unset? get/any 'tmp [append out :tmp]
        ]
    ] 
    parse/all content [
        any [
            end break 
            | "<%" [copy value to "%>" 2 skip | copy value to end] (eval value) 
            | copy value [to "<%" | to end] (append out value)
        ]
    ] 
    out
]
華夏公益教科書