# $Id$
#
# >>Title::     HTML Tuning
#
# >>Copyright::
# Copyright (c) 1992-1996, Ian Clatworthy (ianc@mincom.com).
# You may distribute under the terms specified in the LICENSE file.
#
# >>History::
# -----------------------------------------------------------------------
# Date      Who     Change
# 26-Apr-99 ianc    Added HTML_OLD_FOOTERS
# 29-Feb-96 ianc    SDF 2.000
# -----------------------------------------------------------------------
#
# >>Purpose::
# The {{stdlib/html.sdn}} module defines [[SDF]] configuration details for
# generating [[HTML]] files.
#
# >>Description::
#
# >>Limitations::
#

# Make HTML a restricted family of variables
!restrict 'HTML'

# Declare HTML document variables
!block variables; family="HTML"; export
Name                        Type            Rule
TITLE                       string
BG_IMAGE                    string
BG_FIXED                    boolean
BG_COLOR                    string
TEXT_COLOR                  string
LINK_COLOR                  string
VLINK_COLOR                 string
CHANGED_COLOR               string
PRE_HEADER                  string
POST_FOOTER                 string

# Section separator stuff
SECTION_LEVEL               integer
PRE_SECTION                 string

# header/footer URLs
URL_HOME                    string
URL_CATALOG                 string
URL_SEARCH                  string

# Navigation text
TEXT_CONTENTS               string
TEXT_PARENT                 string
TEXT_PREVIOUS               string
TEXT_NEXT                   string
TEXT_HOME                   string
TEXT_CATALOG                string
TEXT_SEARCH                 string

# Stuff for building topics
TOPIC                       string
SDT                         string
TOPIC_PATTERN               string

# For now, this is the way to tune table unit widths
TABLE_UNIT                  number
!endblock

# Declare HTML paragraph attributes
!block paraattrs; family="html"
Name                Type            Rule
!endblock

# Declare HTML phrase attributes
!block phraseattrs; family="html"
Name            Type            Rule
!endblock

# Declare HTML table parameters
!block tableparams; family="html"
Name            Type            Rule
!endblock

# Declare HTML row parameters
!block rowparams; family="html"
Name            Type            Rule
!endblock

# Declare HTML cell parameters
!block cellparams; family="html"
Name                Type            Rule
!endblock

# Define paragraph styles (default is P if not known and not below)
!block parastyles
Name        To                      Attributes
Line        HR
PB          HR
Addr        ADDRESS
Sign        ADDRESS
TITLE       TITLE
!endblock

# Mapping of phrase styles (default is Name if not below)
# The SDF_* one will be ignored - this seems better than "UNKNOWN"
!block phrasestyles
Name    To
A       SDF_ASIS
B       B
I       I
N       SDF_NORMAL
U       U
EX      TT
FILE    TT
#JUMP    A
1       EM
2       STRONG
3       =U
SUB     SUB
SUP     SUP
S       SDF_ASIS
ST      STRONG
Y       =ST
!endblock


# Mapping tables for attribute/parameter values
!block script
%html_align = (
    '1',    'Justify',
    'Full', 'Justify',
);
!endblock

# Mapping of paragraph attributes
!block paraattrs
Name        To          Map         Attributes
align       align       %html_align
!endblock

# Mapping of phrase attributes
!block phraseattrs
Name        To          Map         Attributes
family
size
bold
italics
underline
changed
color
!endblock

# Mapping of cell parameters
!block cellparams
Name        To          Map         Parameters
!endblock

## Set the default navigation text strings
#!define HTML_TEXT_CONTENTS      "Contents"
#!define HTML_TEXT_PARENT        "Parent Topic"
#!define HTML_TEXT_PREVIOUS      "Previous Topic"
#!define HTML_TEXT_NEXT          "Next Topic"
#!define HTML_TEXT_HOME          "Home"
#!define HTML_TEXT_CATALOG       "Catalog"
#!define HTML_TEXT_SEARCH        "Search"

## Set the default color for changed text
!default HTML_CHANGED_COLOR "teal"

# Setup the default section separator stuff
!default HTML_SECTION_LEVEL $var{'HTML_SUBTOPICS_MODE'} ? 2 : 1
!if HTMLDOC
    !macro HTML_PRE_SECTION
    !endmacro
!else
    !macro HTML_PRE_SECTION
    Line:
    !endmacro
!endif

# Prepend a separator before each section (the notoc stuff ensures
# that this rule isn't applied to the H1 generated by build_title)
!on paragraph '[HAP]\d';; \
    $my_style = $var{'HTML_SUBTOPICS_MODE'} ? $attr{'orig_style'} : $style; \
    if ($var{'DOC_TOC'} && substr($my_style, 1) <= $var{'HTML_SECTION_LEVEL'}) { \
        &PrependText('!HTML_PRE_SECTION') unless $attr{'notoc'}; \
    }

# In topics mode, special processing is needed on headings
!if $var{'HTML_TOPICS_MODE'} || $var{'HTML_SUBTOPICS_MODE'}
    !on paragraph '[HAP]\d';; &HtmlTopicsModeHeading
!endif

# ignore Page-breaks in html
!on paragraph 'PB';; $style = 'N'

# Default build_title output
!macro build_html_cover
!if $var{'OPT_DRIVER'} eq 'html'
        !div title
        !default DOC_TOC 2
        !default DOC_HTML_LOGO  $var{'DOC_LOGO'}
        !if DOC_HTML_LOGO
            !default DOC_HTML_LOGO_BASE  $var{'DOC_LOGO_BASE'}
            !import DOC_HTML_LOGO; align=Right; base=$var{'DOC_HTML_LOGO_BASE'}
            P1[notoc; class='doc-title'] [[DOC_TITLE]]
        !else
            P1[notoc; class='doc-title'] [[DOC_TITLE]]
        !endif
        !if $var{'OPT_STYLE'} eq 'paper'
            #Sign: [[DOC_STATUS]]
        !elsif DOC_STATUS
            Sign: {{A[class='doc-id'][[DOC_ID]]}} {{A[class='doc-status']([[DOC_STATUS]])}}
        !elsif DOC_ID
            Sign: {{A[class='doc-id'][[DOC_ID]]}}
        !endif
        Sign[class='doc-author'] [[join(", ", grep(/\w/, &Var('DOC_AUTHOR'), &Var('DOC_AUTHOR2'), &Var('DOC_AUTHOR3')))]]
        Sign[class='doc-modified'] [[DATE:DOC_MODIFIED]]
        !clear
        !enddiv

        # Setup the HTML title
        !HTML_BUILD_TITLE

        # This is no longer required now that the title is put in it's own div
        ## Mark the contents so we know where it is in topics mode
        #!block inline; target='html'
#<!-- TOC -->
#<!-- ENDTOC -->
        #!endblock
!else
    # This is used for HTML documents generated via Frame
	dName: [[DOC_TITLE]]
	dStat: [[DOC_ID]] ([[DOC_STATUS]])
	dAuth: [[join(", ", grep(/\w/, @variable{'DOC_AUTHOR', 'DOC_AUTHOR2', 'DOC_AUTHOR3'}))]]
!endif
!endmacro

# Macro for building the title of the document and/or topic
!macro HTML_BUILD_TITLE
    !if HTML_SUBTOPICS_MODE
        !if DOC_PROJECT
            !define HTML_TITLE "$var{'DOC_PROJECT'}: $var{'HTML_MAIN_TITLE'}: $var{'DOC_TITLE'}"
        !else
            !define HTML_TITLE "$var{'HTML_MAIN_TITLE'}: $var{'DOC_TITLE'}"
        !endif
    !elsif DOC_PROJECT
        !define HTML_TITLE "$var{'DOC_PROJECT'}: $var{'DOC_TITLE'}"
    !else
        !define HTML_TITLE DOC_TITLE
    !endif
!endmacro


# Subroutine to build the main document navigation line
!block script
sub _html_mdnav {
    local($mdn);

    $mdn .= '{{A[jump=HTML_URL_HOME] [[HTML_TEXT_HOME]]}} | ' if $var{'HTML_URL_HOME'};
    $mdn .= '{{A[jump=HTML_URL_CATALOG] [[HTML_TEXT_CATALOG]]}} | ' if $var{'HTML_URL_CATALOG'};
    $mdn .= '{{A[jump=HTML_URL_SEARCH] [[HTML_TEXT_SEARCH]]}} | ' if $var{'HTML_URL_SEARCH'};
    $mdn =~ s/ \| $//;
    return $mdn;
}
!endblock

# Build the default header and footer for the main document
!macro HTML_HEADER
    !HTML_NAVIGATE
!endmacro
!macro HTML_FOOTER
    !HTML_NAVIGATE
!endmacro
!macro HTML_NAVIGATE
    !if HTML_TOPICS_MODE
        !HTML_TOPIC_NAVIGATE
    !else
        !div navigate
        !define _HTML_NAV &_html_mdnav
        !if _HTML_NAV
            [align='Center'] [[_HTML_NAV]]
        !endif
        !enddiv
    !endif
!endmacro

# Build the default header and footer for topics
!macro HTML_TOPIC_HEADER
    !default DOC_TOPIC_LOGO $var{'DOC_LOGO'}
    !if DOC_TOPIC_LOGO
        !default DOC_TOPIC_LOGO_BASE  $var{'DOC_LOGO_BASE'}
        !import DOC_TOPIC_LOGO; align="Right"; base=$var{'DOC_TOPIC_LOGO_BASE'}
        !HTML_TOPIC_NAVIGATE
        !clear "Right"
    !else
        !HTML_TOPIC_NAVIGATE
    !endif
!endmacro
!macro HTML_TOPIC_FOOTER
    !HTML_TOPIC_NAVIGATE
!endmacro
!macro HTML_TOPIC_NAVIGATE
!div navigate
    !block script
    if ($var{'HTML_TOPICS_MODE'}) {
        $_next = $topics[0] . ".html";
        $_prev = $topics[$#topics] . ".html";
    }
    else {
        $_base = $var{'HTML_TOPIC'};
        $_next = $topic_next{$_base} ? $topic_next{$_base} . ".html" : '';
        $_prev = $topic_prev{$_base} ? $topic_prev{$_base} . ".html" : '';
        $_up   = $topic_up{$_base} ? $topic_up{$_base} . ".html" : '';
    }

    # Build the second navigation line, if any
    $_nav2 = &_html_mdnav;
    if ($_nav2) {
        $_nav2 = "{{CHAR:nl}}" . $_nav2;
    }
    !endblock
    
    !if HTML_TOPICS_MODE
        [align='Center']
        {{A[jump=$_prev] [[HTML_TEXT_PREVIOUS]]}}
        | {{A[jump=$_next] [[HTML_TEXT_NEXT]]}}
        [[$_nav2]]
    !else
        [align='Center']
        {{A[jump=HTML_URL_CONTENTS] [[HTML_TEXT_CONTENTS]]}}
        | {{A[jump=$_up] [[HTML_TEXT_PARENT]]}}
        | {{A[jump=$_prev] [[HTML_TEXT_PREVIOUS]]}}
        | {{A[jump=$_next] [[HTML_TEXT_NEXT]]}}
        [[$_nav2]]
    !endif
!enddiv
!endmacro

# Use old footers, if requested
!if HTML_OLD_FOOTERS
    !macro HTML_FOOTER
        !HTML_PRE_SECTION
        !HTML_NAVIGATE
    !endmacro
    !macro HTML_TOPIC_FOOTER
        !HTML_PRE_SECTION
        !HTML_TOPIC_NAVIGATE
    !endmacro
!endif
