nsHTMLContentSerializer.h (1797B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* 8 * nsIContentSerializer implementation that can be used with an 9 * nsIDocumentEncoder to convert an HTML (not XHTML!) DOM to an HTML 10 * string that could be parsed into more or less the original DOM. 11 */ 12 13 #ifndef nsHTMLContentSerializer_h__ 14 #define nsHTMLContentSerializer_h__ 15 16 #include "nsString.h" 17 #include "nsXHTMLContentSerializer.h" 18 19 class nsAtom; 20 21 class nsHTMLContentSerializer final : public nsXHTMLContentSerializer { 22 public: 23 nsHTMLContentSerializer(); 24 virtual ~nsHTMLContentSerializer(); 25 26 NS_IMETHOD AppendElementStart( 27 mozilla::dom::Element* aElement, 28 mozilla::dom::Element* aOriginalElement) override; 29 30 NS_IMETHOD AppendElementEnd(mozilla::dom::Element* aElement, 31 mozilla::dom::Element* aOriginalElement) override; 32 33 NS_IMETHOD AppendDocumentStart(mozilla::dom::Document* aDocument) override; 34 35 protected: 36 [[nodiscard]] virtual bool SerializeHTMLAttributes( 37 mozilla::dom::Element* aContent, mozilla::dom::Element* aOriginalElement, 38 nsAString& aTagPrefix, const nsAString& aTagNamespaceURI, 39 nsAtom* aTagName, int32_t aNamespace, nsAString& aStr); 40 41 [[nodiscard]] virtual bool AppendAndTranslateEntities( 42 const nsAString& aStr, nsAString& aOutputStr) override; 43 44 private: 45 static const uint8_t kEntities[]; 46 static const uint8_t kAttrEntities[]; 47 static const char* const kEntityStrings[]; 48 }; 49 50 nsresult NS_NewHTMLContentSerializer(nsIContentSerializer** aSerializer); 51 52 #endif