跳转到内容

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
]
华夏公益教科书