xref: /haiku/src/apps/haikudepot/textview/MarkupParser.h (revision d7f7bf2d890f652e20b8cf34e9b4c6ae1d3e20eb)
1*d7f7bf2dSAxel Dörfler /*
2*d7f7bf2dSAxel Dörfler  * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
3*d7f7bf2dSAxel Dörfler  * All rights reserved. Distributed under the terms of the MIT License.
4*d7f7bf2dSAxel Dörfler  */
5*d7f7bf2dSAxel Dörfler #ifndef MARKUP_PARSER_H
6*d7f7bf2dSAxel Dörfler #define MARKUP_PARSER_H
7*d7f7bf2dSAxel Dörfler 
8*d7f7bf2dSAxel Dörfler #include "TextDocument.h"
9*d7f7bf2dSAxel Dörfler 
10*d7f7bf2dSAxel Dörfler 
11*d7f7bf2dSAxel Dörfler class MarkupParser {
12*d7f7bf2dSAxel Dörfler public:
13*d7f7bf2dSAxel Dörfler 								MarkupParser();
14*d7f7bf2dSAxel Dörfler 								MarkupParser(
15*d7f7bf2dSAxel Dörfler 									const CharacterStyle& characterStyle,
16*d7f7bf2dSAxel Dörfler 									const ParagraphStyle& paragraphStyle);
17*d7f7bf2dSAxel Dörfler 
18*d7f7bf2dSAxel Dörfler 			void				SetStyles(
19*d7f7bf2dSAxel Dörfler 									const CharacterStyle& characterStyle,
20*d7f7bf2dSAxel Dörfler 									const ParagraphStyle& paragraphStyle);
21*d7f7bf2dSAxel Dörfler 
HeadingCharacterStyle()22*d7f7bf2dSAxel Dörfler 			const CharacterStyle& HeadingCharacterStyle() const
23*d7f7bf2dSAxel Dörfler 									{ return fHeadingStyle; }
HeadingParagraphStyle()24*d7f7bf2dSAxel Dörfler 			const ParagraphStyle& HeadingParagraphStyle() const
25*d7f7bf2dSAxel Dörfler 									{ return fHeadingParagraphStyle; }
26*d7f7bf2dSAxel Dörfler 
NormalCharacterStyle()27*d7f7bf2dSAxel Dörfler 			const CharacterStyle& NormalCharacterStyle() const
28*d7f7bf2dSAxel Dörfler 									{ return fNormalStyle; }
NormalParagraphStyle()29*d7f7bf2dSAxel Dörfler 			const ParagraphStyle& NormalParagraphStyle() const
30*d7f7bf2dSAxel Dörfler 									{ return fParagraphStyle; }
31*d7f7bf2dSAxel Dörfler 
32*d7f7bf2dSAxel Dörfler 			TextDocumentRef		CreateDocumentFromMarkup(const BString& text);
33*d7f7bf2dSAxel Dörfler 			void				AppendMarkup(const TextDocumentRef& document,
34*d7f7bf2dSAxel Dörfler 									const BString& text);
35*d7f7bf2dSAxel Dörfler 
36*d7f7bf2dSAxel Dörfler private:
37*d7f7bf2dSAxel Dörfler 			void				_InitStyles();
38*d7f7bf2dSAxel Dörfler 
39*d7f7bf2dSAxel Dörfler 			void				_ParseText(const BString& text);
40*d7f7bf2dSAxel Dörfler 			void				_CopySpan(const BString& text,
41*d7f7bf2dSAxel Dörfler 									int32& start, int32 end);
42*d7f7bf2dSAxel Dörfler 			void				_ToggleStyle(const CharacterStyle& style);
43*d7f7bf2dSAxel Dörfler 			void				_FinishParagraph(bool isLast);
44*d7f7bf2dSAxel Dörfler 
45*d7f7bf2dSAxel Dörfler private:
46*d7f7bf2dSAxel Dörfler 			CharacterStyle		fNormalStyle;
47*d7f7bf2dSAxel Dörfler 			CharacterStyle		fBoldStyle;
48*d7f7bf2dSAxel Dörfler 			CharacterStyle		fItalicStyle;
49*d7f7bf2dSAxel Dörfler 			CharacterStyle		fBoldItalicStyle;
50*d7f7bf2dSAxel Dörfler 			CharacterStyle		fHeadingStyle;
51*d7f7bf2dSAxel Dörfler 
52*d7f7bf2dSAxel Dörfler 			ParagraphStyle		fParagraphStyle;
53*d7f7bf2dSAxel Dörfler 			ParagraphStyle		fHeadingParagraphStyle;
54*d7f7bf2dSAxel Dörfler 			ParagraphStyle		fBulletStyle;
55*d7f7bf2dSAxel Dörfler 
56*d7f7bf2dSAxel Dörfler 			const CharacterStyle* fCurrentCharacterStyle;
57*d7f7bf2dSAxel Dörfler 			const ParagraphStyle* fCurrentParagraphStyle;
58*d7f7bf2dSAxel Dörfler 
59*d7f7bf2dSAxel Dörfler 			// while parsing:
60*d7f7bf2dSAxel Dörfler 			TextDocumentRef		fTextDocument;
61*d7f7bf2dSAxel Dörfler 			Paragraph			fCurrentParagraph;
62*d7f7bf2dSAxel Dörfler 			int32				fSpanStartOffset;
63*d7f7bf2dSAxel Dörfler };
64*d7f7bf2dSAxel Dörfler 
65*d7f7bf2dSAxel Dörfler 
66*d7f7bf2dSAxel Dörfler #endif // MARKUP_PARSER_H
67