From: José Matox Date: Sun, 24 Oct 2004 23:53:42 +0000 (+0000) Subject: Fix description paragraph. (docbook) X-Git-Tag: 1.6.10~14913 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=b6263feca727aaf2ee25c2b8075566efc77f29fa;p=features.git Fix description paragraph. (docbook) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9119 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index 74e1b5cdfc..f1a5b67bd1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2004-10-24 José Matos + + * 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 * buffer.C (makeLinuxDocFile, makeDocBookFile): diff --git a/src/output_docbook.C b/src/output_docbook.C index 1e2862cbf0..62822e35aa 100644 --- a/src/output_docbook.C +++ b/src/output_docbook.C @@ -28,10 +28,12 @@ #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; @@ -107,8 +109,7 @@ ParagraphList::const_iterator makeParagraph(Buffer const & buf, 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'; } @@ -143,6 +144,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, string id = ""; ParagraphList::const_iterator send; string wrapper = ""; + pos_type sep = 0; // Opening inner tag switch (bstyle->latextype) { @@ -154,11 +156,13 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, 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; } @@ -168,7 +172,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, 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; } @@ -196,6 +200,8 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, 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; @@ -255,8 +261,7 @@ ParagraphList::const_iterator makeCommand(Buffer const & buf, // 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()); diff --git a/src/paragraph.C b/src/paragraph.C index fce394073b..72d7358303 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1347,42 +1347,62 @@ string Paragraph::getDocbookId() const } +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 tag if (font_old.emph() != font.emph()) { if (font.emph() == LyXFont::ON) { - if (style->latexparam() == "CDATA") + if (cdata) os << "]]>"; os << ""; - if (style->latexparam() == "CDATA") + if (cdata) os << "latexparam() == "CDATA") + } else if (i != initial) { + if (cdata) os << "]]>"; os << ""; - if (style->latexparam() == "CDATA") + if (cdata) os << "latexparam() == "CDATA") + if (cdata) os << "]]>"; inset->docbook(buf, os, runparams); - if (style->latexparam() == "CDATA") + if (cdata) os << "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 << "\nlabeltag() << "><" - << 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 << ""; - if (style->latexparam() == "CDATA") + if (cdata) os << " not closed... - os << "labeltag() << ">\n<" - << style->itemtag() << "><" - << defaultstyle->latexname() << "> "; - } if (style->free_spacing) os << '\n'; } diff --git a/src/paragraph.h b/src/paragraph.h index ded4888a95..f937fdbd07 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -132,12 +132,17 @@ public: /// 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;