2 * \file output_docbook.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
14 #include "output_docbook.h"
17 #include "bufferparams.h"
18 #include "paragraph.h"
19 #include "paragraph_funcs.h"
20 #include "ParagraphParameters.h"
23 #include "insets/insetcommand.h"
25 #include "support/lstrings.h"
26 #include "support/lyxlib.h"
33 using lyx::support::atoi;
34 using lyx::support::split;
43 void docbookParagraphs(Buffer const & buf,
44 ParagraphList const & paragraphs,
46 OutputParams const & runparams)
48 vector<string> environment_stack(10);
49 vector<string> environment_inner(10);
50 vector<string> command_stack(10);
52 bool command_flag = false;
53 Paragraph::depth_type command_depth = 0;
54 Paragraph::depth_type command_base = 0;
55 Paragraph::depth_type cmd_depth = 0;
56 Paragraph::depth_type depth = 0; // paragraph depth
60 ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
61 ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
63 for (; par != pend; ++par) {
65 int desc_on = 0; // description mode
67 LyXLayout_ptr const & style = par->layout();
69 // environment tag closing
70 for (; depth > par->params().depth(); --depth) {
71 if (!environment_inner[depth].empty())
72 sgml::closeEnvTags(os, false, environment_inner[depth],
73 command_depth + depth);
74 sgml::closeTag(os, depth + command_depth, false, environment_stack[depth]);
75 environment_stack[depth].erase();
76 environment_inner[depth].erase();
79 if (depth == par->params().depth()
80 && environment_stack[depth] != style->latexname()
81 && !environment_stack[depth].empty()) {
82 sgml::closeEnvTags(os, false, environment_inner[depth],
83 command_depth + depth);
84 sgml::closeTag(os, depth + command_depth, false, environment_stack[depth]);
86 environment_stack[depth].erase();
87 environment_inner[depth].erase();
90 // Write opening SGML tags.
92 switch (style->latextype) {
94 sgml::openTag(os, depth + command_depth,
95 false, style->latexname());
100 //error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
103 command_name = style->latexname();
105 cmd_depth = style->commanddepth;
106 inner_tag = style->innertag();
109 if (cmd_depth < command_base) {
110 for (Paragraph::depth_type j = command_depth;
111 j >= command_base; --j) {
112 sgml::closeTag(os, j, false, command_stack[j]);
115 command_depth = command_base = cmd_depth;
116 } else if (cmd_depth <= command_depth) {
117 for (int j = command_depth;
118 j >= int(cmd_depth); --j) {
119 sgml::closeTag(os, j, false, command_stack[j]);
122 command_depth = cmd_depth;
124 command_depth = cmd_depth;
126 command_depth = command_base = cmd_depth;
129 if (command_stack.size() == command_depth + 1)
130 command_stack.push_back(string());
131 command_stack[command_depth] = command_name;
133 // treat label as a special case for
134 // more WYSIWYM handling.
135 // This is a hack while paragraphs can't have
136 // attributes, like id in this case.
137 if (par->isInset(0)) {
138 InsetOld * inset = par->getInset(0);
139 InsetOld::Code lyx_code = inset->lyxCode();
140 if (lyx_code == InsetOld::LABEL_CODE) {
141 command_name += " id=\"";
142 command_name += (static_cast<InsetCommand *>(inset))->getContents();
148 sgml::openTag(os, depth + command_depth, false, command_name);
149 // Inner tagged header text, e.g. <title> for sectioning:
150 sgml::openTag(os, depth + 1 + command_depth, false, inner_tag);
153 case LATEX_ENVIRONMENT:
154 case LATEX_ITEM_ENVIRONMENT:
155 if (depth < par->params().depth()) {
156 depth = par->params().depth();
157 environment_stack[depth].erase();
160 if (environment_stack[depth] != style->latexname()) {
161 if (environment_stack.size() == depth + 1) {
162 environment_stack.push_back("!-- --");
163 environment_inner.push_back("!-- --");
165 environment_stack[depth] = style->latexname();
166 environment_inner[depth] = "!-- --";
167 sgml::openTag(os, depth + command_depth, false, environment_stack[depth]);
169 sgml::closeEnvTags(os, false, environment_inner[depth],
170 command_depth + depth);
173 if (style->latextype == LATEX_ENVIRONMENT) {
174 if (!style->latexparam().empty()) {
175 if (style->latexparam() == "CDATA")
178 sgml::openTag(os, depth + command_depth, false, style->latexparam());
183 desc_on = (style->labeltype == LABEL_MANUAL);
185 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
186 sgml::openTag(os, depth + 1 + command_depth,
187 false, environment_inner[depth]);
189 item_name = desc_on ? "term" : "para";
190 sgml::openTag(os, depth + 1 + command_depth,
194 sgml::openTag(os, depth + command_depth,
195 false, style->latexname());
199 par->simpleDocBookOnePar(buf, os, outerFont(par, paragraphs), desc_on,
200 runparams, depth + 1 + command_depth);
203 // write closing SGML tags
204 switch (style->latextype) {
206 sgml::closeTag(os, depth + command_depth, false, inner_tag);
208 case LATEX_ENVIRONMENT:
209 if (!style->latexparam().empty()) {
210 if (style->latexparam() == "CDATA")
213 sgml::closeTag(os, depth + command_depth, false, style->latexparam());
216 case LATEX_ITEM_ENVIRONMENT:
217 if (desc_on == 1) break;
219 sgml::closeTag(os, depth + 1 + command_depth, false, end_tag);
221 case LATEX_PARAGRAPH:
222 sgml::closeTag(os, depth + command_depth, false, style->latexname());
225 sgml::closeTag(os, depth + command_depth, false, style->latexname());
231 for (int d = depth; d >= 0; --d) {
232 if (!environment_stack[depth].empty()) {
233 sgml::closeEnvTags(os, false, environment_inner[depth],
234 command_depth + depth);
238 for (int j = command_depth; j >= 0 ; --j)
239 if (!command_stack[j].empty()) {
240 sgml::closeTag(os, j, false, command_stack[j]);