Changeset View
Changeset View
Standalone View
Standalone View
src/lib/3rdparty/markdown.h
- This file was added.
1 | | ||||
---|---|---|---|---|---|
2 | /* | ||||
3 | Copyright (c) 2009 by Chad Nelson | ||||
4 | Released under the MIT License. | ||||
5 | See the provided LICENSE.TXT file for details. | ||||
6 | */ | ||||
7 | | ||||
8 | #ifndef MARKDOWN_H_INCLUDED | ||||
9 | #define MARKDOWN_H_INCLUDED | ||||
10 | | ||||
11 | #include <iostream> | ||||
12 | #include <string> | ||||
13 | #include <list> | ||||
14 | | ||||
15 | #include <boost/noncopyable.hpp> | ||||
16 | #include <boost/shared_ptr.hpp> | ||||
17 | #include <boost/optional.hpp> | ||||
18 | #include <boost/unordered_map.hpp> | ||||
19 | | ||||
20 | namespace markdown { | ||||
21 | | ||||
22 | using boost::optional; | ||||
23 | using boost::none; | ||||
24 | | ||||
25 | // Forward references. | ||||
26 | class Token; | ||||
27 | class LinkIds; | ||||
28 | | ||||
29 | typedef boost::shared_ptr<Token> TokenPtr; | ||||
30 | typedef std::list<TokenPtr> TokenGroup; | ||||
31 | | ||||
32 | class Document: private boost::noncopyable { | ||||
33 | public: | ||||
34 | Document(size_t spacesPerTab=cDefaultSpacesPerTab); | ||||
35 | Document(std::istream& in, size_t spacesPerTab=cDefaultSpacesPerTab); | ||||
36 | ~Document(); | ||||
37 | | ||||
38 | // You can call read() functions multiple times before writing if | ||||
39 | // desirable. Once the document has been processed for writing, it can't | ||||
40 | // accept any more input. | ||||
41 | bool read(const std::string&); | ||||
42 | bool read(std::istream&); | ||||
43 | void write(std::ostream&); | ||||
44 | void writeTokens(std::ostream&); // For debugging | ||||
45 | | ||||
46 | // The class is marked noncopyable because it uses reference-counted | ||||
47 | // links to things that get changed during processing. If you want to | ||||
48 | // copy it, use the `copy` function to explicitly say that. | ||||
49 | Document copy() const; // TODO: Copy function not yet written. | ||||
50 | | ||||
51 | private: | ||||
52 | bool _getline(std::istream& in, std::string& line); | ||||
53 | void _process(); | ||||
54 | void _mergeMultilineHtmlTags(); | ||||
55 | void _processInlineHtmlAndReferences(); | ||||
56 | void _processBlocksItems(TokenPtr inTokenContainer); | ||||
57 | void _processParagraphLines(TokenPtr inTokenContainer); | ||||
58 | | ||||
59 | static const size_t cSpacesPerInitialTab, cDefaultSpacesPerTab; | ||||
60 | | ||||
61 | const size_t cSpacesPerTab; | ||||
62 | TokenPtr mTokenContainer; | ||||
63 | LinkIds *mIdTable; | ||||
64 | bool mProcessed; | ||||
65 | }; | ||||
66 | | ||||
67 | } // namespace markdown | ||||
68 | | ||||
69 | #endif // MARKDOWN_H_INCLUDED |