On Mon, Nov 17, 2003 at 11:16:57PM +0200, Martin Vermeer spake thusly:
 
> My primary objective with this is to parametrize the docbook list code
> by moving stuff from LyX to the .layout files. (Yes, this makes them a
> little messier looking right now. Doesn't bother the end user nor the 
> LaTeX-only user.) 
> 
> This is not finished yet: inside simpleDocBookOnePar there is the
> listitem/para stuff still irritatingly hardwired. (In AGU this takes
> the form <item><p>.)

Here is the slightly improved version. Now also listitem/para inside
simpleDocBookOnePar is fully parametrized: it takes the default layout
name (para for docbook, p for AGU) to build the innermost tags in list
items. I suspect this must be generally valid (?)

Does this more clearly illustrate the idea?

Check-in later today, shout to object ;-)

- Martin

-- 
Martin Vermeer  [EMAIL PROTECTED]
Helsinki University of Technology 
Dept. of Surveying, Inst. of Geodesy
P.O. Box 1200, FIN-02015 HUT, Finland
:wq
Index: lib/layouts/db_stdlists.inc
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/layouts/db_stdlists.inc,v
retrieving revision 1.4
diff -u -p -r1.4 db_stdlists.inc
--- lib/layouts/db_stdlists.inc 15 Sep 2003 15:20:18 -0000      1.4
+++ lib/layouts/db_stdlists.inc 18 Nov 2003 08:27:06 -0000
@@ -11,18 +11,23 @@ Input stdlists.inc
 Style Itemize
        LatexType             Item_Environment
        LatexName             itemizedlist
+       ItemTag               listitem
 End
 
 
 Style Enumerate
        LatexType             Item_Environment
        LatexName             orderedlist
+       ItemTag               listitem
 End
 
 
 Style Description
        LatexType             Item_environment
        LatexName             variablelist
+       InnerTag              varlistentry
+       LabelTag              term
+       ItemTag               listitem
 End
 
 # maybe List is the same as simplelist (I need to check it).
Index: src/lyxlayout.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxlayout.C,v
retrieving revision 1.23
diff -u -p -r1.23 lyxlayout.C
--- src/lyxlayout.C     14 Nov 2003 14:05:03 -0000      1.23
+++ src/lyxlayout.C     18 Nov 2003 08:27:06 -0000
@@ -82,6 +82,8 @@ enum LayoutTags {
        LT_TOPSEP,
        LT_TOCLEVEL,
        LT_INNERTAG,
+       LT_LABELTAG,
+       LT_ITEMTAG,
        LT_INTITLE // keep this last!
 };
 
@@ -145,6 +147,7 @@ bool LyXLayout::Read(LyXLex & lexrc, LyX
                { "innertag",       LT_INNERTAG },
                { "intitle",        LT_INTITLE },
                { "itemsep",        LT_ITEMSEP },
+               { "itemtag",        LT_ITEMTAG },
                { "keepempty",      LT_KEEPEMPTY },
                { "labelbottomsep", LT_LABEL_BOTTOMSEP },
                { "labelcounter",   LT_LABELCOUNTER },
@@ -153,6 +156,7 @@ bool LyXLayout::Read(LyXLex & lexrc, LyX
                { "labelsep",       LT_LABELSEP },
                { "labelstring",    LT_LABELSTRING },
                { "labelstringappendix", LT_LABELSTRING_APPENDIX },
+               { "labeltag",       LT_LABELTAG },
                { "labeltype",      LT_LABELTYPE },
                { "latexfooter",    LT_LATEXFOOTER },
                { "latexheader",    LT_LATEXHEADER },
@@ -337,6 +341,16 @@ bool LyXLayout::Read(LyXLex & lexrc, LyX
                case LT_INNERTAG:
                        if (lexrc.next())
                                innertag_ = lexrc.getString();
+                       break;
+
+               case LT_LABELTAG:
+                       if (lexrc.next())
+                               labeltag_ = lexrc.getString();
+                       break;
+
+               case LT_ITEMTAG:
+                       if (lexrc.next())
+                               itemtag_ = lexrc.getString();
                        break;
 
                case LT_PREAMBLE:
Index: src/lyxlayout.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxlayout.h,v
retrieving revision 1.17
diff -u -p -r1.17 lyxlayout.h
--- src/lyxlayout.h     14 Nov 2003 14:05:03 -0000      1.17
+++ src/lyxlayout.h     18 Nov 2003 08:27:06 -0000
@@ -65,6 +65,10 @@ public:
        ///
        std::string const & innertag() const { return innertag_; }
        ///
+       std::string const & labeltag() const { return labeltag_; }
+       ///
+       std::string const & itemtag() const { return itemtag_; }
+       ///
        std::string const & labelstring_appendix() const {
                return labelstring_appendix_;
        }
@@ -211,6 +215,10 @@ private:
        std::string latexparam_;
        /// Internal tag to use (e.g., <title></title> for sect header)
        std::string innertag_;
+       /// Internal tag to use e.g. to surround varlistentry label)
+       std::string labeltag_;
+       /// Internal tag to surround the item text in a list)
+       std::string itemtag_;
        /// Macro definitions needed for this layout
        std::string preamble_;
 };
Index: src/output_docbook.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/output_docbook.C,v
retrieving revision 1.2
diff -u -p -r1.2 output_docbook.C
--- src/output_docbook.C        14 Nov 2003 14:05:03 -0000      1.2
+++ src/output_docbook.C        18 Nov 2003 08:27:06 -0000
@@ -57,20 +57,20 @@ void docbookParagraphs(Buffer const & bu
 
        string command_name;
 
+       string item_tag;
+
        ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
        ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
 
        for (; par != pend; ++par) {
-               string inner_tag;
                int desc_on = 0; // description mode
 
                LyXLayout_ptr const & style = par->layout();
 
                // environment tag closing
                for (; depth > par->params().depth(); --depth) {
-                       if (!environment_inner[depth].empty()) 
                        sgml::closeEnvTags(os, false, environment_inner[depth], 
-                                       command_depth + depth);
+                               item_tag, command_depth + depth);
                        sgml::closeTag(os, depth + command_depth, false, 
environment_stack[depth]);
                        environment_stack[depth].erase();
                        environment_inner[depth].erase();
@@ -80,15 +80,14 @@ void docbookParagraphs(Buffer const & bu
                   && environment_stack[depth] != style->latexname()
                   && !environment_stack[depth].empty()) {
                                sgml::closeEnvTags(os, false, 
environment_inner[depth], 
-                                       command_depth + depth);
+                                       item_tag, command_depth + depth);
                        sgml::closeTag(os, depth + command_depth, false, 
environment_stack[depth]);
 
                        environment_stack[depth].erase();
                        environment_inner[depth].erase();
                }
-
+               
                // Write opening SGML tags.
-               string item_name;
                switch (style->latextype) {
                case LATEX_PARAGRAPH:
                        sgml::openTag(os, depth + command_depth,
@@ -103,7 +102,6 @@ void docbookParagraphs(Buffer const & bu
                        command_name = style->latexname();
 
                        cmd_depth = style->commanddepth;
-                       inner_tag = style->innertag();
                        
                        if (command_flag) {
                                if (cmd_depth < command_base) {
@@ -147,7 +145,8 @@ void docbookParagraphs(Buffer const & bu
 
                        sgml::openTag(os, depth + command_depth, false, command_name);
                        // Inner tagged header text, e.g. <title> for sectioning:
-                       sgml::openTag(os, depth + 1 + command_depth, false, inner_tag);
+                       sgml::openTag(os, depth + 1 + command_depth, false, 
+                               style->innertag());
                        break;
 
                case LATEX_ENVIRONMENT:
@@ -166,8 +165,8 @@ void docbookParagraphs(Buffer const & bu
                                environment_inner[depth] = "!-- --";
                                sgml::openTag(os, depth + command_depth, false, 
environment_stack[depth]);
                        } else {
-                                       sgml::closeEnvTags(os, false, 
environment_inner[depth], 
-                                               command_depth + depth);
+                               sgml::closeEnvTags(os, false, 
environment_inner[depth], 
+                                       style->itemtag(), command_depth + depth);
                        }
 
                        if (style->latextype == LATEX_ENVIRONMENT) {
@@ -182,13 +181,11 @@ void docbookParagraphs(Buffer const & bu
 
                        desc_on = (style->labeltype == LABEL_MANUAL);
 
-                       environment_inner[depth] = desc_on ? "varlistentry" : 
"listitem";
-                       sgml::openTag(os, depth + 1 + command_depth,
-                                   false, environment_inner[depth]);
+                       environment_inner[depth] = style->innertag();
 
-                       item_name = desc_on ? "term" : "para";
-                       sgml::openTag(os, depth + 1 + command_depth,
-                                   false, item_name);
+                       if (!environment_inner[depth].empty())
+                               sgml::openTag(os, depth + 1 + command_depth,
+                                   false, environment_inner[depth]);
                        break;
                default:
                        sgml::openTag(os, depth + command_depth,
@@ -199,11 +196,11 @@ void docbookParagraphs(Buffer const & bu
                par->simpleDocBookOnePar(buf, os, outerFont(par, paragraphs), desc_on,
                                         runparams, depth + 1 + command_depth);
 
-               string end_tag;
                // write closing SGML tags
                switch (style->latextype) {
                case LATEX_COMMAND:
-                       sgml::closeTag(os, depth + command_depth, false, inner_tag);
+                       sgml::closeTag(os, depth + command_depth, false, 
+                               style->innertag());
                        break;
                case LATEX_ENVIRONMENT:
                        if (!style->latexparam().empty()) {
@@ -214,9 +211,7 @@ void docbookParagraphs(Buffer const & bu
                        }
                        break;
                case LATEX_ITEM_ENVIRONMENT:
-                       if (desc_on == 1) break;
-                       end_tag = "para";
-                       sgml::closeTag(os, depth + 1 + command_depth, false, end_tag);
+                       item_tag = style->itemtag();
                        break;
                case LATEX_PARAGRAPH:
                        sgml::closeTag(os, depth + command_depth, false, 
style->latexname());
@@ -231,7 +226,7 @@ void docbookParagraphs(Buffer const & bu
        for (int d = depth; d >= 0; --d) {
                if (!environment_stack[depth].empty()) {
                                sgml::closeEnvTags(os, false, 
environment_inner[depth], 
-                                       command_depth + depth);
+                                       item_tag, command_depth + depth);
                }
        }
 
Index: src/paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.344
diff -u -p -r1.344 paragraph.C
--- src/paragraph.C     13 Nov 2003 13:43:38 -0000      1.344
+++ src/paragraph.C     18 Nov 2003 08:27:06 -0000
@@ -1334,12 +1334,28 @@ void Paragraph::simpleDocBookOnePar(Buff
        bool emph_flag = false;
 
        LyXLayout_ptr const & style = layout();
+       LyXLayout_ptr const & defaultstyle 
+               = buf.params().getLyXTextClass().defaultLayout();
 
        LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : 
style->font);
 
        int char_line_count = depth;
-       //if (!style.free_spacing)
-       //      os << string(depth,' ');
+       bool label_closed = true;
+       bool para_closed = true;
+       
+       if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
+               if (!style->free_spacing)
+                       os << string(depth,' ');
+               if (!style->labeltag().empty()) {
+                       os << "<" << style->labeltag() << ">\n";
+                       label_closed = false;
+               } else {
+                       os << "<" << style->itemtag() << ">\n" 
+                          << string(depth, ' ') << "<" 
+                          << defaultstyle->latexname() << ">\n";
+                       para_closed = false;
+               }
+       }
 
        // parsing main loop
        for (pos_type i = 0; i < size(); ++i) {
@@ -1385,10 +1401,13 @@ void Paragraph::simpleDocBookOnePar(Buff
                                os << c;
                        } else if (isFreeSpacing() || c != ' ') {
                                        os << str;
-                       } else if (desc_on == 1) {
+                       } else if (!style->labeltag().empty() && !label_closed) {
                                ++char_line_count;
-                               os << "\n</term><listitem><para>";
-                               desc_on = 2;
+                               os << "\n</" << style->labeltag() << "><" 
+                                  << style->itemtag() << "><" 
+                                  << defaultstyle->latexname() << ">";
+                               label_closed = true;
+                               para_closed = false;
                        } else {
                                os << ' ';
                        }
@@ -1405,9 +1424,15 @@ void Paragraph::simpleDocBookOnePar(Buff
        }
 
        // resets description flag correctly
-       if (desc_on == 1) {
+       if (!label_closed) {
                // <term> not closed...
-               os << "</term>\n<listitem><para>&nbsp;</para>";
+               os << "</" << style->labeltag() << ">\n<" 
+                  << style->itemtag() << "><" 
+                  << defaultstyle->latexname() << ">&nbsp;";
+       }
+       if (!para_closed) {
+               os << "\n" << string(depth, ' ') << "</" 
+                  << defaultstyle->latexname() << ">\n";
        }
        if (style->free_spacing)
                os << '\n';
Index: src/sgml.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/sgml.C,v
retrieving revision 1.12
diff -u -p -r1.12 sgml.C
--- src/sgml.C  29 Oct 2003 19:19:23 -0000      1.12
+++ src/sgml.C  18 Nov 2003 08:27:06 -0000
@@ -118,13 +118,13 @@ int closeTag(ostream & os, Paragraph::de
 
 unsigned int closeEnvTags(ostream & ofs, bool mixcont,
                        string const & environment_inner_depth,
+                       string const & itemtag,
                        lyx::depth_type total_depth)
 {
        unsigned int lines;
        if (environment_inner_depth != "!-- --") {
-               string item_name= "listitem";
-               lines += closeTag(ofs, total_depth, mixcont, item_name);
-               if (environment_inner_depth == "varlistentry")
+               lines += closeTag(ofs, total_depth, mixcont, itemtag);
+               if (!environment_inner_depth.empty())
                        lines += closeTag(ofs, total_depth, mixcont,
                                environment_inner_depth);
        }
Index: src/sgml.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/sgml.h,v
retrieving revision 1.10
diff -u -p -r1.10 sgml.h
--- src/sgml.h  29 Oct 2003 13:48:18 -0000      1.10
+++ src/sgml.h  18 Nov 2003 08:27:06 -0000
@@ -39,6 +39,7 @@ int closeTag(std::ostream & os, lyx::dep
 unsigned int closeEnvTags(std::ostream & os, 
                bool mixcont,
                std::string const & environment_inner_depth,
+               std::string const & item_tag,
                lyx::depth_type total_depth);
 
 }

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to