markdown.h
Go to the documentation of this file.
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#pragma once
9
10#include <iostream>
11#include <list>
12#include <memory>
13#include <string>
14
15namespace markdown
16{
17 // Forward references.
18 class Token;
19 class LinkIds;
20
21 using TokenPtr = std::shared_ptr<Token>;
22 using TokenGroup = std::list<TokenPtr>;
23
25 {
26 public:
27 Document(size_t spacesPerTab = cDefaultSpacesPerTab);
28 Document(std::istream& in, size_t spacesPerTab = cDefaultSpacesPerTab);
29 ~Document();
30
31 // You can call read() functions multiple times before writing if
32 // desirable. Once the document has been processed for writing, it can't
33 // accept any more input.
34 bool read(const std::string&);
35 bool read(std::istream&);
36 void write(std::ostream&);
37 void writeTokens(std::ostream&); // For debugging
38
39 // The class is marked noncopyable because it uses reference-counted
40 // links to things that get changed during processing. If you want to
41 // copy it, use the `copy` function to explicitly say that.
42 Document copy() const; // TODO: Copy function not yet written.
43
44 private:
45 bool _getline(std::istream& in, std::string& line);
46 void _process();
47 void _mergeMultilineHtmlTags();
48 void _processInlineHtmlAndReferences();
49 void _processBlocksItems(TokenPtr inTokenContainer);
50 void _processParagraphLines(TokenPtr inTokenContainer);
51
52 static const size_t cSpacesPerInitialTab, cDefaultSpacesPerTab;
53
54 const size_t cSpacesPerTab;
55 TokenPtr mTokenContainer;
56 LinkIds* mIdTable;
57 bool mProcessed;
58 };
59
60} // namespace markdown
Document(size_t spacesPerTab=cDefaultSpacesPerTab)
Definition markdown.cpp:932
void write(std::ostream &)
Document copy() const
void writeTokens(std::ostream &)
bool read(const std::string &)
Definition markdown.cpp:956
std::shared_ptr< Token > TokenPtr
Definition markdown.h:21
std::list< TokenPtr > TokenGroup
Definition markdown.h:22