Annotation of Amaya/amaya/HTML.trans, revision 1.6

1.1       cvs         1: ! Use of the file HTML.trans
                      2: !!!!!!!!!!!!!!!!!!!!!!!!!!!!
                      3: ! This file can be edited during an Amaya session. It will be 
                      4: ! dynamically parsed when the transformation tool is required by
1.2       cvs         5: ! the editor. So new transformations can be added while editing.
1.1       cvs         6: !
                      7: ! Syntax of the transformation language for Amaya
                      8: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                      9: !
                     10: ! comments begin with !
                     11: !
                     12: ! This file can be edited during an Amaya session. It will be 
                     13: ! dynamically parsed when the transformation tool is required by
1.2       cvs        14: ! the editor. So new transformations can be added while editing.
1.1       cvs        15: !
                     16: ! A tranformation rule has three parts : 
                     17: !     - a name terminated by a colon ":"
                     18: !     - a source pattern terminated by a semi-colon ";"
                     19: !     - and a list of rules between braces "{" "}", each one
1.2       cvs        20: !           terminated by a semi-colon ";"
1.1       cvs        21: !
                     22: ! The name will appear in the transform menu.
                     23: !
                     24: ! The pattern gives of a specific organization of the elements
                     25: ! to be transformed: it contains HTML tags and SGML-like syntax
                     26: ! for the composition operators:
                     27: !     | for choice
                     28: !     , for sibling
                     29: !     + for sequence
                     30: !     ? for option
                     31: !     ( ) for grouping nodes
                     32: ! The braces "{" "}" define the content of a node.
                     33: ! The symbol "*" is a token that matches any element type
                     34: ! It is possible to rename a tag by preceeding it with a name
                     35: ! followed by a colon ":"
                     36: !
                     37: ! A rule expresses transformations to be applied to the elements 
                     38: ! identified in the pattern.
                     39: ! A rule has two parts separated by the symbol ">":
                     40: !     - a source tag
                     41: !     - and a target tag list. This list is itself divided into
                     42: !       two parts separated by a colon":": 
                     43: !         * the generation location path
                     44: !         * and the list of tags to be generated
                     45: ! The dot symbol "." is used for descending in the tree structure.
                     46: ! if the special token star "*" ends the list of tags to be 
                     47: ! generated, the source elment tag is not changed but this element
                     48: ! can be moved in a different place in the destination. 
                     49: 
                     50: 
                     51: ! Transformation rules 
                     52: !!!!!!!!!!!!!!!!!!!!!!
                     53: 
                     54: !between lists
                     55: !!!!!!!!!!!!!!
                     56: 
                     57: Definition list:*{(LI{(P|list:*{(li2:LI)+})+})+};
                     58:        {
                     59:        P > DL:DT;
                     60:        list > DL:DD;
                     61:        li2 > DL.DD:;
                     62:        }
                     63: 
                     64: Bulleted list:(DL{(DT|DD{(*)+})+})+;
                     65:        {
                     66:        DT > UL:LI.P;
                     67:        * > UL.LI.UL:LI.*;
                     68:        }
                     69: 
                     70: Numbered list:(DL{(DT|DD{(*)+})+})+;
                     71:        {
                     72:        DT > OL:LI.P;
                     73:        * > OL.LI.OL:LI.*;
                     74:        }
                     75: 
                     76: Remove DL:(DL{(DT|DD{(*)+})+})+;
                     77:        {
                     78:         DT > :P.STRONG;
                     79:         * > :*;
                     80:        }
                     81: 
                     82: !flattering headings 
                     83: !!!!!!!!!!!!!!!!!!!!
                     84: 
                     85: Paragraphs: 
                     86: (H1|H2|H3|H4|H5|H6|*{(LI{(il:*)+})+}),(H1|H2|H3|H4|H5|H6|P|*{(LI{(il:*)+})+})+;
                     87:        { 
                     88:        H1 > :P;
                     89:        H2 > :P;
                     90:        H3 > :P;
                     91:        H4 > :P;
                     92:        H5 > :P;
                     93:        H6 > :P;
                     94:        P > :P;
                     95:        il > :P;
                     96:        }
                     97: 
                     98: ! Preformatted to/from paragraphs
                     99: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    100: 
                    101: Preformatted: P+;
                    102:        {
                    103:        P>:PRE;
                    104:        }
                    105: 
                    106: Paragraph: PRE+;
                    107:        {
                    108:        PRE>:P;
                    109:        }
                    110: 
                    111: 
                    112: 
                    113: 
                    114: !Tables to/from lists
                    115: !!!!!!!!!!!!!!!!!!!!
                    116: 
                    117: Table: *{(lev1:LI{?(*{(lev2:LI)+}|elem:*)+})+};
                    118:        {
                    119:        lev1 > <TABLE border=1>:TR;
                    120:        elem > TABLE.TR:TD.*;
                    121:        lev2 > TABLE.TR:TD;
                    122:        }
                    123: 
                    124: Table: DL{(DT|DD)+};
                    125:        {
                    126:        DT > <TABLE border=1>.TBODY:TR.TD;
                    127:        DD > TABLE.TBODY.TR:TD;
                    128:        }
                    129: 
                    130: Numbered list:TABLE{?CAPTION,?THEAD{(t:TR{(chead:TD|chead2:TH)+})+},(TBODY{(TR{TD,?(TD2:TD)+})+})+,?TFOOT{(tf:TR{(cfoot:TD|cfoot2:TH)+})+}};
                    131:        {
                    132:        CAPTION > :OL.LI.STRONG;
                    133:        chead > OL:LI;
                    134:        chead2> OL:LI;
                    135:        TBODY > :OL;
                    136:        TR > OL:LI;
                    137:        TD > OL.LI:;
                    138:        TD2 >OL.LI.UL:LI;
                    139:        tf > :OL;       
                    140:        cfoot > OL:LI;
                    141:        cfoot2 > OL:LI;
                    142:        }
                    143: 
                    144: Bulleted list:TABLE{?CAPTION,?THEAD{(t:TR{(chead:TD|chead2:TH)+})+},TBODY{(TR{TD,?(TD2:TD)+})+},?TFOOT{(tf:TR{(cfoot:TD|cfoot2:TH)+})+}};
                    145:        {
                    146:        CAPTION > :UL.LI.STRONG;
                    147:        chead > UL:LI;
                    148:        chead2> UL:LI;
                    149:        TBODY > :UL;
                    150:        TR > UL:LI;
                    151:        TD > UL.LI:;
                    152:        TD2 >UL.LI.UL:LI;
                    153:        tf > :UL;       
                    154:        cfoot > UL:LI;
                    155:        cfoot2 > UL:LI;
                    156:        }
                    157: 
                    158: ! List transformations
                    159: !!!!!!!!!!!!!!!!!!!!!!
                    160: 
                    161: Remove one level: *{(LI{(cont:*)+})+};
                    162:        {
                    163:        cont > :*;
                    164:        }
                    165: 
                    166: Remove two levels: *{(LI{(*{?(LI{(Lev2:*)+})+})+})+};
                    167:        {
                    168:        Lev2 > :*;
                    169:        }
                    170: 
                    171: Merge Items: LI,(LI2:LI)+;
                    172:        {
                    173:        LI > LI:;
                    174:        LI2 > LI:;
                    175:        }
                    176: 
                    177: Split Items: (LI{a:*,(b:*)+})+;
                    178:        {
                    179:        a > :LI.*;
                    180:        b > :LI.*;
                    181:        }
                    182: 
                    183: Merge Lists: UL{LI+},(UL{LI+})+;
                    184:        {
                    185:        LI > UL:LI;
                    186:        }
                    187: 
                    188: Merge Lists: OL{LI+},(OL{LI+})+;
                    189:        {
                    190:        LI > OL:LI;
                    191:        }
                    192: 
                    193: Merge Lists: DL{(DT|DD)+},(DL{(DT|DD)+})+;
                    194:        {
                    195:        DT > DL:DT;
                    196:        DD > DL:DD;
                    197:        }
                    198: 
                    199: ! Forms to/from elements
                    200: !!!!!!!!!!!!!!!!!!!!!!!!
                    201: 
                    202: Form: *+;
                    203:        {
                    204:        *>Form:*;
                    205:        }
                    206: 
                    207: Remove Form: FORM{*+};
                    208:        {
                    209:        *>:*;
                    210:        }
                    211: 
                    212: ! Lists to/from elements
                    213: !!!!!!!!!!!!!!!!!!!!!!!!
                    214: 
                    215: Bulleted list: (P|UL|OL|MENU|DIR|PRE|FORM)+;
                    216:        {
                    217:         P > UL:LI.P;
                    218:         UL> UL.LI:UL;
                    219:         OL> UL.LI:OL;
                    220:         MENU> UL:LI.MENU;
                    221:         DIR> UL:LI.DIR;
                    222:         PRE> UL:LI.PRE;
                    223:         FORM> UL:LI.FORM;
                    224:         }
                    225: 
                    226: Numbered list:(P|UL|OL|MENU|DIR|PRE|FORM)+;
                    227:           {
                    228:         P > OL:LI.P;
                    229:         UL> OL.LI:UL;
                    230:         OL> OL.LI:OL;
                    231:         MENU> OL:LI.MENU;
                    232:         DIR> OL:LI.DIR;
                    233:         PRE> OL:LI.PRE;
                    234:         FORM> OL:LI.FORM;
                    235:         }
                    236: 
                    237: ! Tables to/from elements
                    238: !!!!!!!!!!!!!!!!!!!!!!!!!
                    239: 
                    240: !Table: (H:H1|H:H2|H:H3|H:H4|H:H5|H:H6|P),(H:H1|H:H2|H:H3|H:H4|H:H5|H:H6|*)+;
                    241: !      {
                    242: !      P> <TABLE border=1>.TR.TD:P;
                    243: !      H> <TABLE border=1>:TR.TD.*;
                    244: !      *> <TABLE border=1>.TR:TD.*;
                    245: !      }
                    246: 
                    247: 
                    248: Vertical Table: *,*+;
                    249:        {
                    250:        *><TABLE border=1>:TR.TD.*;
                    251:        }
                    252: 
                    253: Horizontal Table : *,*+;
                    254:        {
                    255:        *><TABLE border=1>.TR:TD.*;
                    256:        }
                    257: 
                    258: Remove Table:TABLE{?CAPTION,?(body:*{(TR{(TD{(?cell_content:*)+}|TH{(?cell_content:*)+})+})+})+};
                    259:        {
                    260:        CAPTION>H3;
                    261:        cell_content>:*;
                    262:        }
                    263: 
                    264: Transpose Table:TABLE{TBODY{TR{(TD)+}|(TR{td2:TD})+}};
                    265:        {
                    266:        TD><TABLE BORDER=1>:TR.TD;
                    267:        td2><TABLE BORDER=1>.TR:TD;
                    268:        }
                    269: 
                    270: 
                    271: !headings to/from definitions
                    272: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    273: 
                    274: Definition list:(H1,?HR,?(level1:*)+,?(H2,?(level2:*)+,?((H3|H4|H5|H6),(level3:*)+)+)+)+;
                    275:        {
                    276:        H1 > DL:DT;
                    277:        level1>DL.DD:*;
                    278:        H2 > DL.DD:DL.DT ;
                    279:        level2 > DL.DD.DL.DD:*;
                    280:        H3 > DL.DD.DL.DD:DL.DT ;
                    281:        H4 > DL.DD.DL.DD:DL.DT ;
                    282:        H5 > DL.DD.DL.DD:DL.DT ;
                    283:        H6 > DL.DD.DL.DD:DL.DT ;
                    284:        level3 > DL.DD.DL.DD.DL.DD:*;
                    285:        }
                    286: 
                    287: Definition list:(H2,?HR,?(level1:*)+,(H3,?(level2:*)+,((H4|H5|H6),(level3:*)+)+)+)+;
                    288:        {
                    289:        H2 > DL:DT;
                    290:        level1>DL.DD:*;
                    291:        H3 > DL.DD:DL.DT ;
                    292:        level2 > DL.DD.DL.DD:*;
                    293:        H4 > DL.DD.DL.DD:DL.DT ;
                    294:        H5 > DL.DD.DL.DD:DL.DT ;
                    295:        H6 > DL.DD.DL.DD:DL.DT ;
                    296:        level3 > DL.DD.DL.DD.DL.DD:*;
                    297:        }
                    298: 
                    299: 
                    300: 
                    301: Definition list:(H3,?HR,?(level1:*)+,?(H4,?(level2:*)+,((H5|H6),(level3:*)+)+)+)+;
                    302:        {
                    303:        H3 > DL:DT;
                    304:        level1>DL.DD:*;
                    305:        H4 > DL.DD:DL.DT ;
                    306:        level2 > DL.DD.DL.DD:*;
                    307:        H5 > DL.DD.DL.DD:DL.DT ;
                    308:        H6 > DL.DD.DL.DD:DL.DT ;
                    309:        level3 > DL.DD.DL.DD.DL.DD:*;
                    310:        }
                    311: 
                    312: Multi level Definition list:(H4,?HR,?(level1:*)+,(H5,?(level2:*)+,((H6)+,(level3:*)+)+)+)+;
                    313:        {
                    314:        H4 > DL:DT;
                    315:        level1>DL.DD:*;
                    316:        H5 > DL.DD:DL.DT ;
                    317:        level2 > DL.DD.DL.DD:*;
                    318:        H6 > DL.DD.DL.DD:DL.DT ;
                    319:        level3 > DL.DD.DL.DD.DL.DD:*;
                    320:        }
                    321: 
                    322: Definition list:(H1,?HR,?(level1:*)+,?((H2|H3|H4|H5|H6),(level2:*)+)+)+;
                    323:        {
                    324:        H1 > DL:DT;
                    325:        level1 > DL.DD:*;
                    326:        H2 > DL.DD:DL.DT ;
                    327:        H3 > DL.DD:DL.DT ;
                    328:        H4 > DL.DD:DL.DT ;
                    329:        H5 > DL.DD:DL.DT ;
                    330:        H6 > DL.DD:DL.DT ;
                    331:        level2 > DL.DD.DL.DD:*;
                    332:        }
                    333: 
                    334: Definition list:(H2,?HR,?(level1:*)+,?((H3|H4|H5|H6),(level2:*)+)+)+;
                    335:        {
                    336:        H2 > DL:DT;
                    337:        level1>DL.DD:*;
                    338:        H3 > DL.DD:DL.DT ;
                    339:        H4 > DL.DD:DL.DT ;
                    340:        H5 > DL.DD:DL.DT ;
                    341:        H6 > DL.DD:DL.DT ;
                    342:        level2 > DL.DD.DL.DD:*;
                    343:        }
                    344: 
                    345: Definition list:(H3,?HR,?(level1:*)+,?((H4|H5|H6),(level2:*)+)+)+;
                    346:        {
                    347:        H3 > DL:DT;
                    348:        level1>DL.DD:*;
                    349:        H4 > DL.DD:DL.DT ;
                    350:        H5 > DL.DD:DL.DT ;
                    351:        H6 > DL.DD:DL.DT ;
                    352:        level2 > DL.DD.DL.DD:*;
                    353:        }
                    354: 
                    355: Definition list:(H4,?HR,?(level1:*)+,?((H5|H6),(level2:*)+)+)+;
                    356:        {
                    357:        H4 > DL:DT;
                    358:        level1>DL.DD:*;
                    359:        H5 > DL.DD:DL.DT ;
                    360:        H6 > DL.DD:DL.DT ;
                    361:        level2 > DL.DD.DL.DD:*;
                    362:        }
                    363: 
                    364: 
                    365: 
                    366: Headings H1:(DL{(dt1:DT|DD{(DL{(dt2:DT|DD{(DL{(dt3:DT|DD{content:*})+}|content:*)+})+}|content:*)+})+}|HR)+;
                    367:        {
                    368:        dt1 > :H1;
                    369:        dt2 > :H2;
                    370:        dt3 > :H3;
                    371:        content > :*;
                    372:        }
                    373: 
                    374: Headings H2:(DL{(dt1:DT|DD{(DL{(dt2:DT|DD{(DL{(dt3:DT|DD{content:*})+}|content:*)+})+}|content:*)+})+}|HR)+;
                    375:        {
                    376:        dt1 > :H2;
                    377:        dt2 > :H3;
                    378:        dt3 > :H4;
                    379:        content > :*;
                    380:        }
                    381: 
                    382: 
                    383: Headings H3:(DL{(dt1:DT|DD{(DL{(dt2:DT|DD{(DL{(dt3:DT|DD{content:*})+}|content:*)+})+}|content:*)+})+}|HR)+;
                    384:        {
                    385:        dt1 > :H3;
                    386:        dt2 > :H4;
                    387:        dt3 > :H5;
                    388:        content > :*;
                    389:        }
                    390: 
                    391: Definition list: P{STRONG|B},(DL{DD+}|p2:P+);
                    392:        {
                    393:        STRONG > DL:DT;
                    394:        B > DL:DT;
                    395:        DD > DL:*;
                    396:        p2 > DL.DD:*;
                    397:        }
                    398: 
                    399: Remove Div: (DIV{*+})+;
                    400:        {
1.3       cvs       401:         * > :*;
                    402:        }
                    403: 
                    404: Remove P level: P{IMG};
                    405:        {
                    406:         IMG > :*;
1.1       cvs       407:        }
                    408: 
                    409: Remove BlockQuote: (BLOCKQUOTE{*+})+;
                    410:        {
                    411:        * > :*;
                    412:        }
                    413: 
                    414: Remove tag FONT: FONT{*+};
                    415:        {
                    416:        * > :*;
                    417:        }
1.4       cvs       418: 
1.5       cvs       419: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    420: ! Transformation for maths
                    421: 
1.6     ! cvs       422: !surround an element with a root
        !           423: root : *;
        !           424:        {
        !           425:        *>MROOT:*;
        !           426:        *>MROOT:MTEXT." ";
        !           427:        }
        !           428: 
1.5       cvs       429: !surround an element with a square root
                    430: square root: *;
                    431:         {
                    432:         *> MSQRT:*;
                    433:         }
                    434: 
                    435: !surround a set of elements with a square root
                    436: square root: *+;
                    437:         {
                    438:         *> MSQRT.MROW:*;
                    439:         }
                    440: 
                    441: ! removes a square root
                    442: remove sqrt: MSQRT{*+};
                    443:         {
                    444:         *> :*;
                    445:         }
                    446: 
                    447: !surround element(s) with a fraction
                    448: fraction: (num:*,den:*) | MROW{num:*,den:*} | *;
                    449:         {
                    450:         num > MFRAC:*;
                    451:         den > MFRAC:*;
                    452:         *> MFRAC:*;
                    453:         *> MFRAC:MTEXT." ";
                    454:         }
                    455: 
                    456: !removes a fraction level, replacing it by mrow
                    457: remove frac: MFRAC{(num:*,den:*)|numalone:*};
                    458:         {
                    459:         num > MROW:*;
                    460:         den > MROW:*;
                    461:         numalone > :*;
                    462:         }
                    463: 
1.6     ! cvs       464: 
1.5       cvs       465: !changes MSUB in MSUP
                    466: superscript:MSUB;
1.4       cvs       467:        {
1.5       cvs       468:        MSUB > MSUP;
1.4       cvs       469:        }
1.5       cvs       470: 
                    471: !changes MSUP in MSUB
                    472: subscript:MSUP;
                    473:        {
                    474:        MSUP > MSUB;
                    475:        }
                    476: 
                    477: !changes MSUB or MSUP in MSUBSUP
                    478: subsup:MSUB{base:*,sub:*} | MSUP{base:*,sup:*};
                    479:        {
                    480:        base > MSUBSUP:*;
                    481:        sup > MSUBSUP:MTEXT." ";
                    482:        sup > MSUBSUP:*;
                    483:        sub > MSUBSUP:*;
                    484:        sub > MSUBSUP:MTEXT." ";
                    485:        }
                    486: 
1.6     ! cvs       487: !surroud element with a subsup
        !           488: add subsup:*;
        !           489:        {
        !           490:        * > MSUBSUP:*;
        !           491:        * > MSUBSUP:MTEXT." ";
        !           492:        * > MSUBSUP:MTEXT." ";
        !           493:        }
        !           494: 
        !           495: !surroud element with a sub
        !           496: add subscript:*;
        !           497:        {
        !           498:        * > MSUB:*;
        !           499:        * > MSUB:MTEXT." ";
        !           500:        }
        !           501: 
        !           502: !surroud element with a sup
        !           503: add superscript:*;
        !           504:        {
        !           505:        * > MSUP:*;
        !           506:        * > MSUP:MTEXT." ";
        !           507:        }
        !           508: 
        !           509: ! removes a Row level
        !           510: remove row: MROW{*+};
        !           511:         {
        !           512:         *> :*;
        !           513:         }
        !           514: 
        !           515: 
1.5       cvs       516: !does not work!!!
1.6     ! cvs       517: !parenthesise: row:MROW | *;
1.5       cvs       518: !        {
                    519: !        *>:MF."(";
                    520: !        *>:*;
                    521: !        *>:MF.")";
                    522: !        }
                    523: 
                    524: 
                    525: 

Webmaster