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