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 "mozilla/Attributes.h" 17 #include "nsXHTMLContentSerializer.h" 18 #include "nsString.h" 19 20 class nsAtom; 21 22 class nsHTMLContentSerializer final : public nsXHTMLContentSerializer { 23 public: 24 nsHTMLContentSerializer(); 25 virtual ~nsHTMLContentSerializer(); 26 27 NS_IMETHOD AppendElementStart( 28 mozilla::dom::Element* aElement, 29 mozilla::dom::Element* aOriginalElement) override; 30 31 NS_IMETHOD AppendElementEnd(mozilla::dom::Element* aElement, 32 mozilla::dom::Element* aOriginalElement) override; 33 34 NS_IMETHOD AppendDocumentStart(mozilla::dom::Document* aDocument) override; 35 36 protected: 37 [[nodiscard]] virtual bool SerializeHTMLAttributes( 38 mozilla::dom::Element* aContent, mozilla::dom::Element* aOriginalElement, 39 nsAString& aTagPrefix, const nsAString& aTagNamespaceURI, 40 nsAtom* aTagName, int32_t aNamespace, nsAString& aStr); 41 42 [[nodiscard]] virtual bool AppendAndTranslateEntities( 43 const nsAString& aStr, nsAString& aOutputStr) override; 44 45 private: 46 static const uint8_t kEntities[]; 47 static const uint8_t kAttrEntities[]; 48 static const char* const kEntityStrings[]; 49 }; 50 51 nsresult NS_NewHTMLContentSerializer(nsIContentSerializer** aSerializer); 52 53 #endif 54