From 83e7c2cff73797fa8f22a8f2cabef003679da10e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Matox?= Date: Wed, 7 Nov 2001 13:22:43 +0000 Subject: [PATCH] Improved support for docbook export in inset text. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2975 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 12 +++ src/buffer.C | 24 +++--- src/buffer.h | 30 ++++--- src/insets/ChangeLog | 8 +- src/insets/insettext.C | 179 ++++++++++++++++++++++++++++++++++++++++- 5 files changed, 220 insertions(+), 33 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6c9856c896..2fb5f37712 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2001-11-07 José Matos + + * buffer.h: + * buffer.C (sgmlError): linuxDocError renamed, and made public, added + const qualifier. + + * buffer.C (sgmlOpenTag): + * buffer.C (sgmlCloseTag): removed debug info. + + * buffer.h (sgmlOpenTag): + * buffer.h (sgmlCloseTag): made public. + 2001-11-07 Jean-Marc Lasgouttes * buffer.C (saveParamsAsDefaults): diff --git a/src/buffer.C b/src/buffer.C index edefcb7cdd..3455879be7 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -2509,8 +2509,8 @@ void Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth, string const & latexname) const { if (!latexname.empty() && latexname != "!-- --") - os << "" << "<" << latexname << ">"; - //os << string(depth, ' ') << "<" << latexname << ">\n"; + //os << "" << "<" << latexname << ">"; + os << string(depth, ' ') << "<" << latexname << ">\n"; } @@ -2518,8 +2518,8 @@ void Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth, string const & latexname) const { if (!latexname.empty() && latexname != "!-- --") - os << "" << "\n"; - //os << string(depth, ' ') << "\n"; + //os << "" << "\n"; + os << string(depth, ' ') << "\n"; } @@ -2616,9 +2616,9 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) case LATEX_COMMAND: if (depth!= 0) - linuxDocError(par, 0, - _("Error : Wrong depth for" - " LatexType Command.\n")); + sgmlError(par, 0, + _("Error : Wrong depth for" + " LatexType Command.\n")); if (!environment_stack[depth].empty()){ sgmlCloseTag(ofs, depth, @@ -2953,8 +2953,8 @@ void Buffer::simpleLinuxDocOnePar(ostream & os, // Print an error message. -void Buffer::linuxDocError(Paragraph * par, int pos, - string const & message) +void Buffer::sgmlError(Paragraph * par, int pos, + string const & message) const { // insert an error marker in text InsetError * new_inset = new InsetError(message); @@ -3080,9 +3080,9 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) case LATEX_COMMAND: if (depth != 0) - linuxDocError(par, 0, - _("Error : Wrong depth for " - "LatexType Command.\n")); + sgmlError(par, 0, + _("Error : Wrong depth for " + "LatexType Command.\n")); command_name = style.latexname(); diff --git a/src/buffer.h b/src/buffer.h index bcdef34b19..0e8bc1efad 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -167,9 +167,9 @@ public: void simpleDocBookOnePar(std::ostream &, string & extra, Paragraph * par, int & desc_on, Paragraph::depth_type depth) const ; - - /// - int runChktex(); + /// + void simpleLinuxDocOnePar(std::ostream & os, Paragraph * par, + Paragraph::depth_type depth); /// void makeLinuxDocFile(string const & filename, @@ -177,10 +177,21 @@ public: /// void makeDocBookFile(string const & filename, bool nice, bool only_body = false); + /// Open SGML/XML tag. + void sgmlOpenTag(std::ostream & os, Paragraph::depth_type depth, + string const & latexname) const; + /// Closes SGML/XML tag. + void sgmlCloseTag(std::ostream & os, Paragraph::depth_type depth, + string const & latexname) const; + /// + void sgmlError(Paragraph * par, int pos, + string const & message) const; /// returns the main language for the buffer (document) Language const * getLanguage() const; /// + int runChktex(); + /// bool isLyxClean() const; /// bool isBakClean() const; @@ -316,19 +327,6 @@ public: /// Used when typesetting to place errorboxes. TexRow texrow; private: - /// Open SGML/XML tag. - void sgmlOpenTag(std::ostream & os, Paragraph::depth_type depth, - string const & latexname) const; - /// Closes SGML/XML tag. - void sgmlCloseTag(std::ostream & os, Paragraph::depth_type depth, - string const & latexname) const; - /// - void linuxDocError(Paragraph * par, int pos, - string const & message); - /// - void simpleLinuxDocOnePar(std::ostream & os, Paragraph * par, - Paragraph::depth_type depth); - /// is save needed mutable bool lyx_clean; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 203649cb10..af1d16a7a9 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,6 +1,10 @@ -2001-11-03 José Matos +2001-11-07 José Matos - * /insetindex.C: added header file for std::ostream. + * insettext.C (docbook): full support for paragraphs inside insettext. + +2001-11-06 José Matos + + * insetindex.C: added header file for std::ostream. 2001-11-03 José Matos diff --git a/src/insets/insettext.C b/src/insets/insettext.C index fb3463d026..7c3b972e08 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -59,6 +59,7 @@ using std::endl; using std::min; using std::max; using std::make_pair; +using std::vector; extern unsigned char getCurrentTextClass(Buffer *); extern bool math_insert_greek(BufferView *, char); @@ -1364,12 +1365,184 @@ int InsetText::docbook(Buffer const * buf, ostream & os) const { Paragraph * p = par; unsigned int lines = 0; - int desc = 0; + + vector environment_stack(10); + vector environment_inner(10); + + int const command_depth = 0; + string item_name; - string tmp; + Paragraph::depth_type depth = 0; // paragraph depth + while (p) { - buf->simpleDocBookOnePar(os, tmp, p, desc, 0); + string sgmlparam; + int desc_on = 0; // description mode + + LyXLayout const & style = + textclasslist.Style(buf->params.textclass, + p->layout); + + // environment tag closing + for (; depth > p->params().depth(); --depth) { + if (environment_inner[depth] != "!-- --") { + item_name = "listitem"; + buf->sgmlCloseTag(os, command_depth + depth, + item_name); + if (environment_inner[depth] == "varlistentry") + buf->sgmlCloseTag(os, depth+command_depth, + environment_inner[depth]); + } + buf->sgmlCloseTag(os, depth + command_depth, + environment_stack[depth]); + environment_stack[depth].erase(); + environment_inner[depth].erase(); + } + + if (depth == p->params().depth() + && environment_stack[depth] != style.latexname() + && !environment_stack[depth].empty()) { + if (environment_inner[depth] != "!-- --") { + item_name= "listitem"; + buf->sgmlCloseTag(os, command_depth+depth, + item_name); + if (environment_inner[depth] == "varlistentry") + buf->sgmlCloseTag(os, + depth + command_depth, + environment_inner[depth]); + } + + buf->sgmlCloseTag(os, depth + command_depth, + environment_stack[depth]); + + environment_stack[depth].erase(); + environment_inner[depth].erase(); + } + + // Write opening SGML tags. + switch (style.latextype) { + case LATEX_PARAGRAPH: + buf->sgmlOpenTag(os, depth + command_depth, + style.latexname()); + break; + + case LATEX_COMMAND: + buf->sgmlError(p, 0, + _("Error : LatexType Command not allowed here.\n")); + return -1; + break; + + case LATEX_ENVIRONMENT: + case LATEX_ITEM_ENVIRONMENT: + if (depth < p->params().depth()) { + depth = p->params().depth(); + environment_stack[depth].erase(); + } + + if (environment_stack[depth] != style.latexname()) { + if(environment_stack.size() == depth + 1) { + environment_stack.push_back("!-- --"); + environment_inner.push_back("!-- --"); + } + environment_stack[depth] = style.latexname(); + environment_inner[depth] = "!-- --"; + buf->sgmlOpenTag(os, depth + command_depth, + environment_stack[depth]); + } else { + if (environment_inner[depth] != "!-- --") { + item_name= "listitem"; + buf->sgmlCloseTag(os, + command_depth + depth, + item_name); + if (environment_inner[depth] == "varlistentry") + buf->sgmlCloseTag(os, + depth + command_depth, + environment_inner[depth]); + } + } + + if (style.latextype == LATEX_ENVIRONMENT) { + if (!style.latexparam().empty()) { + if(style.latexparam() == "CDATA") + os << "sgmlOpenTag(os, depth + command_depth, + style.latexparam()); + } + break; + } + + desc_on = (style.labeltype == LABEL_MANUAL); + + if (desc_on) + environment_inner[depth]= "varlistentry"; + else + environment_inner[depth]= "listitem"; + + buf->sgmlOpenTag(os, depth + 1 + command_depth, + environment_inner[depth]); + + if (desc_on) { + item_name= "term"; + buf->sgmlOpenTag(os, depth + 1 + command_depth, + item_name); + } else { + item_name= "para"; + buf->sgmlOpenTag(os, depth + 1 + command_depth, + item_name); + } + break; + default: + buf->sgmlOpenTag(os, depth + command_depth, + style.latexname()); + break; + } + + string extra_par; + buf->simpleDocBookOnePar(os, extra_par, p, desc_on, + depth + 1 + command_depth); p = p->next(); + + string end_tag; + // write closing SGML tags + switch (style.latextype) { + case LATEX_ENVIRONMENT: + if (!style.latexparam().empty()) { + if(style.latexparam() == "CDATA") + os << "]]>"; + else + buf->sgmlCloseTag(os, depth + command_depth, + style.latexparam()); + } + break; + case LATEX_ITEM_ENVIRONMENT: + if (desc_on == 1) break; + end_tag= "para"; + buf->sgmlCloseTag(os, depth + 1 + command_depth, end_tag); + break; + case LATEX_PARAGRAPH: + buf->sgmlCloseTag(os, depth + command_depth, style.latexname()); + break; + default: + buf->sgmlCloseTag(os, depth + command_depth, style.latexname()); + break; + } + } + + // Close open tags + for (int d = depth; d >= 0; --d) { + if (!environment_stack[depth].empty()) { + if (environment_inner[depth] != "!-- --") { + item_name = "listitem"; + buf->sgmlCloseTag(os, command_depth + depth, + item_name); + if (environment_inner[depth] == "varlistentry") + buf->sgmlCloseTag(os, depth + command_depth, + environment_inner[depth]); + } + + buf->sgmlCloseTag(os, depth + command_depth, + environment_stack[depth]); + } } return lines; -- 2.39.2