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 "BufferParams.h"
18 #include "BufferView.h"
20 #include "DispatchResult.h"
21 #include "FuncRequest.h"
22 #include "FuncStatus.h"
26 #include "LyXAction.h"
27 #include "OutputParams.h"
29 #include "ParagraphParameters.h"
30 #include "Paragraph.h"
31 #include <output_docbook.h>
33 #include "support/docstream.h"
34 #include "support/gettext.h"
35 #include "support/lstrings.h"
36 #include "support/TempFile.h"
41 using namespace lyx::support;
45 InsetERT::InsetERT(Buffer * buf, CollapseStatus status)
46 : InsetCollapsible(buf)
52 InsetERT::InsetERT(InsetERT const & old)
53 : InsetCollapsible(old)
57 void InsetERT::write(ostream & os) const
60 InsetCollapsible::write(os);
64 int InsetERT::plaintext(odocstringstream & os,
65 OutputParams const & rp, size_t max_length) const
68 // do not output TeX code
71 ParagraphList::const_iterator par = paragraphs().begin();
72 ParagraphList::const_iterator end = paragraphs().end();
74 while (par != end && os.str().size() <= max_length) {
75 pos_type siz = par->size();
76 for (pos_type i = 0; i < siz; ++i) {
77 char_type const c = par->getChar(i);
78 // output the active characters
95 void InsetERT::docbook(XMLStream & xs, OutputParams const & runparams) const
97 auto const begin = paragraphs().begin();
99 auto const end = paragraphs().end();
101 odocstringstream os; // No need for XML handling here.
103 // Recreate the logic of makeParagraph in output_docbook.cpp, but much simplified: never open <para>
104 // in an ERT, use simple line breaks.
105 // New line after each paragraph of the ERT, save the last one.
106 while (true) { // For each paragraph in the ERT...
107 auto pars = par->simpleDocBookOnePar(buffer(), runparams, text().outerFont(distance(begin, par)));
108 auto p = pars.begin();
109 while (true) { // For each line of this ERT paragraph...
125 // Output the ERT as a comment with the appropriate escaping.
126 xs << XMLStream::ESCAPE_NONE << "<!-- ";
127 xs << XMLStream::ESCAPE_COMMENTS << os.str();
128 xs << XMLStream::ESCAPE_NONE << " -->";
133 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
135 switch (cmd.action()) {
136 case LFUN_INSET_MODIFY:
137 if (cmd.getArg(0) == "ert") {
138 cur.recordUndoInset(this);
139 setStatus(cur, string2params(to_utf8(cmd.argument())));
144 InsetCollapsible::doDispatch(cur, cmd);
151 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
152 FuncStatus & status) const
154 switch (cmd.action()) {
155 case LFUN_INSET_INSERT:
156 status.setEnabled(false);
158 case LFUN_INSET_MODIFY:
159 if (cmd.getArg(0) == "ert") {
160 status.setEnabled(true);
166 return InsetCollapsible::getStatus(cur, cmd, status);
172 docstring const InsetERT::buttonLabel(BufferView const & bv) const
174 if (decoration() == InsetLayout::CLASSIC)
175 return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
177 return getNewLabel(_("ERT"));
181 InsetCollapsible::CollapseStatus InsetERT::string2params(string const & in)
185 istringstream data(in);
188 lex.setContext("InsetERT::string2params");
192 return static_cast<CollapseStatus>(s);
196 string InsetERT::params2string(CollapseStatus status)
199 data << "ert" << ' ' << status;
204 docstring InsetERT::xhtml(XMLStream &, OutputParams const &) const