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 <string>
12 #include <list>
13 #include <memory>
14 
15 namespace 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 
24  class Document
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
61 
markdown::Document
Definition: markdown.h:24
markdown::Document::writeTokens
void writeTokens(std::ostream &)
Definition: markdown.cpp:997
markdown::Document::read
bool read(const std::string &)
Definition: markdown.cpp:906
markdown::TokenPtr
std::shared_ptr< Token > TokenPtr
Definition: markdown.h:21
markdown::Document::Document
Document(size_t spacesPerTab=cDefaultSpacesPerTab)
Definition: markdown.cpp:887
markdown::Document::~Document
~Document()
Definition: markdown.cpp:901
markdown
Definition: markdown-tokens.cpp:16
markdown::Document::write
void write(std::ostream &)
Definition: markdown.cpp:991
markdown::LinkIds
Definition: markdown-tokens.h:21
markdown::TokenGroup
std::list< TokenPtr > TokenGroup
Definition: markdown.h:22
markdown::Document::copy
Document copy() const