diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp
index 9ccc4e3e78..fbd9f4bc1c 100644
--- a/src/output_xhtml.cpp
+++ b/src/output_xhtml.cpp
@@ -233,8 +233,15 @@ namespace {
bool XHTMLStream::closeFontTags()
{
+ if (isTagPending(parsep_tag))
+ // we haven't had any content
+ return true;
+
+ // this may be a useless check, since we ought at least to have
+ // the parsep_tag. but it can't hurt too much to be careful.
if (tag_stack_.empty())
return true;
+
// first, we close any open font tags we can close
html::StartTag curtag = tag_stack_.back();
while (html::isFontTag(curtag.tag_)) {
@@ -429,6 +436,17 @@ bool XHTMLStream::isTagOpen(string const & stag) const
}
+bool XHTMLStream::isTagPending(string const & stag) const
+{
+ TagStack::const_iterator sit = pending_tags_.begin();
+ TagStack::const_iterator const sen = pending_tags_.end();
+ for (; sit != sen; ++sit)
+ if (sit->tag_ == stag)
+ return true;
+ return false;
+}
+
+
// this is complicated, because we want to make sure that
// everything is properly nested. the code ought to make
// sure of that, but we won't assert (yet) if we run into
diff --git a/src/output_xhtml.h b/src/output_xhtml.h
index e214da87f0..497ffdbce0 100644
--- a/src/output_xhtml.h
+++ b/src/output_xhtml.h
@@ -146,6 +146,8 @@ private:
///
bool isTagOpen(std::string const &) const;
///
+ bool isTagPending(std::string const &) const;
+ ///
void writeError(std::string const &) const;
///
odocstream & os_;