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"
19 #include "InsetLayout.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"
37 using namespace lyx::support;
41 InsetERT::InsetERT(Buffer * buf, CollapseStatus status)
42 : InsetCollapsible(buf)
48 InsetERT::InsetERT(InsetERT const & old)
49 : InsetCollapsible(old)
53 void InsetERT::write(ostream & os) const
56 InsetCollapsible::write(os);
60 int InsetERT::plaintext(odocstringstream & os,
61 OutputParams const & rp, size_t max_length) const
64 // do not output TeX code
67 ParagraphList::const_iterator par = paragraphs().begin();
68 ParagraphList::const_iterator end = paragraphs().end();
70 while (par != end && os.str().size() <= max_length) {
71 pos_type siz = par->size();
72 for (pos_type i = 0; i < siz; ++i) {
73 char_type const c = par->getChar(i);
74 // output the active characters
91 void InsetERT::docbook(XMLStream & xs, OutputParams const & runparams) const
93 auto const begin = paragraphs().begin();
95 auto const end = paragraphs().end();
97 odocstringstream os; // No need for XML handling here.
99 // Recreate the logic of makeParagraph in output_docbook.cpp, but much simplified: never open <para>
100 // in an ERT, use simple line breaks.
101 // New line after each paragraph of the ERT, save the last one.
102 while (true) { // For each paragraph in the ERT...
103 std::vector<docstring> pars_prepend;
104 std::vector<docstring> pars;
105 std::vector<docstring> pars_append;
106 tie(pars_prepend, pars, pars_append) = par->simpleDocBookOnePar(buffer(), runparams, text().outerFont(distance(begin, par)), 0, false, true);
108 for (docstring const & parXML : pars_prepend)
109 xs << XMLStream::ESCAPE_NONE << parXML;
110 auto p = pars.begin();
111 while (true) { // For each line of this ERT paragraph...
119 for (docstring const & parXML : pars_append)
120 xs << XMLStream::ESCAPE_NONE << parXML;
129 // // Implement the special case of \and: split the current item.
130 // if (os.str() == "\\and" || os.str() == "\\and ") {
131 // auto lay = getLayout();
134 // Output the ERT as a comment with the appropriate escaping if the command is not recognised.
135 if (trim(os.str()) == from_ascii("\\textquotesingle")) {
137 } else if (trim(os.str()) == from_ascii("\\TeX") || trim(os.str()) == from_ascii("\\TeX{}")) {
139 } else if (trim(os.str()) == from_ascii("\\LaTeX") || trim(os.str()) == from_ascii("\\LaTeX{}")) {
141 } else if (trim(os.str()) == from_ascii("\\LaTeXe") || trim(os.str()) == from_ascii("\\LaTeXe{}")) {
142 xs << "LaTeX2ε";
143 } else if (trim(os.str()) == from_ascii("\\LyX") || trim(os.str()) == from_ascii("\\LyX{}")) {
145 } else if (trim(os.str()) == from_ascii("\\oe") || trim(os.str()) == from_ascii("\\oe{}")) {
147 } else if (trim(os.str()) == from_ascii("\\OE") || trim(os.str()) == from_ascii("\\OE{}")) {
150 xs << XMLStream::ESCAPE_NONE << "<!-- ";
151 xs << XMLStream::ESCAPE_COMMENTS << os.str();
152 xs << XMLStream::ESCAPE_NONE << " -->";
157 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
159 switch (cmd.action()) {
160 case LFUN_INSET_MODIFY:
161 if (cmd.getArg(0) == "ert") {
162 cur.recordUndoInset(this);
163 setStatus(cur, string2params(to_utf8(cmd.argument())));
168 InsetCollapsible::doDispatch(cur, cmd);
175 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
176 FuncStatus & status) const
178 switch (cmd.action()) {
179 case LFUN_INSET_INSERT:
180 status.setEnabled(false);
182 case LFUN_INSET_MODIFY:
183 if (cmd.getArg(0) == "ert") {
184 status.setEnabled(true);
190 return InsetCollapsible::getStatus(cur, cmd, status);
196 docstring const InsetERT::buttonLabel(BufferView const & bv) const
199 docstring const locked = tempfile_ ? docstring(1, 0x1F512) : docstring();
200 if (decoration() == InsetDecoration::CLASSIC)
201 return locked + (isOpen(bv) ? _("ERT") : getNewLabel(_("ERT")));
202 return locked + getNewLabel(_("ERT"));
206 InsetCollapsible::CollapseStatus InsetERT::string2params(string const & in)
210 istringstream data(in);
213 lex.setContext("InsetERT::string2params");
217 return static_cast<CollapseStatus>(s);
221 string InsetERT::params2string(CollapseStatus status)
224 data << "ert" << ' ' << status;
229 docstring InsetERT::xhtml(XMLStream &, OutputParams const &) const