From d9b62b3f9c04b4f1be005b6b5f08f5b2b508948e Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 5 Jun 2009 18:18:44 +0000 Subject: [PATCH] Improve tag output routines. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29957 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/output_xhtml.cpp | 66 +++++++++++++++++++------------------------- src/output_xhtml.h | 2 ++ 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp index 36da8011db..bfebbe6369 100644 --- a/src/output_xhtml.cpp +++ b/src/output_xhtml.cpp @@ -63,23 +63,21 @@ docstring escapeChar(char_type c) } return str; } -} // html -namespace { +// FIXME This needs to be protected somehow. static vector taglist; -void openTag(odocstream & os, Layout const & lay) +void openTag(odocstream & os, string tag, string attr) { - string const & tag = lay.htmltag(); if (tag.empty()) return; + // FIXME This is completely primitive. We need something + // a lot better. // Now do some checks on nesting of tags. if (tag == "p") if (find(taglist.begin(), taglist.end(), "p") != taglist.end()) return; - // FIXME More? Better? - string attr = lay.htmlattr(); if (!attr.empty()) attr = ' ' + attr; os << from_ascii("<" + tag + attr + ">"); @@ -87,67 +85,61 @@ void openTag(odocstream & os, Layout const & lay) } -void closeTag(odocstream & os, Layout const & lay) +void closeTag(odocstream & os, string tag) { - string const & tag = lay.htmltag(); - if (tag.empty() || taglist.empty()) - // Here we will just assume this does not need to be done. - return; - if (find(taglist.begin(), taglist.end(), tag) == taglist.end()) + if (tag.empty()) return; - os << from_ascii(""); - // Check for proper nesting + // FIXME Check for proper nesting string const & lasttag = taglist.back(); if (lasttag != tag) { LYXERR0("Last tag was `" << lasttag << "' when closing `" << tag << "'!"); return; } taglist.pop_back(); + os << from_ascii(""); +} + + + +} // html + +namespace { + +void openTag(odocstream & os, Layout const & lay) +{ + html::openTag(os, lay.htmltag(), lay.htmlattr()); +} + + +void closeTag(odocstream & os, Layout const & lay) +{ + html::closeTag(os, lay.htmltag()); } void openLabelTag(odocstream & os, Layout const & lay) { - string const & tag = lay.htmllabel(); - if (tag.empty()) - return; - string attr = lay.htmllabelattr(); - if (!attr.empty()) - attr = ' ' + attr; - os << from_ascii("<" + tag + attr + ">"); + html::openTag(os, lay.htmllabel(), lay.htmllabelattr()); } void closeLabelTag(odocstream & os, Layout const & lay) { - string const & tag = lay.htmllabel(); - if (tag.empty()) - return; - os << from_ascii(""); + html::closeTag(os, lay.htmllabel()); } void openItemTag(odocstream & os, Layout const & lay) { - string const & tag = lay.htmlitem(); - if (tag.empty()) - return; - string attr = lay.htmlitemattr(); - if (!attr.empty()) - attr = ' ' + attr; - os << from_ascii("<" + tag + attr + ">"); + html::openTag(os, lay.htmlitem(), lay.htmlitemattr()); } void closeItemTag(odocstream & os, Layout const & lay) { - string const & tag = lay.htmlitem(); - if (tag.empty()) - return; - os << from_ascii(""); + html::closeTag(os, lay.htmlitem()); } - ParagraphList::const_iterator searchParagraph( ParagraphList::const_iterator p, ParagraphList::const_iterator const & pend) diff --git a/src/output_xhtml.h b/src/output_xhtml.h index e58e4a8db4..57bde40868 100644 --- a/src/output_xhtml.h +++ b/src/output_xhtml.h @@ -28,6 +28,8 @@ void xhtmlParagraphs(ParagraphList const & subset, namespace html { docstring escapeChar(char_type c); + void openTag(odocstream & os, std::string tag, std::string attr); + void closeTag(odocstream & os, std::string tag); } } // namespace lyx -- 2.39.2