3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
17 #include "FuncRequest.h"
18 #include "FuncStatus.h"
21 #include "OutputParams.h"
23 #include "ParagraphParameters.h"
24 #include "Paragraph.h"
25 #include <output_docbook.h>
27 #include "support/docstream.h"
28 #include "support/gettext.h"
29 #include "support/lstrings.h"
30 #include "support/TempFile.h"
35 using namespace lyx::support;
39 InsetERT::InsetERT(Buffer * buf, CollapseStatus status)
40 : InsetCollapsible(buf)
46 InsetERT::InsetERT(InsetERT const & old)
47 : InsetCollapsible(old)
51 void InsetERT::write(ostream & os) const
54 InsetCollapsible::write(os);
58 int InsetERT::plaintext(odocstringstream & os,
59 OutputParams const & rp, size_t max_length) const
62 // do not output TeX code
65 ParagraphList::const_iterator par = paragraphs().begin();
66 ParagraphList::const_iterator end = paragraphs().end();
68 while (par != end && os.str().size() <= max_length) {
69 pos_type siz = par->size();
70 for (pos_type i = 0; i < siz; ++i) {
71 char_type const c = par->getChar(i);
72 // output the active characters
89 void InsetERT::docbook(XMLStream & xs, OutputParams const & runparams) const
91 auto const begin = paragraphs().begin();
93 auto const end = paragraphs().end();
95 odocstringstream os; // No need for XML handling here.
97 // Recreate the logic of makeParagraph in output_docbook.cpp, but much simplified: never open <para>
98 // in an ERT, use simple line breaks.
99 // New line after each paragraph of the ERT, save the last one.
100 while (true) { // For each paragraph in the ERT...
101 auto pars = par->simpleDocBookOnePar(buffer(), runparams, text().outerFont(distance(begin, par)));
102 auto p = pars.begin();
103 while (true) { // For each line of this ERT paragraph...
119 // // Implement the special case of \and: split the current item.
120 // if (os.str() == "\\and" || os.str() == "\\and ") {
121 // auto lay = getLayout();
124 // Output the ERT as a comment with the appropriate escaping.
125 xs << XMLStream::ESCAPE_NONE << "<!-- ";
126 xs << XMLStream::ESCAPE_COMMENTS << os.str();
127 xs << XMLStream::ESCAPE_NONE << " -->";
132 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
134 switch (cmd.action()) {
135 case LFUN_INSET_MODIFY:
136 if (cmd.getArg(0) == "ert") {
137 cur.recordUndoInset(this);
138 setStatus(cur, string2params(to_utf8(cmd.argument())));
143 InsetCollapsible::doDispatch(cur, cmd);
150 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
151 FuncStatus & status) const
153 switch (cmd.action()) {
154 case LFUN_INSET_INSERT:
155 status.setEnabled(false);
157 case LFUN_INSET_MODIFY:
158 if (cmd.getArg(0) == "ert") {
159 status.setEnabled(true);
165 return InsetCollapsible::getStatus(cur, cmd, status);
171 docstring const InsetERT::buttonLabel(BufferView const & bv) const
173 if (decoration() == InsetLayout::CLASSIC)
174 return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
176 return getNewLabel(_("ERT"));
180 InsetCollapsible::CollapseStatus InsetERT::string2params(string const & in)
184 istringstream data(in);
187 lex.setContext("InsetERT::string2params");
191 return static_cast<CollapseStatus>(s);
195 string InsetERT::params2string(CollapseStatus status)
198 data << "ert" << ' ' << status;
203 docstring InsetERT::xhtml(XMLStream &, OutputParams const &) const