renderHTML.h


max21 Unternehmensgruppe
// used for HTML and Latex rendering in Helpdesk and WebPublisher
a1 = [[[[NSSWCOF completeFn] replace:@"IntarS 5.1" with:product] replace:@"000001" with:[_APP mandant]] componentsSeparatedByString:@"\n"];
[latexma removeAllObjects];
[lma removeAllObjects];
for(i1=0,j1=[a1 count];i1<j1;i1++){
    NSString *line = [[a1 oai:i1]stringWithoutWindowsShit];
    NSString *arg1,*arg2;
    if([line hasSecurePrefix:@"\\%"])continue;
    if([line hasSecurePrefix:@"\\h1"]){
#include "endLastRegion.h"
        arg1 = [line secureSubstringFromIndex:4];
        if(FILLED(arg1)){
            [lma addObject:[NSSWF @"<div class=HelpdeskH1>%@</div>",[arg1 htmlEscapedString]]];
            [latexma addObject:[NSSWF @"\\%@{%@}",[self section:gliederungsTiefe+1],[[arg1 stringWithoutLeadingWhiteSpace]latexEscapedString]]];
        }
        continue;
    }
    if([line hasSecurePrefix:@"\\h2"]){
#include "endLastRegion.h"
        arg1 = [line secureSubstringFromIndex:4];
        if(FILLED(arg1)){
            [lma addObject:[NSSWF @"<div class=HelpdeskH2>%@</div>",[arg1 htmlEscapedString]]];
            [latexma addObject:[NSSWF @"\\%@{%@}",[self section:gliederungsTiefe+2],[[arg1 stringWithoutLeadingWhiteSpace]latexEscapedString]]];
        }
        continue;
    }
    if([line hasSecurePrefix:@"\\text"]){
#include "endLastRegion.h"
        [lma addObject:@"<div class=HelpdeskText>"];
        if([line hasSecurePrefix:@"\\text*"]){
            arg1 = [line secureSubstringFromIndex:7];
            addBR = YES; // Zeilenumbrueche statt paragraphen bei newline
        }else{
            arg1 = [line secureSubstringFromIndex:6];
        }
        if(FILLED(arg1)){
            [lma addObject:[arg1 htmlEscapedString]];
            [latexma addObject:[[arg1 stringWithoutLeadingWhiteSpace] latexEscapedString]];
            [lma addObject:@"<br>"];
            if(addBR){
                [latexma addObject:@"\\\\"];
            }else{
                [latexma addObject:@"\\par"];
            }
        }
        inText = YES;
        continue;
    }
    if([line hasSecurePrefix:@"\\tt"]){
#include "endLastRegion.h"
        [lma addObject:@"<div class=HelpdeskTT>"];
        [latexma addObject:@"{\\footnotesize\\begin{lstlisting}"];
        arg1 = [line secureSubstringFromIndex:4];
        if(FILLED(arg1)){
            [lma addObject:[[arg1 htmlEscapedString]stringWithHTMLTabs]];
            [lma addObject:@"<br>"];
            [latexma addObject:[arg1 stringWithoutLeadingWhiteSpace]];
        }
        inTT = YES;
        continue;
    }
    if([line hasSecurePrefix:@"\\latex "]){ // latex-Code inline; z.B. \tiny \normalsize
        [latexma addObject:[line secureSubstringFromIndex:7]];
        continue;
    }
    if([line hasSecurePrefix:@"\\html "]){ // html-Code inline; 
        [latexma addObject:[line secureSubstringFromIndex:6]];
        continue;
    }
    if([line hasSecurePrefix:@"\\sbs"]){ // step by step
#include "endLastRegion.h"
        [lma addObject:@"<div class=HelpdeskSBS><ol>"];
        [latexma addObject:@"\\begin{enumerate}"];
        inOL = YES;
        continue;
    }
    if([line hasSecurePrefix:@"\\ul"]){ // unordered list
#include "endLastRegion.h"
        [lma addObject:@"<div class=HelpdeskUL><ul>"];
        [latexma addObject:@"\\begin{itemize}"];
        inUL = YES;
        continue;
    }
    if([line hasSecurePrefix:@"\\step "]){ // step by step
        if(!inOL && !inUL)continue;
        arg1 = [line secureSubstringFromIndex:6];
        if(FILLED(arg1)){
            if(inOL){
                [lma addObject:@"<li class=HelpdeskStep>"];
            }else{
                [lma addObject:@"<li class=HelpdeskLI>"];
            }
            [latexma addObject:[NSSWF @"\\item %@",[arg1 latexEscapedString]]];
            [lma addObject:[arg1 htmlEscapedString]];
        }
        continue;
    }
    if([line hasSecurePrefix:@"\\img"]){
        NSArray *a2 = [line componentsSeparatedByString:@"{"];
        NSString *imgPath,*arg2Html,*bild_fn;
        if([a2 count]!=3){
            LOGS(([NSSWF  @"Syntax-Error in %@ line %i:\n%@",completeFn,i,line]));
            continue;
        }
        arg1 = [[a2 oai:1]stringWithoutLastChar];
        imgPath = [NSSWF @"%@/Images/%@",basePath,arg1];
        if(![myFM fileExistsAtPath:imgPath]){
            LOGS(([NSSWF  @"Image not found in %@ line %i:\n%@",imgPath,i,line]));
            continue;
        }
        arg2 = [[a2 oai:2]stringWithoutLastChar];
        arg2Html = [arg2 htmlEscapedString];
        if(mit_bild_fn){
            bild_fn = [NSSWF @" (%@)",arg1];
        }else{
            bild_fn = @"";
        }
        [lma addObject:[NSSWF @"<div><img class=HelpdeskImg src=\"/%@/Images/%@\" alt=\"%@\" title=\"%@\"><br><span class=HelpdeskImgTitel>%@ %@</span><br><br></div>",targetPath,arg1,arg2Html,arg2Html,arg2Html,bild_fn]];
        [latexma addObject:@"\\begin{figure}[ht]"];
        [latexma addObject:@"\\centering"];
        [latexma addObject:[NSSWF @"\\includegraphics[width=12cm]{%@}",arg1]];
        [latexma addObject:[NSSWF @"\\caption{%@ %@}",[arg2 latexEscapedString],[bild_fn latexEscapedString]]];
        [latexma addObject:@"\\end{figure}"];
        continue;
    }
    if([line hasSecurePrefix:@"\\dl"]){
	// "download" wie \a aber url relativ zum Image-Directory
        NSArray *a2 = [line componentsSeparatedByString:@"{"];
        NSString *prevLine;
        if([a2 count]!=3){
            LOGS(([NSSWF  @"Syntax-Error in %@ line %i:\n%@",completeFn,i,line]));
            continue;
        }
        arg1 = [[a2 oai:1]stringWithoutLastChar]; // url relativ zu Image ohne fuehrendes /
        arg2 = [[a2 oai:2]stringWithoutLastChar]; // text
        prevLine = [lma lastObject];
        if([prevLine hasSecureSuffix:@"<br>"]){
            prevLine = [prevLine substringToIndex:[prevLine length] - 4]; // link auch im Text
            [lma removeLastObject];
            [lma addObject:prevLine];
        }
        [lma addObject:[NSSWF @"<a href=\"/%@/Images/%@\" target=\"extern\">%@</a>",targetPath,arg1,[arg2 htmlEscapedString]]];
        [latexma addObject:[NSSWF @"\\htmladdnormallink{/%@/Images/%@}{%@}",targetPath,[arg2 latexEscapedString],arg1]];
        continue;
    }
    if([line hasSecurePrefix:@"\\ai"]){ // anker internal
        NSArray *a2 = [line componentsSeparatedByString:@"{"];
        NSString *prevLine;
        if([a2 count]!=3){
            LOGS(([NSSWF  @"Syntax-Error in %@ line %i:\n%@",completeFn,i,line]));
            continue;
        }
        arg1 = [[a2 oai:1]stringWithoutLastChar]; // id
        arg2 = [[a2 oai:2]stringWithoutLastChar]; // text
        prevLine = [lma lastObject];
        if([prevLine hasSecureSuffix:@"<br>"]){
            prevLine = [prevLine substringToIndex:[prevLine length] - 4]; // link auch im Text
            [lma removeLastObject];
            [lma addObject:prevLine];
        }
        [lma addObject:line]; // kann erst aufgeloest werden, wenn IDs aller Seiten bekannt sind 
        continue;
    }
    if([line hasSecurePrefix:@"\\a"]){
        NSArray *a2 = [line componentsSeparatedByString:@"{"];
        NSString *prevLine;
        if([a2 count]!=3){
            LOGS(([NSSWF  @"Syntax-Error in %@ line %i:\n%@",completeFn,i,line]));
            continue;
        }
        arg1 = [[a2 oai:1]stringWithoutLastChar]; // url
        arg2 = [[a2 oai:2]stringWithoutLastChar]; // text
        prevLine = [lma lastObject];
        if([prevLine hasSecureSuffix:@"<br>"]){
            prevLine = [prevLine substringToIndex:[prevLine length] - 4]; // link auch im Text
            [lma removeLastObject];
            [lma addObject:prevLine];
        }
        [lma addObject:[NSSWF @"<a href=\"%@\" target=\"extern\">%@</a>",arg1,[arg2 htmlEscapedString]]];
        [latexma addObject:[NSSWF @"\\htmladdnormallink{%@}{%@}",[arg2 latexEscapedString],arg1]];
        continue;
    }
    if([line hasSecurePrefix:@"\\id"]){
        [eo tvfk([line secureSubstringFromIndex:4],@"internal_id")];
        continue;
    }
    if([line hasSecurePrefix:@"\\meta_title"]){
        [eo tvfk([line secureSubstringFromIndex:12],@"meta_title")];
        continue;
    }
    if([line hasSecurePrefix:@"\\meta_description"]){
        [eo tvfk([line secureSubstringFromIndex:18],@"meta_description")];
        continue;
    }
    if([line hasSecurePrefix:@"\\meta_keywords"]){
        [eo tvfk([line secureSubstringFromIndex:15],@"meta_keywords")];
        continue;
    }
    if(inTT){
        [lma addObject:[[line htmlEscapedString] stringWithHTMLTabs]];
        [lma addObject:@"<br>"];
        [latexma addObject:line]; // hier nicht escapen, da verbatim
        continue;
    }
    if(!inText){
    // automatisch fallback auf \text
#include "endLastRegion.h"
        [lma addObject:@"<div class=HelpdeskText>"];
        inText = YES;
    }
    if(inText){
        [lma addObject:[line htmlEscapedString]];
        [lma addObject:@"<br>"];
        [latexma addObject:[line latexEscapedString]];
        if(addBR){
            // fuer text*
            [latexma addObject:@"\\\\"];
        }else{
            [latexma addObject:@"\\par"];
        }
        continue;
    }
}
#include "endLastRegion.h"
Foto