]> git.lyx.org Git - lyx.git/blob - src/output_linuxdoc.C
* remove various xforms relicts, in particular:
[lyx.git] / src / output_linuxdoc.C
1 /**
2  * \file output_linuxdoc.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author José Matos
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "output_linuxdoc.h"
15
16 #include "buffer.h"
17 #include "bufferparams.h"
18 #include "outputparams.h"
19 #include "paragraph.h"
20 #include "paragraph_funcs.h"
21 #include "ParagraphList.h"
22 #include "ParagraphParameters.h"
23 #include "sgml.h"
24
25 #include <stack>
26
27 using std::ostream;
28 using std::stack;
29 using std::vector;
30 using std::string;
31
32 void linuxdocParagraphs(Buffer const & buf,
33                         ParagraphList const & paragraphs,
34                         ostream & os,
35                         OutputParams const & runparams)
36 {
37
38         Paragraph::depth_type depth = 0; // paragraph depth
39         string item_name;
40         vector<string> environment_stack(5);
41
42         ParagraphList::const_iterator pit = paragraphs.begin();
43         ParagraphList::const_iterator pend = paragraphs.end();
44         
45         BOOST_ASSERT(runparams.par_begin <= runparams.par_end);
46         // if only part of the paragraphs will be outputed
47         if (runparams.par_begin !=  runparams.par_end) {
48                 pit = boost::next(paragraphs.begin(), runparams.par_begin);
49                 pend = boost::next(paragraphs.begin(), runparams.par_end);
50                 // runparams will be passed to nested paragraphs, so
51                 // we have to reset the range parameters.
52                 const_cast<OutputParams&>(runparams).par_begin = 0;
53                 const_cast<OutputParams&>(runparams).par_end = 0;
54         }
55
56         for (; pit != pend; ++pit) {
57                 LyXLayout_ptr const & style = pit->layout();
58                 // treat <toc> as a special case for compatibility with old code
59                 if (!pit->empty() && pit->isInset(0)) {
60                         InsetBase const * inset = pit->getInset(0);
61                         if (inset->lyxCode() == InsetBase::TOC_CODE) {
62                                 string const temp = "toc";
63                                 sgml::openTag(os, temp);
64                                 continue;
65                         }
66                 }
67
68                 // environment tag closing
69                 for (; depth > pit->params().depth(); --depth) {
70                         sgml::closeTag(os, environment_stack[depth]);
71                         environment_stack[depth].erase();
72                 }
73
74                 // write opening SGML tags
75                 switch (style->latextype) {
76                 case LATEX_PARAGRAPH:
77                         if (depth == pit->params().depth()
78                            && !environment_stack[depth].empty()) {
79                                 sgml::closeTag(os, environment_stack[depth]);
80                                 environment_stack[depth].erase();
81                                 if (depth)
82                                         --depth;
83                                 else
84                                         os << "</p>";
85                         }
86                         sgml::openTag(os, style->latexname());
87                         break;
88
89                 case LATEX_COMMAND:
90 #if 0
91                         if (depth != 0)
92                                 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
93 #endif
94
95                         if (!environment_stack[depth].empty()) {
96                                 sgml::closeTag(os, environment_stack[depth]);
97                                 os << "</p>";
98                         }
99
100                         environment_stack[depth].erase();
101                         sgml::openTag(os, style->latexname());
102                         break;
103
104                 case LATEX_ENVIRONMENT:
105                 case LATEX_ITEM_ENVIRONMENT:
106                 case LATEX_BIB_ENVIRONMENT: {
107                         string const & latexname = style->latexname();
108
109                         if (depth == pit->params().depth()
110                             && environment_stack[depth] != latexname) {
111                                 sgml::closeTag(os, environment_stack[depth]);
112                                 environment_stack[depth].erase();
113                         }
114                         if (depth < pit->params().depth()) {
115                                depth = pit->params().depth();
116                                environment_stack[depth].erase();
117                         }
118                         if (environment_stack[depth] != latexname) {
119                                 if (depth == 0) {
120                                         sgml::openTag(os, "p");
121                                 }
122                                 sgml::openTag(os, latexname);
123
124                                 if (environment_stack.size() == depth + 1)
125                                         environment_stack.push_back("!-- --");
126                                 environment_stack[depth] = latexname;
127                         }
128
129                         if (style->latexparam() == "CDATA")
130                                 os << "<![CDATA[";
131
132                         if (style->latextype == LATEX_ENVIRONMENT) break;
133
134                         if (style->labeltype == LABEL_MANUAL)
135                                 item_name = "tag";
136                         else
137                                 item_name = "item";
138
139                         sgml::openTag(os, item_name);
140                 }
141                 break;
142
143                 default:
144                         sgml::openTag(os, style->latexname());
145                         break;
146                 }
147
148                 pit->simpleLinuxDocOnePar(buf, os,
149                                           outerFont(std::distance(paragraphs.begin(), pit), paragraphs),
150                                           runparams, depth);
151
152                 os << "\n";
153                 // write closing SGML tags
154                 switch (style->latextype) {
155                 case LATEX_COMMAND:
156                         break;
157                 case LATEX_ENVIRONMENT:
158                 case LATEX_ITEM_ENVIRONMENT:
159                 case LATEX_BIB_ENVIRONMENT:
160                         if (style->latexparam() == "CDATA")
161                                 os << "]]>";
162                         break;
163                 default:
164                         sgml::closeTag(os, style->latexname());
165                         break;
166                 }
167         }
168
169         // Close open tags
170         for (int i = depth; i >= 0; --i)
171                 sgml::closeTag(os, environment_stack[i]);
172 }