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