XML sanitation

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8087 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Martin Vermeer 2003-11-14 14:05:03 +00:00
parent 4e132eecef
commit 93ea4edddf
7 changed files with 110 additions and 73 deletions

View File

@ -1,3 +1,9 @@
2003-11-14 Martin Vermeer <martin.vermeer@hut.fi>
* layouts/db_stdsections.inc:
* layouts/db_stdtitle.inc: XML sanitation: new layout
parameters InnerTag and CommandDepth
2003-11-13 Angus Leeming <leeming@lyx.org>
* CREDITS: added Ling Li.

View File

@ -1,8 +1,9 @@
# Textclass definition file for docbook.
# Author : José Abílio Oliveira Matos <jamatos@lyx.org>
# Modified by Martin Vermeer <martin.vermeer@hut.fi>
# This file is the counterpart of stdsections.inc
# It is desireable, as far as possible, to have the same look and feeling for
# It is desirable, as far as possible, to have the same look and feel for
# related layouts in latex and docbook.
Input stdsections.inc
@ -10,47 +11,55 @@ Input stdsections.inc
Style Part
LatexType Command
LatexName part
LatexParam "0|"
InnerTag "title"
CommandDepth 0
End
Style Chapter
LatexType Command
LatexName chapter
LatexParam "1|"
InnerTag "title"
CommandDepth 1
End
Style Section
LatexType Command
LatexName sect1
LatexParam "2|"
InnerTag "title"
CommandDepth 2
End
Style Subsection
LatexType Command
LatexName sect2
LatexParam "3|"
InnerTag "title"
CommandDepth 3
End
Style Subsubsection
LatexType Command
LatexName sect3
LatexParam "4|"
InnerTag "title"
CommandDepth 4
End
Style Paragraph
LatexType Command
LatexName sect4
LatexParam "5|"
InnerTag "title"
CommandDepth 5
End
Style Subparagraph
LatexType Command
LatexName sect5
LatexParam "6|"
InnerTag "title"
CommandDepth 6
End

View File

@ -1,8 +1,9 @@
# Textclass definition file for docbook.
# Author : José Abílio Oliveira Matos <jamatos@lyx.org>
# This file is the counterpart of stdstile.inc
# It is desireable, as far as possible, to have the same look and feeling for
# Modified Martin Vermeer <martin.vermeer@hut.fi>
#
# This file is the counterpart of stdstyle.inc
# It is desirable, as far as possible, to have the same look and feel for
# related layouts in latex and docbook.
Input stdtitle.inc
@ -11,7 +12,8 @@ Input stdtitle.inc
Style Title
LatexType Command
LatexName articleinfo
LatexParam "2|"
CommandDepth 2
InnerTag "title"
End

View File

@ -1,3 +1,9 @@
2003-11-14 Martin Vermeer <martin.vermeer@hut.fi>
* lyxlayout.[Ch]:
* output_docbook.C: XML sanitation: new layout
parameters InnerTag and CommandDepth
2003-11-13 Martin Vermeer <martin.vermeer@hut.fi>
* BufferView_pimpl.C:

View File

@ -33,6 +33,7 @@ enum LayoutTags {
LT_ALIGNPOSSIBLE,
LT_MARGIN,
LT_BOTTOMSEP,
LT_COMMANDDEPTH,
LT_COPYSTYLE,
LT_DEPENDSON,
LT_OBSOLETEDBY,
@ -80,7 +81,8 @@ enum LayoutTags {
LT_SPACING,
LT_TOPSEP,
LT_TOCLEVEL,
LT_INTITLE
LT_INNERTAG,
LT_INTITLE // keep this last!
};
/////////////////////
@ -118,6 +120,7 @@ LyXLayout::LyXLayout ()
pass_thru = false;
is_environment = false;
toclevel = 0;
commanddepth = 0;
}
@ -126,52 +129,54 @@ bool LyXLayout::Read(LyXLex & lexrc, LyXTextClass const & tclass)
{
// This table is sorted alphabetically [asierra 30March96]
keyword_item layoutTags[] = {
{ "align", LT_ALIGN },
{ "alignpossible", LT_ALIGNPOSSIBLE },
{ "bottomsep", LT_BOTTOMSEP },
{ "copystyle", LT_COPYSTYLE },
{ "dependson", LT_DEPENDSON },
{ "end", LT_END },
{ "endlabelstring", LT_ENDLABELSTRING },
{ "endlabeltype", LT_ENDLABELTYPE },
{ "fill_bottom", LT_FILL_BOTTOM },
{ "fill_top", LT_FILL_TOP },
{ "font", LT_FONT },
{ "freespacing", LT_FREE_SPACING },
{ "intitle", LT_INTITLE },
{ "itemsep", LT_ITEMSEP },
{ "keepempty", LT_KEEPEMPTY },
{ "labelbottomsep", LT_LABEL_BOTTOMSEP },
{ "labelcounter", LT_LABELCOUNTER },
{ "labelfont", LT_LABELFONT },
{ "labelindent", LT_LABELINDENT },
{ "labelsep", LT_LABELSEP },
{ "labelstring", LT_LABELSTRING },
{ "align", LT_ALIGN },
{ "alignpossible", LT_ALIGNPOSSIBLE },
{ "bottomsep", LT_BOTTOMSEP },
{ "commanddepth", LT_COMMANDDEPTH },
{ "copystyle", LT_COPYSTYLE },
{ "dependson", LT_DEPENDSON },
{ "end", LT_END },
{ "endlabelstring", LT_ENDLABELSTRING },
{ "endlabeltype", LT_ENDLABELTYPE },
{ "fill_bottom", LT_FILL_BOTTOM },
{ "fill_top", LT_FILL_TOP },
{ "font", LT_FONT },
{ "freespacing", LT_FREE_SPACING },
{ "innertag", LT_INNERTAG },
{ "intitle", LT_INTITLE },
{ "itemsep", LT_ITEMSEP },
{ "keepempty", LT_KEEPEMPTY },
{ "labelbottomsep", LT_LABEL_BOTTOMSEP },
{ "labelcounter", LT_LABELCOUNTER },
{ "labelfont", LT_LABELFONT },
{ "labelindent", LT_LABELINDENT },
{ "labelsep", LT_LABELSEP },
{ "labelstring", LT_LABELSTRING },
{ "labelstringappendix", LT_LABELSTRING_APPENDIX },
{ "labeltype", LT_LABELTYPE },
{ "latexfooter", LT_LATEXFOOTER },
{ "latexheader", LT_LATEXHEADER },
{ "latexname", LT_LATEXNAME },
{ "latexparagraph", LT_LATEXPARAGRAPH },
{ "latexparam", LT_LATEXPARAM },
{ "latextype", LT_LATEXTYPE },
{ "leftmargin", LT_LEFTMARGIN },
{ "margin", LT_MARGIN },
{ "needprotect", LT_NEED_PROTECT },
{ "newline", LT_NEWLINE },
{ "nextnoindent", LT_NEXTNOINDENT },
{ "obsoletedby", LT_OBSOLETEDBY },
{ "optionalargs", LT_OPTARGS },
{ "parindent", LT_PARINDENT },
{ "parsep", LT_PARSEP },
{ "parskip", LT_PARSKIP },
{ "passthru", LT_PASS_THRU },
{ "preamble", LT_PREAMBLE },
{ "rightmargin", LT_RIGHTMARGIN },
{ "spacing", LT_SPACING },
{ "textfont", LT_TEXTFONT },
{ "toclevel", LT_TOCLEVEL },
{ "topsep", LT_TOPSEP }
{ "labeltype", LT_LABELTYPE },
{ "latexfooter", LT_LATEXFOOTER },
{ "latexheader", LT_LATEXHEADER },
{ "latexname", LT_LATEXNAME },
{ "latexparagraph", LT_LATEXPARAGRAPH },
{ "latexparam", LT_LATEXPARAM },
{ "latextype", LT_LATEXTYPE },
{ "leftmargin", LT_LEFTMARGIN },
{ "margin", LT_MARGIN },
{ "needprotect", LT_NEED_PROTECT },
{ "newline", LT_NEWLINE },
{ "nextnoindent", LT_NEXTNOINDENT },
{ "obsoletedby", LT_OBSOLETEDBY },
{ "optionalargs", LT_OPTARGS },
{ "parindent", LT_PARINDENT },
{ "parsep", LT_PARSEP },
{ "parskip", LT_PARSKIP },
{ "passthru", LT_PASS_THRU },
{ "preamble", LT_PREAMBLE },
{ "rightmargin", LT_RIGHTMARGIN },
{ "spacing", LT_SPACING },
{ "textfont", LT_TEXTFONT },
{ "toclevel", LT_TOCLEVEL },
{ "topsep", LT_TOPSEP }
};
bool error = false;
@ -314,6 +319,11 @@ bool LyXLayout::Read(LyXLex & lexrc, LyXTextClass const & tclass)
nextnoindent = false;
break;
case LT_COMMANDDEPTH:
lexrc.next();
commanddepth = lexrc.getInteger();
break;
case LT_LATEXNAME:
if (lexrc.next())
latexname_ = lexrc.getString();
@ -324,6 +334,11 @@ bool LyXLayout::Read(LyXLex & lexrc, LyXTextClass const & tclass)
latexparam_ = lexrc.getString();
break;
case LT_INNERTAG:
if (lexrc.next())
innertag_ = lexrc.getString();
break;
case LT_PREAMBLE:
preamble_ = lexrc.getLongString("EndPreamble");
break;

View File

@ -63,6 +63,8 @@ public:
///
std::string const & latexparam() const { return latexparam_; }
///
std::string const & innertag() const { return innertag_; }
///
std::string const & labelstring_appendix() const {
return labelstring_appendix_;
}
@ -178,6 +180,8 @@ public:
int optionalargs;
/// Which counter to step
std::string counter;
/// Depth of XML command
int commanddepth;
private:
/// Name of the layout/paragraph environment
@ -205,6 +209,8 @@ private:
std::string labelstring_appendix_;
/// LaTeX parameter for environment
std::string latexparam_;
/// Internal tag to use (e.g., <title></title> for sect header)
std::string innertag_;
/// Macro definitions needed for this layout
std::string preamble_;
};

View File

@ -55,16 +55,13 @@ void docbookParagraphs(Buffer const & buf,
Paragraph::depth_type cmd_depth = 0;
Paragraph::depth_type depth = 0; // paragraph depth
string item_name;
string command_name;
ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
for (; par != pend; ++par) {
string sgmlparam;
string c_depth;
string c_params;
string inner_tag;
int desc_on = 0; // description mode
LyXLayout_ptr const & style = par->layout();
@ -91,6 +88,7 @@ void docbookParagraphs(Buffer const & buf,
}
// Write opening SGML tags.
string item_name;
switch (style->latextype) {
case LATEX_PARAGRAPH:
sgml::openTag(os, depth + command_depth,
@ -104,11 +102,9 @@ void docbookParagraphs(Buffer const & buf,
command_name = style->latexname();
sgmlparam = style->latexparam();
c_params = split(sgmlparam, c_depth,'|');
cmd_depth = atoi(c_depth);
cmd_depth = style->commanddepth;
inner_tag = style->innertag();
if (command_flag) {
if (cmd_depth < command_base) {
for (Paragraph::depth_type j = command_depth;
@ -150,9 +146,8 @@ void docbookParagraphs(Buffer const & buf,
}
sgml::openTag(os, depth + command_depth, false, command_name);
item_name = c_params.empty() ? "title" : c_params;
sgml::openTag(os, depth + 1 + command_depth, false, item_name);
// Inner tagged header text, e.g. <title> for sectioning:
sgml::openTag(os, depth + 1 + command_depth, false, inner_tag);
break;
case LATEX_ENVIRONMENT:
@ -208,9 +203,7 @@ void docbookParagraphs(Buffer const & buf,
// write closing SGML tags
switch (style->latextype) {
case LATEX_COMMAND:
end_tag = c_params.empty() ? "title" : c_params;
sgml::closeTag(os, depth + command_depth,
false, end_tag);
sgml::closeTag(os, depth + command_depth, false, inner_tag);
break;
case LATEX_ENVIRONMENT:
if (!style->latexparam().empty()) {