pike.git / lib / modules / Tools.pmod / Standalone.pmod / autodoc_to_html.pike

version» Context lines:

pike.git/lib/modules/Tools.pmod/Standalone.pmod/autodoc_to_html.pike:104:    foreach(n->get_children(), Node c)    if(c->get_node_type()==XML_ELEMENT) {    if(c->get_any_name()!="source-position")    return c;    else    position->update(c);    }    return UNDEFINED;   }    - int section, subsection; -  - string low_parse_chapter(Node n, int chapter) { + string low_parse_chapter(Node n, array(string) section_path) {    string ret = "";    Node dummy = Node(XML_ELEMENT, "dummy", ([]), "");    foreach(n->get_elements(), Node c)    switch(c->get_any_name()) {       case "p":    dummy->replace_children( ({ c }) ); -  ret += parse_text(dummy); +  ret += parse_text(dummy, UNDEFINED, section_path);    break;       case "example":    ret += "<p></p><pre>" + quote(c->value_of_node()) +    "</pre><p></p>\n";    break;       case "ul":    case "ol":    ret += (string)c;
pike.git/lib/modules/Tools.pmod/Standalone.pmod/autodoc_to_html.pike:143:    ret += "<" + tag + ">" + parse_text(cc) + "</" + tag + ">\n";    }    ret += "</dl>";    break;       case "matrix":    ret += layout_matrix( map(c->get_elements("r")->get_elements("c"), map, parse_text) );    break;       case "section": -  if(section) -  error("Section inside section.\n"); -  if(subsection) -  error("Section inside subsection.\n"); -  section = (int)c->get_attributes()->number; -  ret += "</dd>\n<dt><a name='" + section + "'></a>\n" -  "<h2 class='header'>" + chapter + "." + section + -  ". " + quote(c->get_attributes()->title || +  case "subsection": +  string section = c->get_attributes()->number; +  array(string) new_section_path = section_path + ({ section }); +  string section_name = new_section_path * "."; +  ret += sprintf("</dd>\n<dt><a name='%s'></a>\n" +  "<h%d class='header'>%s. %s</h%d></dt>\n<dd>", +  section_name, +  sizeof(new_section_path), +  section_name, +  quote(c->get_attributes()->title ||    // The following for bug compat. -  c->get_attributes()->name) + -  "</h2></dt>\n<dd>"; -  ret += low_parse_chapter(c, chapter); -  section = 0; +  c->get_attributes()->name || +  ""), +  sizeof(new_section_path)); +  ret += low_parse_chapter(c, new_section_path);    break;    -  case "subsection": -  if(!section) -  error("Subsection outside section.\n"); -  if(subsection) -  error("Subsection inside subsection.\n"); -  subsection = (int)c->get_attributes()->number; -  ret += "</dd><dt>" -  "<h3 class='header'>" + chapter + "." + section + "." + subsection + -  ". " + quote(c->get_attributes()->title) + -  "</h3></dt><dd>"; -  ret += low_parse_chapter(c, chapter); -  subsection = 0; -  break; -  +     case "docgroup":    ret += parse_docgroup(c);    break;       case "autodoc":    ret += parse_autodoc(c);    break;       case "namespace":    ret += parse_namespace(c);
pike.git/lib/modules/Tools.pmod/Standalone.pmod/autodoc_to_html.pike:217:    if(!noheader) {    ret += "<dl><dt>"    "<h1 class='header'>";    if(n->get_attributes()->number)    ret += n->get_attributes()->number + ". ";    ret += quote(n->get_attributes()->title) +    "</h1>"    "</dt><dd>";    }    -  ret += low_parse_chapter(n, (int)n->get_attributes()->number); +  ret += low_parse_chapter(n, ({ n->get_attributes()->number }));       if(!noheader)    ret = ret + "</dd></dl>";       return ret;   }      string parse_appendix(Node n, void|int noheader) {    string ret ="";    if(!noheader)    ret += "<dl><dt>"    "<h2 class='header'>Appendix " +    (string)({ 64+(int)n->get_attributes()->number }) + ". " +    n->get_attributes()->name + "</h2>\n"    "</dt><dd>";       Node c = n->get_first_element("doc");    if(c) -  ret += parse_text(c); +  ret += parse_text(c, UNDEFINED, +  ({ (string)({ 64+(int)n->get_attributes()->number }) }));    else    error( "No doc element in appendix.\n" );      #ifdef DEBUG    if(sizeof(n->get_elements("doc"))>1)    error( "More than one doc element in appendix node.\n" );   #endif       if(!noheader)    ret = ret + "</dd></dl>";
pike.git/lib/modules/Tools.pmod/Standalone.pmod/autodoc_to_html.pike:577:    if (!is_quoted) {    text = quote(text);    }       ret->add(text);    }    else return quote(text);   }      //! Typically called with a <group/> node or a sub-node that is a container. - string parse_text(Node n, void|String.Buffer ret) { + string parse_text(Node n, void|String.Buffer ret, +  array(string)|void section_path) {    if(n->get_node_type()==XML_TEXT && n->get_text()) {    if(ret)    ret->add("parse_text:#1:", quote(n->get_text()));    else    return quote("parse_text:#1:" + n->get_text());    }       int cast;    if(!ret) {    ret = String.Buffer();
pike.git/lib/modules/Tools.pmod/Standalone.pmod/autodoc_to_html.pike:613:    ((flags & (Tools.AutoDoc.FLAG_KEEP_GOING|Tools.AutoDoc.FLAG_DEBUG)) ==    Tools.AutoDoc.FLAG_DEBUG)) {    error( "Forbidden node type " + c->get_node_type() + " in doc node.\n" );    }       array rows;    string name = c->get_any_name();    switch(name) {    case "text":    ret->add("<dd>"); -  parse_text(c, ret); +  parse_text(c, ret, section_path);    ret->add("</dd>\n");    break;       case "p":    case "b":    case "i":    case "tt":    case "sub":    case "sup":    ret->add("<", name, ">"); -  parse_text(c, ret); +  parse_text(c, ret, section_path);    ret->add("</", name, ">");    break;       case "pre":    ret->add(lay->pre); -  parse_text(c, ret); +  parse_text(c, ret, section_path);    ret->add(lay->_pre);    break;       case "code":    ret->add(lay->code);    parse_code(c, ret);    ret->add(lay->_code);    break;       case "expr":
pike.git/lib/modules/Tools.pmod/Standalone.pmod/autodoc_to_html.pike:693:    case "item":    if(c->get_attributes()->name) {    ret->add("<dt>", c->get_attributes()->name, "</dt>\n");    if(c->count_children() &&    ((flags & (Tools.AutoDoc.FLAG_KEEP_GOING|Tools.AutoDoc.FLAG_DEBUG)) ==    Tools.AutoDoc.FLAG_DEBUG)) {    error( "dl item has a child.\n" );    }    } else if (c->count_children()) {    ret->add("<dt>"); -  parse_text(c, ret); +  parse_text(c, ret, section_path);    ret->add("</dt>");    }    break;       case "mapping":    build_box(c, ret, "group", "member",    lambda(Node n) {    string res = "";    Node nn = n->get_first_element("index");    if (nn) {
pike.git/lib/modules/Tools.pmod/Standalone.pmod/autodoc_to_html.pike:793:    Tools.AutoDoc.FLAG_DEBUG)) {    error( "url node has not one child. %O\n", c->html_of_node() );    }    m = c->get_attributes();    if(!m->href)    m->href=c->value_of_node();    ret->add( sprintf("%s%s</a>", render_tag("a", m), c->value_of_node()) );    break;       case "section": -  if(section && !(flags & Tools.AutoDoc.FLAG_KEEP_GOING)) -  error("Section inside section.\n"); -  ret->add ("<h2>", quote (c->get_attributes()->title || +  case "subsection": +  array(string) new_section_path = section_path + +  ({ c->get_attributes()->number }); +  ret->sprintf("<h%d>%s</h%d>\n", +  sizeof(new_section_path), +  quote (c->get_attributes()->title ||    // The following for bug compat.    c->get_attributes()->name), -  "</h2>\n"); +  sizeof(new_section_path));    if (!equal (c->get_children()->get_any_name(), ({"text"})) &&    !(flags & Tools.AutoDoc.FLAG_KEEP_GOING))    error ("Expected a single <text> element inside <section>.\n"); -  section = -1; -  parse_text (c->get_children()[0], ret); -  section = 0; +  parse_text (c->get_children()[0], ret, new_section_path);    break;       case "ul":    case "ol":    ret->add( "<", name, ">\n" );    foreach(c->get_elements("group"), Node c) {    int got_item;    foreach(c->get_elements(), Node e) {    switch(e->get_any_name()) {    case "item":
pike.git/lib/modules/Tools.pmod/Standalone.pmod/autodoc_to_html.pike:829:    string title = e->get_attributes()->name;    if (title) {    ret->add("<b>", title, "</b>");    }    got_item = 1;    break;    case "text":    if (!got_item) {    ret->add("<li>");    } -  parse_text(e, ret); +  parse_text(e, ret, section_path);    ret->add("</li>");    got_item = 0;    break;    default:    // Ignored.    break;    }    }    if (got_item) {    ret->add("</li>");
pike.git/lib/modules/Tools.pmod/Standalone.pmod/autodoc_to_html.pike:857:    position->update(c);    break;       case "matrix":    ret->add( layout_matrix( map(c->get_elements("r")->get_elements("c"),    map, parse_text) ) );    break;       case "fixme":    ret->add("<span class='fixme'>FIXME: "); -  parse_text(c, ret); +  parse_text(c, ret, section_path);    ret->add("</span>");    break;       // Not really allowed    case "br":    ret->add( render_tag(c->get_any_name(), c->get_attributes(), 1) );    break;    case "table":    case "td":    case "tr":