X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fxml.h;h=902007581ea4f64dc377e465c76f190746ff5f8a;hb=19f5aa58aa55fe210c689052967ade0f943f82fb;hp=56e5d81114295130d38e89f691d1fe470db68f38;hpb=fc2c36289b5c0cd15f453c4905bb56a2b20aef25;p=lyx.git diff --git a/src/xml.h b/src/xml.h index 56e5d81114..902007581e 100644 --- a/src/xml.h +++ b/src/xml.h @@ -160,6 +160,12 @@ docstring cleanID(docstring const &orig); /// returns a unique numeric ID docstring uniqueID(docstring const & label); +/// determines whether a string only contains space characters +bool isNotOnlySpace(docstring const & str); + +/// trims the string to the left, i.e. remove any space-like character at the beginning of the string +docstring trimLeft(docstring const & str); + struct FontTag; struct EndFontTag; @@ -168,23 +174,23 @@ struct EndFontTag; struct StartTag { /// - explicit StartTag(std::string const & tag) : tag_(from_ascii(tag)), keepempty_(false) {} + explicit StartTag(std::string const & tag) : tag_(from_ascii(tag)), keepempty_(false), tagtype_("none") {} /// - explicit StartTag(docstring const & tag) : tag_(tag), keepempty_(false) {} + explicit StartTag(docstring const & tag) : tag_(tag), keepempty_(false), tagtype_("none") {} /// explicit StartTag(docstring const & tag, docstring const & attr, - bool keepempty = false) - : tag_(tag), attr_(attr), keepempty_(keepempty) {} + bool keepempty = false, std::string const & tagtype = "none") + : tag_(tag), attr_(attr), keepempty_(keepempty), tagtype_(tagtype) {} /// explicit StartTag(std::string const & tag, std::string const & attr, - bool keepempty = false) - : tag_(from_ascii(tag)), attr_(from_ascii(attr)), keepempty_(keepempty) {} + bool keepempty = false, std::string const & tagtype = "none") + : tag_(from_ascii(tag)), attr_(from_utf8(attr)), keepempty_(keepempty), tagtype_(tagtype) {} /// explicit StartTag(std::string const & tag, docstring const & attr, - bool keepempty = false) - : tag_(from_ascii(tag)), attr_(attr), keepempty_(keepempty) {} + bool keepempty = false, std::string const & tagtype = "none") + : tag_(from_ascii(tag)), attr_(attr), keepempty_(keepempty), tagtype_(tagtype) {} /// - virtual ~StartTag() {} + virtual ~StartTag() = default; /// virtual docstring writeTag() const; /// @@ -206,6 +212,8 @@ struct StartTag /// whether to keep things like "" or discard them /// you would want this for td, e.g, but maybe not for a div bool keepempty_; + /// Type of tag for new-line behaviour. Either "paragraph", "inline", "block", or "none" (default). + std::string tagtype_; }; @@ -213,11 +221,13 @@ struct StartTag struct EndTag { /// - explicit EndTag(std::string tag) : tag_(from_ascii(tag)) {} + explicit EndTag(std::string const & tag, std::string const & tagtype = "none") + : tag_(from_ascii(tag)), tagtype_(tagtype) {} /// - explicit EndTag(docstring tag) : tag_(tag) {} + explicit EndTag(docstring const & tag, std::string const & tagtype = "none") + : tag_(tag), tagtype_(tagtype) {} /// - virtual ~EndTag() {} + virtual ~EndTag() = default; /// virtual docstring writeEndTag() const; /// @@ -227,9 +237,12 @@ struct EndTag bool operator!=(StartTag const & rhs) const { return !(*this == rhs); } /// - virtual EndFontTag const * asFontTag() const { return 0; } + virtual EndFontTag const * asFontTag() const { return nullptr; } /// docstring tag_; + /// Type of tag for new-line behaviour. Either "paragraph", "inline", "block", or "none" (default). + /// The value should match that of the corresponding xml::StartTag. + std::string tagtype_; }; @@ -240,27 +253,40 @@ struct CompTag { /// explicit CompTag(std::string const & tag) - : tag_(tag) {} + : tag_(from_utf8(tag)), tagtype_("none") {} + /// + explicit CompTag(docstring const & tag) + : tag_(tag), tagtype_("none") {} + /// + explicit CompTag(std::string const & tag, std::string const & attr, std::string const & tagtype = "none") + : tag_(from_utf8(tag)), attr_(from_utf8(attr)), tagtype_(tagtype) {} + /// + explicit CompTag(std::string const & tag, docstring const & attr, std::string const & tagtype = "none") + : tag_(from_utf8(tag)), attr_(attr), tagtype_(tagtype) {} /// - explicit CompTag(std::string const & tag, std::string const & attr) - : tag_(tag), attr_(attr) {} + explicit CompTag(docstring const & tag, std::string const & attr, std::string const & tagtype = "none") + : tag_(tag), attr_(from_utf8(attr)), tagtype_(tagtype) {} + /// + explicit CompTag(docstring const & tag, docstring const & attr, std::string const & tagtype = "none") + : tag_(tag), attr_(attr), tagtype_(tagtype) {} /// docstring writeTag() const; /// - std::string tag_; + docstring tag_; /// - std::string attr_; + docstring attr_; + /// Type of tag for new-line behaviour. Either "paragraph", "inline", "block", or "none" (default). + std::string tagtype_; }; /// A special case of StartTag, used exclusively for tags that wrap paragraphs. -/// parid is only used for HTML output; XML is supposed to use attr for this. struct ParTag : public StartTag { /// explicit ParTag(std::string const & tag, const std::string & attr): StartTag(tag, from_utf8(attr)) {} /// - ~ParTag() {} + ~ParTag() override = default; }; @@ -358,6 +384,41 @@ void closeTag(odocstream & os, std::string const & name); /// Close tag void closeTag(odocstream & os, Paragraph const & par); +// Convenience functions to open and close tags. First, very low-level ones to ensure a consistent new-line behaviour. +// Block style: +// Content before +// +// Contents of the block. +// +// Content after +// Paragraph style: +// Content before +// Contents of the paragraph. +// Content after +// Inline style: +// Content beforeContents of the paragraph.Content after + +/// +void openTag(XMLStream & xs, const docstring & tag, const docstring & attr, const std::string & tagtype); +/// +void openTag(XMLStream & xs, const std::string & tag, const std::string & attr, const std::string & tagtype); +/// +void openTag(XMLStream & xs, const docstring & tag, const std::string & attr, const std::string & tagtype); +/// +void openTag(XMLStream & xs, const std::string & tag, const docstring & attr, const std::string & tagtype); +/// +void closeTag(XMLStream & xs, const docstring & tag, const std::string & tagtype); +/// +void closeTag(XMLStream & xs, const std::string & tag, const std::string & tagtype); +/// +void compTag(XMLStream & xs, const docstring & tag, const docstring & attr, const std::string & tagtype); +/// +void compTag(XMLStream & xs, const std::string & tag, const std::string & attr, const std::string & tagtype); +/// +void compTag(XMLStream & xs, const docstring & tag, const std::string & attr, const std::string & tagtype); +/// +void compTag(XMLStream & xs, const std::string & tag, const docstring & attr, const std::string & tagtype); + } // namespace xml } // namespace lyx