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"
22 #include "ParagraphParameters.h"
23 #include "Paragraph.h"
24 #include <output_docbook.h>
26 #include "support/docstream.h"
27 #include "support/gettext.h"
28 #include "support/lstrings.h"
29 #include "support/TempFile.h"
34 using namespace lyx::support;
38 InsetERT::InsetERT(Buffer * buf, CollapseStatus status)
39 : InsetCollapsible(buf)
45 InsetERT::InsetERT(InsetERT const & old)
46 : InsetCollapsible(old)
50 void InsetERT::write(ostream & os) const
53 InsetCollapsible::write(os);
57 int InsetERT::plaintext(odocstringstream & os,
58 OutputParams const & rp, size_t max_length) const
61 // do not output TeX code
64 ParagraphList::const_iterator par = paragraphs().begin();
65 ParagraphList::const_iterator end = paragraphs().end();
67 while (par != end && os.str().size() <= max_length) {
68 pos_type siz = par->size();
69 for (pos_type i = 0; i < siz; ++i) {
70 char_type const c = par->getChar(i);
71 // output the active characters
88 void InsetERT::docbook(XMLStream & xs, OutputParams const & runparams) const
90 auto const begin = paragraphs().begin();
92 auto const end = paragraphs().end();
94 odocstringstream os; // No need for XML handling here.
96 // Recreate the logic of makeParagraph in output_docbook.cpp, but much simplified: never open <para>
97 // in an ERT, use simple line breaks.
98 // New line after each paragraph of the ERT, save the last one.
99 while (true) { // For each paragraph in the ERT...
100 auto pars = par->simpleDocBookOnePar(buffer(), runparams, text().outerFont(distance(begin, par)), 0, false, true);
101 auto p = pars.begin();
102 while (true) { // For each line of this ERT paragraph...
118 // // Implement the special case of \and: split the current item.
119 // if (os.str() == "\\and" || os.str() == "\\and ") {
120 // auto lay = getLayout();
123 // Output the ERT as a comment with the appropriate escaping.
124 xs << XMLStream::ESCAPE_NONE << "<!-- ";
125 xs << XMLStream::ESCAPE_COMMENTS << os.str();
126 xs << XMLStream::ESCAPE_NONE << " -->";
130 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
132 switch (cmd.action()) {
133 case LFUN_INSET_MODIFY:
134 if (cmd.getArg(0) == "ert") {
135 cur.recordUndoInset(this);
136 setStatus(cur, string2params(to_utf8(cmd.argument())));
141 InsetCollapsible::doDispatch(cur, cmd);
148 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
149 FuncStatus & status) const
151 switch (cmd.action()) {
152 case LFUN_INSET_INSERT:
153 status.setEnabled(false);
155 case LFUN_INSET_MODIFY:
156 if (cmd.getArg(0) == "ert") {
157 status.setEnabled(true);
163 return InsetCollapsible::getStatus(cur, cmd, status);
169 docstring const InsetERT::buttonLabel(BufferView const & bv) const
171 if (decoration() == InsetLayout::CLASSIC)
172 return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
174 return getNewLabel(_("ERT"));
178 InsetCollapsible::CollapseStatus InsetERT::string2params(string const & in)
182 istringstream data(in);
185 lex.setContext("InsetERT::string2params");
189 return static_cast<CollapseStatus>(s);
193 string InsetERT::params2string(CollapseStatus status)
196 data << "ert" << ' ' << status;
201 docstring InsetERT::xhtml(XMLStream &, OutputParams const &) const