HaikuDepot: Make MarkupParser a bit more flexible...

... by allowing to append markup to an existing document.
This commit is contained in:
Stephan Aßmus 2013-09-08 18:39:56 +02:00
parent 97c332e107
commit cb97f2349f
2 changed files with 22 additions and 4 deletions

View File

@ -64,9 +64,20 @@ MarkupParser::SetStyles(const CharacterStyle& characterStyle,
TextDocumentRef
MarkupParser::CreateDocumentFromMarkup(const BString& text)
{
fTextDocument.SetTo(new(std::nothrow) TextDocument(), true);
if (fTextDocument.Get() == NULL)
return fTextDocument;
TextDocumentRef document(new(std::nothrow) TextDocument(), true);
if (document.Get() == NULL)
return document;
AppendMarkup(document, text);
return document;
}
void
MarkupParser::AppendMarkup(const TextDocumentRef& document, const BString& text)
{
fTextDocument.SetTo(document);
fCurrentCharacterStyle = &fNormalStyle;
fCurrentParagraphStyle = &fParagraphStyle;
@ -76,7 +87,7 @@ MarkupParser::CreateDocumentFromMarkup(const BString& text)
_ParseText(text);
return fTextDocument;
fTextDocument.Unset();
}

View File

@ -19,7 +19,14 @@ public:
const CharacterStyle& characterStyle,
const ParagraphStyle& paragraphStyle);
const CharacterStyle& HeadingCharacterStyle() const
{ return fHeadingStyle; }
const ParagraphStyle& HeadingParagraphStyle() const
{ return fHeadingParagraphStyle; }
TextDocumentRef CreateDocumentFromMarkup(const BString& text);
void AppendMarkup(const TextDocumentRef& document,
const BString& text);
private:
void _InitStyles();