# SGML markup by Patrick L. McGillan
# feel free to change and send changes to package maintainer
# basic document

sub SGML_Base {
    InsertString "<!doctype debiandoc system>"; LineNew;
    InsertString "<debiandoc>"; LineNew;
    2:MoveRight; InsertString "<book>"; LineNew;
    2:MoveRight; InsertString "<titlepag>"; LineNew;
    2:MoveRight; InsertString "<title></title>"; LineNew;
    2:MoveRight; InsertString "<author>"; LineNew;
    2:MoveRight; InsertString "<name></name>"; LineNew;
    InsertString "<email></email>"; LineNew;
    2:MoveLeft; InsertString "</author>"; LineNew;
    2:MoveLeft; InsertString "<version><date></version>"; LineNew;
    InsertString "<abstract>"; LineNew;
    InsertString "</abstract>"; LineNew;
    InsertString "<copyright>"; LineNew;
    2:MoveRight; InsertString "<copyrightsummary>"; LineNew;
    InsertString "</copyrightsummary>"; LineNew;
    2:MoveLeft; InsertString "</copyright>"; LineNew;
    2:MoveLeft; InsertString "</titlepag>"; LineNew;
    InsertString "<toc>"; LineNew;
    InsertString "<chapt>"; LineNew;
    InsertString "</chapt>"; LineNew;
    2:MoveLeft; InsertString "</book>"; LineNew;
    2:MoveLeft; InsertString "</debiandoc>";
}

sub SGML_CH {
    InsertString "<chapt id=\"\">"; LineNew;
    InsertString "<heading></heading>"; LineNew;
    InsertString "<p>"; SavePos; LineNew;
    InsertString "</chapt>"; MoveSavedPos;
}

sub SGML_SE {
    InsertString "<sect>";
}

sub SGML_PA {
    InsertString "<p>";
}

sub SGML_MRF {
    InsertString "<manref name=\"\" section=\"\">";
}

sub SGML_EML {
    InsertString "<email>";
}

sub SGML_FTPS {
    InsertString "<ftpsite>";
}

sub SGML_FTPP {
    InsertString "<ftppath>";
}

sub SGML_HTPS {
    InsertString "<httpsite>";
}

sub SGML_HTPP {
    InsertString "<httppath>";
}

sub SGML_URL {
    InsertString "<url id=\"\" name=\"\">";
}

sub SGML_EX {
    MoveBlockStart; LineNew; InsertString "<example>"; LineNew;
    MoveBlockEnd; LineNew; InsertString "</example>"; BlockUnmark;
}

sub SGML_REF {
    MoveBlockStart; InsertString "<ref id=\"";
    MoveBlockEnd; InsertString "\">"; BlockUnmark;
}

sub SGML_BO {
    MoveBlockStart; InsertString "<strong>";
    MoveBlockEnd; InsertString "</strong>";
    4:MoveLeft; BlockUnmark;
}

sub SGML_IT {
    MoveBlockStart; InsertString "<em>";
    MoveBlockEnd; InsertString "</em>";
    4:MoveLeft; BlockUnmark;
}

sub SGML_TT {
    MoveBlockStart; InsertString "<tt>";
    MoveBlockEnd; InsertString "</tt>";
    4:MoveLeft; BlockUnmark;
}

sub SGML_VAR {
    InsertString "<var>";
}

sub SGML_PAK {
    InsertString "<package>";
}

sub SGML_PGN {
    InsertString "<program>";
}

sub SGML_FIL {
    InsertString "<file>";
}

sub SGML_ORD {
    InsertString "<list>"; LineNew;
    InsertString "<item>"; SavePos; LineNew;
    InsertString "</list>"; MoveSavedPos;
}

sub SGML_NUM {
    InsertString "<enumlist>"; LineNew;
    InsertString "<item>"; SavePos; LineNew;
    InsertString "</enumlist>"; MoveSavedPos;
}

sub SGML_TAG {
    InsertString "<taglist>"; LineNew;
    InsertString "<item>"; SavePos; LineNew;
    InsertString "</taglist>"; MoveSavedPos;
}


colorize SGML {
    SyntaxParser = 'SIMPLE';
    
    color {
        { 'Normal',     'Editor_Default' },
        { 'String',     'Lang_String' },
        { 'Comment',    'Lang_Comment' },
        { 'Command',    'Markup_Punctuation' },
        { 'Symbol',     'Markup_Symbol' },
        { 'Tag',        'Markup_Tag' },
        { 'Special',    'Markup_Special' },
    };

    keyword "Editor_Keywords" { # should be SGML 3.2 complete
        "ABSTRACT",
        "ARTICLE",
        "AUTHOR",
        "BF",
        "BOOK",
        "CHAPT",
        "CODE",
        "COPYRIGHT",
        "DATE",
        "DEBIANDOC",
        "DESCRIP",
        "DOCTYPE",
        "EM",
        "EMAIL",
        "ENUM",
        "ENUMLIST",
        "EXAMPLE",
        "FOOTNOTE",
        "FTPSITE",
        "FTPPATH",
        "HEADING",
        "HTMLURL",
        "HTTPSITE",
        "HTTPPATH",
        "IT",
        "ITEM",
        "ITEMIZE",
        "LABEL",
        "LIST",
        "MANREF",
        "NAME",
        "P",
        "PRGN",
        "PUBLIC",
        "QREF",
        "QUOTE",
        "REF",
        "SECT",
        "SECT1",
        "SECT2",
        "SECT3",
        "SECT4",
        "STRONG",
        "SYSTEM",
        "TAG",
        "TAGLIST",
        "TITLE",
        "TITLEPAG",
        "TOC",
        "TSCREEN",
        "TT",
        "URL",
        "VAR",
        "VERB",
        "VERSION",
    };
    keyword "Editor_Keywords2" {
        "COMPACT",
        "ID",
        "NAME",
        "SECTION",
    };

    h_state 0 { 'Normal' }
    h_trans { 4, '<', '<!--', 'Comment' }
    h_trans { 8, '<', '</', 'Command' }
    h_trans { 1, '<', '<', 'Command' }
    h_trans { 2, '<', '&', 'Symbol' }

    h_state 1 { 'Command' }
    h_trans { 0, '>', '>', 'Command' }
    h_trans { 0, '>', '<', 'Command' }
    h_trans { 0, '>', '/>', 'Command' }
    h_trans { 6, '<', '/', 'Command' }
    h_trans { 3, '<', '"', 'String' }
    h_wtype { -1, -1, -1, 'i', 'a-zA-Z0-9_\-' }

    h_state 2 { 'Symbol' }
    h_trans { 0, '>', ';', 'Symbol' }
    h_trans { 0, '-S', '#a-zA-Z0-9', 'Symbol' }

    h_state 3 { 'String' }
    h_trans { 1, '>', '"', 'String' }

    h_state 4 { 'Comment' }
    h_trans { 5, '>', '--', 'Comment' }

    h_state 5 { 'Special' }
    h_trans { 4, '>', '--', 'Comment' }
    h_trans { 0, '>', '>', 'Comment' }

    h_state 6 { 'Symbol' }
    h_trans { 7, '-', '//', 'Command' }
    h_trans { 0, '>', '/', 'Command' }
    h_trans { 0, '>', '>', 'Symbol' }
    h_trans { 7, '>', '</', 'Command' }
    h_trans { 1, '>', '<', 'Command' }

    h_state 7 { 'Command' }
    h_trans { 6, '>', '/', 'Command' }

    h_state 8 { 'Command' }
    h_trans { 0, '>', '>', 'Command' }
    h_trans { 3, '<', '"', 'String' }
    h_wtype { -1, -1, -1, 'i', 'a-zA-Z0-9_\-' }

}

mode SGML: PLAIN {
    FileNameRx          = /\.\c{SGML?}|{SGML?}$/;
    HilitOn             = 1;
    Colorizer           = "SGML";
    MultiLineHilit      = 1;
    AutoHilitParen      = 1;

    RoutineRegexp       = /\<[Hh]\d\>/;

    SaveFolds           = 2;      # save fold info at end of line
    CommentStart        = "<!--";
    CommentEnd          = "-->";
    WordWrap            = 2;
    RightMargin         = 85;
    AutoIndent          = 1;
    
    Insert              = 1;
    IndentMode          = "Plain";
    Trim                = 1;
}
