致电:
"<p><h1>test</h1><h1>test2</h1></p>"
我想得到:
"<h1>test2</h1></p>"
相反,我得到:
html: copy ""
emit: func [code] [repend html code]
f: func [param [block!]] [
html: copy ""
emit: func [code] [repend html code]
emit <p>
foreach p param [
emit p
]
emit </p>
return html
]
g: func ['arg [string! word!] /local html] [
return h :arg
]
h: func ['arg [string! word!]] [
either word? arg [
text: to-string arg
][
text: arg
]
html: copy ""
emit: func [code] [repend html code]
print text
emit <h1>
emit text
emit </h1>
return html
]
f [(h test) (h test2)]
我看不出为什么我的代码不起作用。请注意,我想在下面使用g函数,因为我有几个h函数,每个函数调用g来对它们进行分解。所以不要摆脱g,这是故意的。
f: func[param [block!] /local html][
html: copy ""
emit: func [code] [repend html code]
emit <p>
foreach p param [
emit p
]
emit </p>
return html
]
g: func['arg [string! word!] /local html][
return h :arg
]
h: func['arg [string! word!] /local html][
either word? arg [text: to-string arg][
text: arg
]
html: copy ""
emit: func [code] [repend html code]
print text
emit <h1>
emit text
emit </h1>
return html
]
f [(h test) (h test2)]
更新
现在我收到红色错误: 脚本错误:html不在指定的上下文中
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="portfolio.css">
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class = "navbar navbar-inverse">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#icons">
<span class="sr-only">toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Zack</a>
</div>
<div class="collapse navbar-collapse" id="icons">
<ul class="nav navbar-nav">
<li><a href="#">About Me</a></li>
<li><a href="#">Skills</a></li>
<li><a href="#">Projects</a></li>
<li><a href="#">Contact Me</a></li>
</ul>
</div>
</nav>
答案 0 :(得分:2)
你的问题是到处使用全局html: copy ""
并且新发布已经发出的html。如果您在规范块中使用 / local html 将其设置为本地,或者在Rebol2中将 func 替换为功能或功能< / strong>在Red中,它应该可以工作
>>f [ [h test] [h test2]]
test
test2
== "<p><h1>test</h1><h1>test2</h1></p>"
>>
答案 1 :(得分:1)
好的,这里是Red和Rebol稍微优化的版本,没有功能或功能
emit: func [code html] [repend html code]
f: func[param [block!] /local html][
html: copy ""
emit <p> html
foreach p param [
emit p html
]
emit </p> html
return html
]
g: func['arg [string! word!] l][
return h :arg
]
h: func['arg [string! word!] /local html text][
either word? arg [text: to-string arg][
text: arg
]
html: copy ""
print text
emit <h1> html
emit text html
emit </h1> html
return html
]
>>f [ [h test] [h test2]]
test
test2
== "<p><h1>test</h1><h1>test2</h1></p>"