1
2
3
4
5
6 #ifndef GENDOC_HTML_SOURCE_CODE_WRITER_INCLUDED
7 #define GENDOC_HTML_SOURCE_CODE_WRITER_INCLUDED
8 #include <gendoc/html/HtmlApi.hpp>
9 #include <sngcpp/ast/SourceCodeWriter.hpp>
10 #include <sngcpp/ast/Node.hpp>
11 #include <sngxml/dom/Element.hpp>
12
13 namespace gendoc { namespace html {
14
15 using namespace sngcpp::ast;
16
17 enum class WriteKind : uint8_t
18 {
19 none= 0,
20 line= 1 << 0,
21 inlineLine= 1 << 1,
22 both= line | inlineLine
23 };
24
25 inline WriteKind operator|(WriteKind left, WriteKind right)
26 {
27 return WriteKind(uint8_t(left) | uint8_t(right));
28 }
29
30 inline WriteKind operator&(WriteKind left, WriteKind right)
31 {
32 return WriteKind(uint8_t(left) & uint8_t(right));
33 }
34
35 class HtmlSourceCodeWriter : public sngcpp::ast::SourceCodeWriter
36 {
37 public:
38 HtmlSourceCodeWriter();
39 void SetLineElement(sngxml::dom::Element* lineElement_) { lineElement = lineElement_; }
40 void SetInlineLineElement(sngxml::dom::Element* inlineLineElement_) { inlineLineElement = inlineLineElement_; }
41 void SetCurrentPos(int currentPos_) { currentPos = currentPos_; }
42 void SetInlineCurrentPos(int inlineCurrentPos_) { inlineCurrentPos = inlineCurrentPos_; }
43 void MoveTo(const Span& span);
44 void WriteLineNumber(const std::u32string& lineNumber) override;
45 void WriteLineNumberKind(const std::u32string& lineNumber, WriteKind kind);
46 void WriteLineComment(const std::u32string& comment) override;
47 void WriteBlockComment(const std::u32string& comment) override;
48 void WriteKeyword(const std::u32string& keyword) override;
49 void WriteIdentifier(const std::u32string& identifier) override;
50 void WriteLink(const std::u32string& identifier, const std::u32string& ref) override;
51 void WriteInlineLink(const std::u32string& identifier, const std::u32string& ref);
52 void WriteType(const std::u32string& type) override;
53 void WritePP(const std::u32string& pp) override;
54 void WriteChar(const std::u32string& chars) override;
55 void WriteString(const std::u32string& string) override;
56 void WriteSpace(int numSpaces) override;
57 void WriteSpaces(const std::u32string& spaces) override;
58 void WriteSpaceKind(int numSpaces, WriteKind kind);
59 void WriteNumber(const std::u32string& number) override;
60 void WriteOther(const std::u32string& other) override;
61 private:
62 sngxml::dom::Element* lineElement;
63 sngxml::dom::Element* inlineLineElement;
64 int currentPos;
65 int inlineCurrentPos;
66 void WriteToElement(sngxml::dom::Element* element, const std::u32string& text);
67 };
68
69 } }
70
71 #endif // GENDOC_HTML_SOURCE_CODE_WRITER_INCLUDED