- vector<string> environment_stack(10);
- vector<string> environment_inner(10);
- vector<string> command_stack(10);
-
- bool command_flag = false;
- Paragraph::depth_type command_depth = 0;
- Paragraph::depth_type command_base = 0;
- Paragraph::depth_type cmd_depth = 0;
- Paragraph::depth_type depth = 0; // paragraph depth
-
- string item_name;
- string command_name;
-
- ParagraphList::iterator par = paragraphs.begin();
- ParagraphList::iterator pend = paragraphs.end();
-
- for (; par != pend; ++par) {
- string sgmlparam;
- string c_depth;
- string c_params;
- int desc_on = 0; // description mode
-
- LyXLayout_ptr const & style = par->layout();
-
- // environment tag closing
- for (; depth > par->params().depth(); --depth) {
- if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
- item_name = "listitem";
- sgml::closeTag(ofs, command_depth + depth, false, item_name);
- if (environment_inner[depth] == "varlistentry")
- sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
- }
- sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
- environment_stack[depth].erase();
- environment_inner[depth].erase();
- }
-
- if (depth == par->params().depth()
- && environment_stack[depth] != style->latexname()
- && !environment_stack[depth].empty()) {
- if (environment_inner[depth] != "!-- --") {
- item_name= "listitem";
- sgml::closeTag(ofs, command_depth+depth, false, item_name);
- if (environment_inner[depth] == "varlistentry")
- sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
- }
-
- sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
-
- environment_stack[depth].erase();
- environment_inner[depth].erase();
- }
-
- // Write opening SGML tags.
- switch (style->latextype) {
- case LATEX_PARAGRAPH:
- sgml::openTag(ofs, depth + command_depth,
- false, style->latexname());
- break;
-
- case LATEX_COMMAND:
- if (depth != 0)
- error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
-
- command_name = style->latexname();
-
- sgmlparam = style->latexparam();
- c_params = split(sgmlparam, c_depth,'|');
-
- cmd_depth = atoi(c_depth);
-
- if (command_flag) {
- if (cmd_depth < command_base) {
- for (Paragraph::depth_type j = command_depth;
- j >= command_base; --j) {
- sgml::closeTag(ofs, j, false, command_stack[j]);
- ofs << endl;
- }
- command_depth = command_base = cmd_depth;
- } else if (cmd_depth <= command_depth) {
- for (int j = command_depth;
- j >= int(cmd_depth); --j) {
- sgml::closeTag(ofs, j, false, command_stack[j]);
- ofs << endl;
- }
- command_depth = cmd_depth;
- } else
- command_depth = cmd_depth;
- } else {
- command_depth = command_base = cmd_depth;
- command_flag = true;
- }
- if (command_stack.size() == command_depth + 1)
- command_stack.push_back(string());
- command_stack[command_depth] = command_name;
-
- // treat label as a special case for
- // more WYSIWYM handling.
- // This is a hack while paragraphs can't have
- // attributes, like id in this case.
- if (par->isInset(0)) {
- InsetOld * inset = par->getInset(0);
- InsetOld::Code lyx_code = inset->lyxCode();
- if (lyx_code == InsetOld::LABEL_CODE) {
- command_name += " id=\"";
- command_name += (static_cast<InsetCommand *>(inset))->getContents();
- command_name += '"';
- desc_on = 3;
- }
- }
-
- sgml::openTag(ofs, depth + command_depth, false, command_name);
-
- item_name = c_params.empty() ? "title" : c_params;
- sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
- break;
-
- case LATEX_ENVIRONMENT:
- case LATEX_ITEM_ENVIRONMENT:
- if (depth < par->params().depth()) {
- depth = par->params().depth();
- environment_stack[depth].erase();
- }
-
- if (environment_stack[depth] != style->latexname()) {
- if (environment_stack.size() == depth + 1) {
- environment_stack.push_back("!-- --");
- environment_inner.push_back("!-- --");
- }
- environment_stack[depth] = style->latexname();
- environment_inner[depth] = "!-- --";
- sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
- } else {
- if (environment_inner[depth] != "!-- --") {
- item_name= "listitem";
- sgml::closeTag(ofs, command_depth + depth, false, item_name);
- if (environment_inner[depth] == "varlistentry")
- sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
- }
- }
-
- if (style->latextype == LATEX_ENVIRONMENT) {
- if (!style->latexparam().empty()) {
- if (style->latexparam() == "CDATA")
- ofs << "<![CDATA[";
- else
- sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
- }
- break;
- }
-
- desc_on = (style->labeltype == LABEL_MANUAL);
-
- environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
- sgml::openTag(ofs, depth + 1 + command_depth,
- false, environment_inner[depth]);
-
- item_name = desc_on ? "term" : "para";
- sgml::openTag(ofs, depth + 1 + command_depth,
- false, item_name);
- break;
- default:
- sgml::openTag(ofs, depth + command_depth,
- false, style->latexname());
- break;
- }
-
- simpleDocBookOnePar(ofs, par, desc_on,
- depth + 1 + command_depth);
-
- string end_tag;
- // write closing SGML tags
- switch (style->latextype) {
- case LATEX_COMMAND:
- end_tag = c_params.empty() ? "title" : c_params;
- sgml::closeTag(ofs, depth + command_depth,
- false, end_tag);
- break;
- case LATEX_ENVIRONMENT:
- if (!style->latexparam().empty()) {
- if (style->latexparam() == "CDATA")
- ofs << "]]>";
- else
- sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
- }
- break;
- case LATEX_ITEM_ENVIRONMENT:
- if (desc_on == 1) break;
- end_tag = "para";
- sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
- break;
- case LATEX_PARAGRAPH:
- sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
- break;
- default:
- sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
- break;
- }
- }