HTML The Definitive Guide (146 page)

Read HTML The Definitive Guide Online

Authors: Chuck Musciano Bill Kennedy

BOOK: HTML The Definitive Guide
2.56Mb size Format: txt, pdf, ePub

two frames being updated at one time.

The drawback to this is that the frames must be adjacent and able to be grouped into a single document. For most pages, though, this solution works fairly well.

We've only scratched the surface of HTML tips and tricks here. Our advice: keep hacking!

15.5 Transparent Images

A. HTML Grammar

Appendix A

 

A. HTML Grammar

Contents:

Grammatical Conventions

The Grammar

For the most part, the exact syntax of an HTML document is not rigidly enforced by a browser. This gives authors wide latitude in creating documents and gives rise to documents that work on most browsers, but are actually incompatible with the standard. Stick to the standards unless your documents are fly-by-night affairs.

The HTML standard explicitly defines the ordering and nesting of tags and document elements. This syntax is embedded within the HTML Document Type Definition and is not readily understood by those not versed in SGML (see
Appendix D, The HTML 4.0 DTD). Accordingly, we provide an

alternate definition of the allowable HTML syntax, using a fairly common tool called a "grammar."

Grammar, whether it defines English sentences or HTML documents, is just a set of rules that indicate the order of language elements. These language elements can be divided into two sets:
terminal
(the actual words of the language) and
nonterminal
(all other grammatical rules). In HTML, the words correspond to the embedded markup tags and text in a document.

To use the grammar to create a valid HTML document, follow the order of the rules to see where the tags and text may be placed to create a valid HTML document.

A.1 Grammatical Conventions

We use a number of typographic and punctuation conventions to make our grammar easy to understand.

A.1.1 Typographic and Naming Conventions
For our HTML grammar, we denote the terminals with a bold, monospaced Courier typeface. The nonterminals appear in italicized text.

We also use a simple naming convention for the majority of our nonterminals: if one defines the syntax of a specific HTML tag, its name will be the tag name followed by
_tag
. If a nonterminal defines the various language elements that may be nested within a certain tag, its name will be the tag name followed by
_content
.

For example, if you are wondering exactly which elements are allowed within an tag, you can look for the
a_content
rule within the grammar. Similarly, to determine the correct syntax of a definition list created with the

tag, look for the
dl_tag
rule.

A.1.2 Punctuation Conventions

Each rule in the grammar starts with the rule's name, followed by the replacement symbol (::=) and the rule's value. We've intentionally kept the grammar simple, but we do use three punctuation elements to denote alternation, repetition, and optional elements in the grammar.

A.1.2.1 Alternation

Alternation indicates that a rule may actually have several different values, and you must choose exactly one of them. Vertical bars (|) separate the alternatives for the rule.

For example, the
heading
rule is equivalent to any one of six HTML heading tags, and so appears in the table as:
heading
::=
h1_tag

|

h2_ta
g

|

h3_tag

|

h4_tag

|

h5_tag

|

h6_tag

The
heading
rule tells us that wherever the
heading
nonterminal appears in a rule, you can replace it with exactly one of the actual heading tags.

A.1.2.2 Repetition

Repetition indicates that an element within a rule may be repeated some number of times. Repeated elements are enclosed in curly braces ({...}). The closing brace has a subscripted number other than one if the element must be repeated a minimum number of times.

For example, the

    tag may only contain
  • tags, or it may actually be empty. The rule, therefore, is:

    ul_tag
    ::=


      {
      li_tag
      }0


    The rule says that the syntax of the

      tag requires the
        tag, zero or more
      • tags, followed by a closing
      tag.

      We spread this rule across several lines and indented some of the elements to make it more readable only; it does not imply that your documents must actually be formatted this way.

      A.1.2.3 Optional elements

      Some elements may appear in a document, but are not required. Optional elements are enclosed in square brackets ([ and ]).

      The

      tag, for example, has an optional caption:
      table_tag
      ::=

      [
      caption_tag
      ]

      {
      tr_tag
      }0


      In addition, the rule says that a table begins with the

      tag, followed by an optional caption, zero or more table-row tags, and ends with the
      tag.

      A.1.3 More Details

      Our grammar stops at the tag level; it does not delve further to show the syntax of each tag, including tag attributes. For these details, refer to the HTML Quick Reference card included with this book.

      A.1.4 Predefined Nonterminals

      The HTML standard defines a few specific kinds of content that correspond to various types of text.

      We use these content types throughout the grammar. They are: literal_text

      Text is interpreted exactly as specified; no character entities or style tags are recognized.

      plain_text

      Regular characters in the document character encoding, along with character entities denoted by the ampersand character.

      style_text

      Like
      plain_text
      , with physical-and content-based style tags allowed.

      15.6 Tricks with Windows

      A.2 The Grammar

      and Frames

      -->

Other books

Running Dark by Joseph Heywood
Brendon by Nicole Edwards
The Labyrinth Makers by Anthony Price
The Surgeon's Surprise Twins by Jacqueline Diamond
Shaka II by Mike Resnick
Smooth Sailing by Susan X Meagher
Dog Lived (and So Will I) by Rhyne, Teresa J.
Taking a Chance by Eviant