section.modes: Sections and paragraphs for (x)html

The module section.modes in the directory http://gloss.bham.ac.uk/mv/html/ of the gloss distribution and web pages contains the code for presenting sections, subsections, and so on, using standards-compliant HTML.

1 Synopsis

You typically use section.modes in your GLOSS (x)html file as follows.

section {
title[TITLE]
...
}

This defines a section, with a title (and automatically, a number) or a subsection of an existing section. The content, ..., can be anything allowed withing a div in HTML.

Other tags defined in section.modes are as follows.

para {
...
}

Defines a paragraph (which is a "div", the contents of which are one logical paragraph, possibly including enumerations and other elements that cannot be children of the HTML "p" tag).

abstract {
...
}

Defines a section to be used as an abstract.

bibliography {
...
}

Defines a section to be used as a bibliography or list of references.

unnumbered-section {
title[TITLE]
...
}

Defines a section in which titles will not be numbered.

section-level[VALUE]
section-number[VALUE]
next-subsection[VALUE]

Gives you the chance to set the sectioning parameters so that section numbering starts where you want it to.

title @id[NAME] [other attributes] [VALUE]

Gives the "<hN>" element containing the title id "NAME". Also puts any section number associated with this title in a <span> of id "NAME-number" and the title itself in a <span> of id "NAME-title". These can be used with the "copy" pseudoelement from the hyperref package. For this feature to work you must make the id the first attribute. Other attributes will be added to the "<hN>" element in the usual way.

2 The code

!declare-prefix @prefix[sec] @uri[http://gloss.bham.ac.uk/mv/html/section] {
!declare-prefix @prefix[xml] @uri[http://gloss.bham.ac.uk/mv/xml/xml] {
!declare-prefix @prefix[html] @uri[http://gloss.bham.ac.uk/mv/html/plain] {

Main parameters controlling section number:

These can be changed to give other effects, such as a web page that starts numbering at section 2, etc

!init-parameter @name[sec:section-level] @value[1]   ; level of current section, 1 = h1, 2 = h2 etc
!init-parameter @name[sec:section-number] @value[]   ; current section, used as prefix to subsections
!init-parameter @name[sec:next-subsection] @value[1] ; number of next subsection within this section
!init-parameter @name[sec:abstract-name] @value[Abstract] ; the name of any "abstract" section
!init-parameter @name[sec:bibliography-name] @value[References] ; the name of any "bibliography" section

Internal parameters:

!init-parameter @name[sec:in-paragraph] @value[]     ; internal parameter to say we are in a paragraph
!init-parameter @name[sec:in-head] @value[]          ; internal parameter to say we are in the head
!mode @name[sec:body-content] @template[html:body-content] @type[process]
  !hook @mode[html:body-content] @action[process]

The title pseudoelement generates a h<number> element with title and section number. Any attributes are given to the h<number> element.

  title
    !element @name[h$\{sec:section-level\}]
      !set-parameter @name[sec:id] @value[]
      !process-tokens @mode[sec:get-id] @parameters[share]
      !process-tokens @mode[xml:attribute-list]
      !attribute @name[class] [section-title]
      !if @test[$\{sec:next-subsection\}]
        !if @test[$\{sec:section-number\}]
          !element @name[span]
            !attribute @name[class] [section-number]
            !if @test[$\{sec:id\}] !attribute @name[id] [$\{sec:id\}-number]
            ${sec:section-number}
          !element @name[span]
            !attribute @name[class] [title-space]
            !literal[ ]
      !element @name[span]
        !attribute @name[class] [section-title]
        !if @test[$\{sec:id\}] !attribute @name[id] [$\{sec:id\}-title]
        !process-tokens @mode[html:body-content]
    !text &#x0A; 

The section-level pseudoelement gives the author a chance to (re)set the section-level parameter from the source document.

  section-level
    !process-tokens @mode[xml:process-attr]
      !set-parameter @name[xml:attr-param] @value[sec:section-level]

The section-number pseudoelement gives the author a chance to (re)set the section-number parameter from the source document.

  section-number
    !process-tokens @mode[xml:process-attr]
      !set-parameter @name[xml:attr-param] @value[sec:section-number] 

The next-subsection pseudoelement gives the author a chance to (re)set the next-subsection parameter from the source document.

  next-subsection
    !process-tokens @mode[xml:process-attr]
      !set-parameter @name[xml:attr-param] @value[sec:next-subsection] 

The abstract pseudoelement makes a div with an abstract.

  abstract
    !element @name[div] !attribute @name[class][abstract]
      !process-tokens @mode[xml:attribute-list]
      !element @name[h2] ${sec:abstract-name}
      !process-tokens @mode[html:body-content]
    !text &#x0A;

The bibliography pseudoelement makes a div with an bibliography.

  bibliography
    !element @name[div] !attribute @name[class][bibliography]
      !process-tokens @mode[xml:attribute-list]
      !element @name[h2] ${sec:bibliography-name}
      !process-tokens @mode[html:body-content]
    !text &#x0A;

The section pseudoelement makes a div with a subsection in which any title element in it will be numbered.

  section
    !process-tokens @mode[sec:do-section]
    !if @test[$\{sec:next-subsection\}] 
      !incr-parameter @name[sec:next-subsection]

The unnumbered-section pseudoelement makes a div with a subsection in which any title element in it will not be numbered.

  unnumbered-section
    !process-tokens @mode[sec:do-section] 
      ${sec:next-subsection}=""

The para pseudoelement makes a div which represents a semantic "paragraph" (that may have other content apart from just a <p> element).

  para
    !if @test[$\{sec:in-paragraph\}]
      !message[WARNING$: nested paragraph found[&#x0A;]]
    !element @name[div] !attribute @name[class][paragraph]
      !process-tokens @mode[xml:attribute-list]
      !process-tokens @mode[html:body-content] ${sec:in-paragraph}="true"
    !text &#x0A; 

The p pseudoelement is just like the HTML p except it is wrapped with a "div @class" if one wasn't already there. (TO DO: should we treat ul, ol and others similarly?).

  p
    !if @test[$\{sec:in-paragraph\}]
      !element @name[p]
        !process-tokens @mode[xml:attribute-list]
        !process-tokens @mode[html:body-content]
    !else  
      !element @name[div]
        !attribute @name[class][paragraph]
        !element @name[p]
          !process-tokens @mode[xml:attribute-list]
          !process-tokens @mode[html:body-content]
  !include @mode[html:body-content] @hook[process]

!mode @name[sec:do-section] @accept[] @type[process]
  !default
    !element @name[div] !attribute @name[class] [sec$\{sec:section-level\}]
      !process-tokens @mode[xml:attribute-list]
      !if @test[$\{sec:next-subsection\}]
        !if-not @test[$\{sec:section-level\}] @value[1]
          !set-parameter @name[sec:section-number] @value[$\{sec:section-number\}.$\{sec:next-subsection\}]
        !else
          !set-parameter @name[sec:section-number] @value[$\{sec:next-subsection\}]
        !set-parameter @name[sec:next-subsection] @value[1]
      !incr-parameter @name[sec:section-level]
      !process-tokens @mode[html:body-content]
    !text &#x0A; 
    !return

!mode @name[sec:get-id] @accept[@id] @type[process]
  !default
    !process-tokens @mode[xml:process-attr]
      !set-parameter @name[xml:attr-param] @value[sec:id]
    !export-parameter @name[sec:id]
    !attribute @name[id] [$\{sec:id\}]

}; !declare-prefix
}; !declare-prefix
}; !declare-prefix

This file is part of the GLOSS system, Copyright Richard Kaye http://gloss.bham.ac.uk/. Usage permitted under the GPL. No Warranty.

This page is copyright. Web page design and creation by GLOSS.