]> git.lyx.org Git - lyx.git/blob - src/output_linuxdoc.C
the stuff from the sneak preview:
[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 "paragraph.h"
19 #include "paragraph_funcs.h"
20 #include "ParagraphList_fwd.h"
21 #include "ParagraphParameters.h"
22 #include "sgml.h"
23
24 #include <stack>
25
26 #ifdef HAVE_LOCALE
27 #endif
28
29 using std::ostream;
30 using std::stack;
31 using std::vector;
32 using std::string;
33
34 void linuxdocParagraphs(Buffer const & buf,
35                         ParagraphList const & paragraphs,
36                         ostream & os,
37                         OutputParams const & runparams)
38 {
39         
40         Paragraph::depth_type depth = 0; // paragraph depth
41         string item_name;
42         vector<string> environment_stack(5);
43
44         ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
45         ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
46         for (; pit != pend; ++pit) {
47                 LyXLayout_ptr const & style = pit->layout();
48                 // treat <toc> as a special case for compatibility with old code
49                 if (pit->isInset(0)) {
50                         InsetBase * inset = pit->getInset(0);
51                         if (inset->lyxCode() == InsetOld::TOC_CODE) {
52                                 string const temp = "toc";
53                                 sgml::openTag(os, depth, false, temp);
54                                 continue;
55                         }
56                 }
57
58                 // environment tag closing
59                 for (; depth > pit->params().depth(); --depth) {
60                         sgml::closeTag(os, depth, false, environment_stack[depth]);
61                         environment_stack[depth].erase();
62                 }
63
64                 // write opening SGML tags
65                 switch (style->latextype) {
66                 case LATEX_PARAGRAPH:
67                         if (depth == pit->params().depth()
68                            && !environment_stack[depth].empty()) {
69                                 sgml::closeTag(os, depth, false, environment_stack[depth]);
70                                 environment_stack[depth].erase();
71                                 if (depth)
72                                         --depth;
73                                 else
74                                         os << "</p>";
75                         }
76                         sgml::openTag(os, depth, false, style->latexname());
77                         break;
78
79                 case LATEX_COMMAND:
80                         if (depth != 0)
81                                 //error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
82                                 ;
83
84                         if (!environment_stack[depth].empty()) {
85                                 sgml::closeTag(os, depth, false, environment_stack[depth]);
86                                 os << "</p>";
87                         }
88
89                         environment_stack[depth].erase();
90                         sgml::openTag(os, depth, false, style->latexname());
91                         break;
92
93                 case LATEX_ENVIRONMENT:
94                 case LATEX_ITEM_ENVIRONMENT:
95                 case LATEX_BIB_ENVIRONMENT: {
96                         string const & latexname = style->latexname();
97
98                         if (depth == pit->params().depth()
99                             && environment_stack[depth] != latexname) {
100                                 sgml::closeTag(os, depth, false,
101                                              environment_stack[depth]);
102                                 environment_stack[depth].erase();
103                         }
104                         if (depth < pit->params().depth()) {
105                                depth = pit->params().depth();
106                                environment_stack[depth].erase();
107                         }
108                         if (environment_stack[depth] != latexname) {
109                                 if (depth == 0) {
110                                         sgml::openTag(os, depth, false, "p");
111                                 }
112                                 sgml::openTag(os, depth, false, latexname);
113
114                                 if (environment_stack.size() == depth + 1)
115                                         environment_stack.push_back("!-- --");
116                                 environment_stack[depth] = latexname;
117                         }
118
119                         if (style->latexparam() == "CDATA")
120                                 os << "<![CDATA[";
121
122                         if (style->latextype == LATEX_ENVIRONMENT) break;
123
124                         if (style->labeltype == LABEL_MANUAL)
125                                 item_name = "tag";
126                         else
127                                 item_name = "item";
128
129                         sgml::openTag(os, depth + 1, false, item_name);
130                 }
131                 break;
132
133                 default:
134                         sgml::openTag(os, depth, false, style->latexname());
135                         break;
136                 }
137
138                 pit->simpleLinuxDocOnePar(buf, os,
139                         outerFont(pit - const_cast<ParagraphList&>(paragraphs).begin(), paragraphs),
140                                           runparams, depth);
141
142                 os << "\n";
143                 // write closing SGML tags
144                 switch (style->latextype) {
145                 case LATEX_COMMAND:
146                         break;
147                 case LATEX_ENVIRONMENT:
148                 case LATEX_ITEM_ENVIRONMENT:
149                 case LATEX_BIB_ENVIRONMENT:
150                         if (style->latexparam() == "CDATA")
151                                 os << "]]>";
152                         break;
153                 default:
154                         sgml::closeTag(os, depth, false, style->latexname());
155                         break;
156                 }
157         }
158
159         // Close open tags
160         for (int i = depth; i >= 0; --i)
161                 sgml::closeTag(os, depth, false, environment_stack[i]);
162 }
163
164