+2004-10-24 José Matos <jamatos@lyx.org>
+
+ * paragraph.[Ch] (getFirstWord): new function to get the first
+ word. Useful for description.
+ (simpleDocBookOnePar): remove depth argument, add another that
+ says where to start the paragraph.
+
+ * output_docbook.C (makeParagraph, makeEnvironment, makeCommand):
+ use the new functions to fix cleanly the support for descriptions.
+
2004-10-24 José Matos <jamatos@lyx.org>
* buffer.C (makeLinuxDocFile, makeDocBookFile):
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/tostr.h"
+#include "support/types.h"
#ifdef HAVE_LOCALE
#endif
+using lyx::pos_type;
using lyx::support::subst;
using std::endl;
id = id.empty()? "": " id = \"" + id + "\"";
sgml::openTag(buf, os, depth, true, style->latexname(), id);
- par->simpleDocBookOnePar(buf, os, outerFont(par - paragraphs.begin(), paragraphs), runparams, depth);
-
+ par->simpleDocBookOnePar(buf, os, runparams, outerFont(par - paragraphs.begin(), paragraphs));
sgml::closeTag(os, depth, true, style->latexname());
os << '\n';
}
string id = "";
ParagraphList::const_iterator send;
string wrapper = "";
+ pos_type sep = 0;
// Opening inner tag
switch (bstyle->latextype) {
case LATEX_ITEM_ENVIRONMENT:
if (!bstyle->labeltag().empty()) {
+ sgml::openTag(buf, os, depth, true, bstyle->innertag());
sgml::openTag(buf, os, depth, true, bstyle->labeltag());
- } else {
- wrapper = defaultstyle->latexname();
- sgml::openTag(buf, os, depth, true, bstyle->itemtag());
+ sep = par->getFirstWord(buf, os, runparams) + 1;
+ sgml::closeTag(os, depth, true, bstyle->labeltag());
}
+ wrapper = defaultstyle->latexname();
+ sgml::openTag(buf, os, depth, true, bstyle->itemtag());
default:
break;
}
case LATEX_ITEM_ENVIRONMENT: {
if(par->params().depth() == pbegin->params().depth()) {
sgml::openTag(buf, os, depth, true, wrapper, id);
- par->simpleDocBookOnePar(buf, os, outerFont(par - paragraphs.begin(), paragraphs), runparams, depth);
+ par->simpleDocBookOnePar(buf, os, runparams, outerFont(par - paragraphs.begin(), paragraphs), sep);
sgml::closeTag(os, depth, true, wrapper);
++par;
}
break;
case LATEX_ITEM_ENVIRONMENT:
sgml::closeTag(os, depth, true, bstyle->itemtag());
+ if (!bstyle->labeltag().empty())
+ sgml::closeTag(os, depth, true, bstyle->innertag());
break;
default:
break;
// Opend inner tag
sgml::openTag(buf, os, depth, true, bstyle->innertag());
- par->simpleDocBookOnePar(buf, os, outerFont(par - paragraphs.begin(), paragraphs),
- runparams, depth);
+ par->simpleDocBookOnePar(buf, os, runparams, outerFont(par - paragraphs.begin(), paragraphs));
// Close inner tags
sgml::closeTag(os, depth, true, bstyle->innertag());
}
+pos_type Paragraph::getFirstWord(Buffer const & buf, ostream & os, OutputParams const & runparams) const
+{
+ pos_type i;
+ LyXLayout_ptr const & style = layout();
+ for (i = 0; i < size(); ++i) {
+ if (isInset(i)) {
+ InsetBase const * inset = getInset(i);
+ inset->docbook(buf, os, runparams);
+ } else {
+ char c = getChar(i);
+ if (c == ' ')
+ break;
+ bool ws;
+ string str;
+ boost::tie(ws, str) = sgml::escapeChar(c);
+
+ if (style->pass_thru)
+ os << c;
+ else
+ os << str;
+ }
+ }
+ return i;
+}
+
void Paragraph::simpleDocBookOnePar(Buffer const & buf,
ostream & os,
- LyXFont const & outerfont,
OutputParams const & runparams,
- lyx::depth_type depth) const
+ LyXFont const & outerfont,
+ pos_type initial) const
{
bool emph_flag = false;
- int char_line_count = 0;
LyXLayout_ptr const & style = layout();
- LyXLayout_ptr const & defaultstyle =
- buf.params().getLyXTextClass().defaultLayout();
-
LyXFont font_old =
style->labeltype == LABEL_MANUAL ? style->labelfont : style->font;
- bool label_closed = true;
-
+ bool cdata = (style->latexparam() == "CDATA");
// parsing main loop
- for (pos_type i = 0; i < size(); ++i) {
+ for (pos_type i = initial; i < size(); ++i) {
LyXFont font = getFont(buf.params(), i, outerfont);
// handle <emphasis> tag
if (font_old.emph() != font.emph()) {
if (font.emph() == LyXFont::ON) {
- if (style->latexparam() == "CDATA")
+ if (cdata)
os << "]]>";
os << "<emphasis>";
- if (style->latexparam() == "CDATA")
+ if (cdata)
os << "<![CDATA[";
emph_flag = true;
- } else if (i) {
- if (style->latexparam() == "CDATA")
+ } else if (i != initial) {
+ if (cdata)
os << "]]>";
os << "</emphasis>";
- if (style->latexparam() == "CDATA")
+ if (cdata)
os << "<![CDATA[";
emph_flag = false;
}
if (isInset(i)) {
InsetBase const * inset = getInset(i);
- if (style->latexparam() == "CDATA")
+ if (cdata)
os << "]]>";
inset->docbook(buf, os, runparams);
- if (style->latexparam() == "CDATA")
+ if (cdata)
os << "<![CDATA[";
} else {
char c = getChar(i);
string str;
boost::tie(ws, str) = sgml::escapeChar(c);
- if (style->pass_thru) {
+ if (style->pass_thru)
os << c;
- } else if (isFreeSpacing() || c != ' ') {
- os << str;
- } else if (!style->labeltag().empty() && !label_closed) {
- ++char_line_count;
- os << "\n</" << style->labeltag() << "><"
- << style->itemtag() << "><"
- << defaultstyle->latexname() << ">";
- label_closed = true;
- } else {
- os << ' ';
- }
+ else
+ os << str;
}
font_old = font;
}
if (emph_flag) {
- if (style->latexparam() == "CDATA")
+ if (cdata)
os << "]]>";
os << "</emphasis>";
- if (style->latexparam() == "CDATA")
+ if (cdata)
os << "<![CDATA[";
}
- // resets description flag correctly
- if (!label_closed) {
- // <term> not closed...
- os << "</" << style->labeltag() << ">\n<"
- << style->itemtag() << "><"
- << defaultstyle->latexname() << "> ";
- }
if (style->free_spacing)
os << '\n';
}
/// Get the id of the paragraph, usefull for docbook
std::string getDocbookId() const;
- ///
+ // Get the first word of a paragraph, return the position where it left
+ lyx::pos_type getFirstWord(Buffer const & buf,
+ std::ostream & os,
+ OutputParams const & runparams) const;
+
+ /// Writes to stream the docbook representation
void simpleDocBookOnePar(Buffer const & buf,
std::ostream &,
- LyXFont const & outerfont,
OutputParams const & runparams,
- lyx::depth_type depth) const;
+ LyXFont const & outerfont,
+ lyx::pos_type initial = 0) const;
///
bool hasSameLayout(Paragraph const & par) const;