#include "insets/InsetBranch.h"
#include "insets/InsetInclude.h"
-#include "insets/InsetTabular.h"
#include "insets/InsetText.h"
#include "mathed/InsetMathHull.h"
params().shell_escape = theSession().shellescapeFiles().find(absFileName());
- params().makeDocumentClass();
+ params().makeDocumentClass(isClone(), isInternal());
return unknown_tokens;
}
if (!ploader)
return;
- InsetIterator it = inset_iterator_begin(*d->inset);
- InsetIterator const end = inset_iterator_end(*d->inset);
- for (; it != end; ++it)
+ InsetIterator it = begin(*d->inset);
+ InsetIterator const itend = end(*d->inset);
+ for (; it != itend; ++it)
it->addPreview(it, *ploader);
ploader->startLoading();
catch (EncodingException const & e) {
docstring const failed(1, e.failed_char);
ostringstream oss;
- oss << "0x" << hex << e.failed_char << dec;
+ oss << "0x" << hex << static_cast<uint32_t>(e.failed_char) << dec;
if (getParFromID(e.par_id).paragraph().layout().pass_thru) {
docstring msg = bformat(_("Uncodable character '%1$s'"
" (code point %2$s)"),
// parsep in output_docbook.cpp).
os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
<< "<!-- This DocBook file was created by LyX " << lyx_version
- << "\n See http://www.lyx.org/ for more information -->\n";
+ << "\n See https://www.lyx.org/ for more information -->\n";
// Directly output the root tag, based on the current type of document.
string languageCode = params().language->code();
// Generate the LaTeX file if neccessary
OutputParams runparams(¶ms().encoding());
- runparams.flavor = OutputParams::LATEX;
+ runparams.flavor = Flavor::LaTeX;
runparams.nice = false;
runparams.linelen = lyxrc.plaintext_linelen;
ExportStatus const retval =
if (!parent())
clearIncludeList();
- for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
+ for (InsetIterator it = begin(inset()); it; ++it) {
it->collectBibKeys(it, checkedFiles);
if (it->lyxCode() == BIBITEM_CODE) {
if (parent() != nullptr)
}
-void Buffer::addBiblioInfo(BiblioInfo const & bin) const
+void Buffer::addBiblioInfo(BiblioInfo const & bi_in) const
{
- // We add the biblio info to the master buffer,
- // if there is one, but also to every single buffer,
- // in case a child is compiled alone.
- BiblioInfo & bi = d->bibinfo_;
- bi.mergeBiblioInfo(bin);
+ // We add the biblio info to the parent buffer,
+ // if there is one, but also to this buffer, in case
+ // it is compiled alone.
+ BiblioInfo & our_bi = d->bibinfo_;
+ our_bi.mergeBiblioInfo(bi_in);
- if (parent() != nullptr) {
- BiblioInfo & masterbi = parent()->d->bibinfo_;
- masterbi.mergeBiblioInfo(bin);
- }
+ if (parent())
+ parent()->addBiblioInfo(bi_in);
}
docstring const oldname = from_utf8(func.getArg(0));
docstring const newname = from_utf8(func.getArg(1));
- InsetIterator it = inset_iterator_begin(inset());
- InsetIterator const end = inset_iterator_end(inset());
+ InsetIterator it = begin(inset());
+ InsetIterator const itend = end(inset());
bool success = false;
- for (; it != end; ++it) {
+ for (; it != itend; ++it) {
if (it->lyxCode() == BRANCH_CODE) {
InsetBranch & ins = static_cast<InsetBranch &>(*it);
if (ins.branch() == oldname) {
return ParConstIterator(doc_iterator_end(this));
}
+bool Buffer::empty() const
+{
+ return paragraphs().size() == 1 && paragraphs().front().empty();
+}
+
Language const * Buffer::language() const
{
for (auto const & insit : par.insetList()) {
it.pos() = insit.pos;
- switch (insit.inset->lyxCode()) {
// is it a nested text inset?
- case TEXT_CODE: {
- InsetText const * itext = insit.inset->asInsetText();
+ if (insit.inset->asInsetText()) {
// Inset needs its own scope?
+ InsetText const * itext = insit.inset->asInsetText();
bool newScope = itext->isMacroScope();
// scope which ends just behind the inset
it.push_back(CursorSlice(*insit.inset));
updateMacros(it, newScope ? insetScope : scope);
it.pop_back();
- break;
+ continue;
}
- case TABULAR_CODE: {
+
+ if (insit.inset->asInsetTabular()) {
CursorSlice slice(*insit.inset);
size_t const numcells = slice.nargs();
for (; slice.idx() < numcells; slice.forwardIdx()) {
updateMacros(it, scope);
it.pop_back();
}
- break;
+ continue;
}
+
// is it an external file?
- case INCLUDE_CODE: {
+ if (insit.inset->lyxCode() == INCLUDE_CODE) {
// get buffer of external file
InsetInclude const & incinset =
static_cast<InsetInclude const &>(*insit.inset);
Buffer * child = incinset.loadIfNeeded();
macro_lock = false;
if (!child)
- break;
+ continue;
// register its position, but only when it is
// included first in the buffer
// register child with its scope
position_to_children[it] = Impl::ScopeBuffer(scope, child);
- break;
- }
- case MATH_HULL_CODE: {
- if (!doing_export)
- break;
- InsetMathHull * hull = insit.inset->asInsetMath()->asHullInset();
- hull->recordLocation(it);
- break;
- }
- case MATHMACRO_CODE: {
- // get macro data
- InsetMathMacroTemplate & macroTemplate =
- *insit.inset->asInsetMath()->asMacroTemplate();
- MacroContext mc(owner_, it);
- macroTemplate.updateToContext(mc);
-
- // valid?
- bool valid = macroTemplate.validMacro();
- // FIXME: Should be fixNameAndCheckIfValid() in fact,
- // then the BufferView's cursor will be invalid in
- // some cases which leads to crashes.
- if (!valid)
- break;
-
- // register macro
- // FIXME (Abdel), I don't understand why we pass 'it' here
- // instead of 'macroTemplate' defined above... is this correct?
- macros[macroTemplate.name()][it] =
- Impl::ScopeMacro(scope, MacroData(owner_, it));
- break;
+ continue;
}
- default:
- break;
+
+ InsetMath * im = insit.inset->asInsetMath();
+ if (doing_export && im) {
+ InsetMathHull * hull = im->asHullInset();
+ if (hull)
+ hull->recordLocation(it);
}
+
+ if (insit.inset->lyxCode() != MATHMACRO_CODE)
+ continue;
+
+ // get macro data
+ InsetMathMacroTemplate & macroTemplate =
+ *insit.inset->asInsetMath()->asMacroTemplate();
+ MacroContext mc(owner_, it);
+ macroTemplate.updateToContext(mc);
+
+ // valid?
+ bool valid = macroTemplate.validMacro();
+ // FIXME: Should be fixNameAndCheckIfValid() in fact,
+ // then the BufferView's cursor will be invalid in
+ // some cases which leads to crashes.
+ if (!valid)
+ continue;
+
+ // register macro
+ // FIXME (Abdel), I don't understand why we pass 'it' here
+ // instead of 'macroTemplate' defined above... is this correct?
+ macros[macroTemplate.name()][it] =
+ Impl::ScopeMacro(scope, MacroData(const_cast<Buffer *>(owner_), it));
}
// next paragraph
void Buffer::getUsedBranches(std::list<docstring> & result, bool const from_master) const
{
- InsetIterator it = inset_iterator_begin(inset());
- InsetIterator const end = inset_iterator_end(inset());
- for (; it != end; ++it) {
- if (it->lyxCode() == BRANCH_CODE) {
- InsetBranch & br = static_cast<InsetBranch &>(*it);
+ for (Inset const & it : inset()) {
+ if (it.lyxCode() == BRANCH_CODE) {
+ InsetBranch const & br = static_cast<InsetBranch const &>(it);
docstring const name = br.branch();
if (!from_master && !params().branchlist().find(name))
result.push_back(name);
result.push_back(name);
continue;
}
- if (it->lyxCode() == INCLUDE_CODE) {
+ if (it.lyxCode() == INCLUDE_CODE) {
// get buffer of external file
InsetInclude const & ins =
- static_cast<InsetInclude const &>(*it);
+ static_cast<InsetInclude const &>(it);
Buffer * child = ins.loadIfNeeded();
if (!child)
continue;
continue;
// update macro in all cells of the InsetMathNest
- DocIterator::idx_type n = minset->nargs();
+ idx_type n = minset->nargs();
MacroContext mc = MacroContext(this, it);
- for (DocIterator::idx_type i = 0; i < n; ++i) {
+ for (idx_type i = 0; i < n; ++i) {
MathData & data = minset->cell(i);
data.updateMacros(nullptr, mc, utype, 0);
}
string const paramName = "key";
UndoGroupHelper ugh(this);
- InsetIterator it = inset_iterator_begin(inset());
+ InsetIterator it = begin(inset());
for (; it; ++it) {
if (it->lyxCode() != CITE_CODE)
continue;
// Some macros rely on font encoding
runparams.main_fontenc = params().main_font_encoding();
+ // Use the right wrapping for the comment at the beginning of the generated
+ // snippet, so that it is either valid LaTeX or valid XML (including HTML and DocBook).
+ docstring comment_start = from_ascii("% ");
+ docstring comment_end = from_ascii("");
+ if (runparams.flavor == Flavor::Html || runparams.flavor == Flavor::DocBook5) {
+ comment_start = from_ascii("<!-- ");
+ comment_end = from_ascii(" -->");
+ }
+
if (output == CurrentParagraph) {
runparams.par_begin = par_begin;
runparams.par_end = par_end;
if (par_begin + 1 == par_end) {
- os << "% "
+ os << comment_start
<< bformat(_("Preview source code for paragraph %1$d"), par_begin)
+ << comment_end
<< "\n\n";
} else {
- os << "% "
+ os << comment_start
<< bformat(_("Preview source code from paragraph %1$s to %2$s"),
convert<docstring>(par_begin),
convert<docstring>(par_end - 1))
+ << comment_end
<< "\n\n";
}
// output paragraphs
- if (runparams.flavor == OutputParams::LYX) {
+ if (runparams.flavor == Flavor::LyX) {
Paragraph const & par = text().paragraphs()[par_begin];
ostringstream ods;
depth_type dt = par.getDepth();
par.write(ods, params(), dt);
os << from_utf8(ods.str());
- } else if (runparams.flavor == OutputParams::HTML) {
+ } else if (runparams.flavor == Flavor::Html) {
XMLStream xs(os);
setMathFlavor(runparams);
xhtmlParagraphs(text(), *this, xs, runparams);
- } else if (runparams.flavor == OutputParams::TEXT) {
+ } else if (runparams.flavor == Flavor::Text) {
bool dummy = false;
// FIXME Handles only one paragraph, unlike the others.
// Probably should have some routine with a signature like them.
writePlaintextParagraph(*this,
text().paragraphs()[par_begin], os, runparams, dummy);
- } else if (runparams.flavor == OutputParams::DOCBOOK5) {
+ } else if (runparams.flavor == Flavor::DocBook5) {
XMLStream xs{os};
docbookParagraphs(text(), *this, xs, runparams);
} else {
d->ignore_parent = false;
}
} else {
- os << "% ";
+ os << comment_start;
if (output == FullSource)
os << _("Preview source code");
else if (output == OnlyPreamble)
os << _("Preview preamble");
else if (output == OnlyBody)
os << _("Preview body");
+ os << comment_end;
os << "\n\n";
- if (runparams.flavor == OutputParams::LYX) {
+ if (runparams.flavor == Flavor::LyX) {
ostringstream ods;
if (output == FullSource)
write(ods);
else if (output == OnlyBody)
text().write(ods);
os << from_utf8(ods.str());
- } else if (runparams.flavor == OutputParams::HTML) {
+ } else if (runparams.flavor == Flavor::Html) {
writeLyXHTMLSource(os, runparams, output);
- } else if (runparams.flavor == OutputParams::TEXT) {
- if (output == OnlyPreamble) {
+ } else if (runparams.flavor == Flavor::Text) {
+ if (output == OnlyPreamble)
os << "% "<< _("Plain text does not have a preamble.");
- } else
+ else
writePlaintextFile(*this, os, runparams);
- } else if (runparams.flavor == OutputParams::DOCBOOK5) {
+ } else if (runparams.flavor == Flavor::DocBook5) {
writeDocBookSource(os, runparams, output);
} else {
// latex or literate
}
MarkAsExporting exporting(this);
string backend_format;
- runparams.flavor = OutputParams::LATEX;
+ runparams.flavor = Flavor::LaTeX;
runparams.linelen = lyxrc.plaintext_linelen;
runparams.includeall = includeall;
vector<string> backs = params().backends();
LYXERR(Debug::FILES, "backend_format=" << backend_format);
// FIXME: Don't hardcode format names here, but use a flag
if (backend_format == "pdflatex")
- runparams.flavor = OutputParams::PDFLATEX;
+ runparams.flavor = Flavor::PdfLaTeX;
else if (backend_format == "luatex")
- runparams.flavor = OutputParams::LUATEX;
+ runparams.flavor = Flavor::LuaTeX;
else if (backend_format == "dviluatex")
- runparams.flavor = OutputParams::DVILUATEX;
+ runparams.flavor = Flavor::DviLuaTeX;
else if (backend_format == "xetex")
- runparams.flavor = OutputParams::XETEX;
+ runparams.flavor = Flavor::XeTeX;
}
string filename = latexName(false);
// Plain text backend
if (backend_format == "text") {
- runparams.flavor = OutputParams::TEXT;
+ runparams.flavor = Flavor::Text;
try {
writePlaintextFile(*this, FileName(filename), runparams);
}
}
// HTML backend
else if (backend_format == "xhtml") {
- runparams.flavor = OutputParams::HTML;
+ runparams.flavor = Flavor::Html;
setMathFlavor(runparams);
if (makeLyXHTMLFile(FileName(filename), runparams) == ExportKilled)
return ExportKilled;
writeFile(FileName(filename));
// DocBook backend
else if (backend_format == "docbook5") {
- runparams.flavor = OutputParams::DOCBOOK5;
+ runparams.flavor = Flavor::DocBook5;
runparams.nice = false;
if (makeDocBookFile(FileName(filename), runparams) == ExportKilled)
return ExportKilled;
}
else if (ins && ins->isSpace())
++blank_count_;
+ else if (ins) {
+ pair<int, int> words = ins->isWords();
+ char_count_ += words.first;
+ word_count_ += words.second;
+ inword = false;
+ }
else {
char_type const c = par.getChar(pos);
if (isPrintableNonspace(c))