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