REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Datatypes: Tag!

Contents

Concept

Tags are used in HTML and other markup languages to indicate how text fields are to be treated. For example, the tag <;HTML> at the beginning of a file indicates that it should be parsed by the rules of the Hypertext Markup Language. A tag with a forward slash (/), such as <;/HTML>, indicates the closing of the tag.

Tags are a subset of series, and thus can be manipulated as such:

a-tag: <img src="mypic.jpg">
probe a-tag
<img src="mypic.jpg">
append a-tag { alt="My Picture!"}
probe a-tag
<img src="mypic.jpg" alt="My Picture!">

Format

Valid tags begin with an open angle bracket (<) and end with a closing bracket (>). For example:

<a href="index.html">
<img src="mypic.jpg" width="150" height="200">

Creation

The to-tag function converts data to the tag! datatype:

probe to-tag "title"
<title>

Use [bad-link:functions/build-tag.txt] to construct tags, including their attributes. The [bad-link:functions/build-tag.txt] function takes one argument, a block. In this block, the first word is used as the tag name and the remaining words are processed as attribute value pairs:

probe build-tag [a href http://www.rebol.com/]
<a href="http://www.rebol.com/">
probe build-tag [
    img src %mypic.jpg width 150 alt "My Picture!"
]
<img src="mypic.jpg" width="150" alt="My Picture!">

Related

Use tag? to determine whether a value is an tag! datatype.

probe tag? <a href="http://www.rebol.com/">
true

As tags are a subset of the series pseudotype, use series? to check this:

probe series? <a href="http://www.rebol.com/">
true

The form function returns a tag as a string:

probe form <a href="http://www.rebol.com/">
{<a href="http://www.rebol.com/">}

The mold function returns a tag as a string:

probe mold <a href="http://www.rebol.com/">
{<a href="http://www.rebol.com/">}

The print function prints a tag to standard output after doing a reform on it:

print <a href="http://www.rebol.com/">
<a href="http://www.rebol.com/">


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin