doxygen
markdown.h
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2015 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby
7  * granted. No representations are made about the suitability of this software
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  */
15 
16 #ifndef MARKDOWN_H
17 #define MARKDOWN_H
18 
19 #include <functional>
20 
21 #include "qcstring.h"
22 #include "parserintf.h"
23 #include "growbuf.h"
24 
25 class Entry;
26 
28 //QCString processMarkdown(const QCString &fileName,const int lineNr,Entry *e,const QCString &s);
29 QCString markdownFileNameToId(const QCString &fileName);
30 
32 class Markdown
33 {
34  public:
35  Markdown(const QCString &fileName,int lineNr,int indentLevel=0);
36  QCString process(const QCString &input, int &startNewlines, bool fromParseInput = false);
37  QCString extractPageTitle(QCString &docs, QCString &id, int &prepend, bool &isIdGenerated);
38  void setIndentLevel(int level) { m_indentLevel = level; }
39 
40  private:
41  QCString processQuotations(const QCString &s,int refIndent);
42  QCString processBlocks(const QCString &s,int indent);
43  QCString isBlockCommand(const char *data,int offset,int size);
44  int isSpecialCommand(const char *data,int offset,int size);
45  void findEndOfLine(const char *data,int size,int &pi,int&i,int &end);
46  int processHtmlTagWrite(const char *data,int offset,int size,bool doWrite);
47  int processHtmlTag(const char *data,int offset,int size);
48  int processEmphasis(const char *data,int offset,int size);
49  int processEmphasis1(const char *data, int size, char c);
50  int processEmphasis2(const char *data, int size, char c);
51  int processEmphasis3(const char *data, int size, char c);
52  int processNmdash(const char *data,int off,int size);
53  int processQuoted(const char *data,int,int size);
54  int processCodeSpan(const char *data, int /*offset*/, int size);
55  void addStrEscapeUtf8Nbsp(const char *s,int len);
56  int processSpecialCommand(const char *data, int offset, int size);
57  int processLink(const char *data,int,int size);
58  int findEmphasisChar(const char *data, int size, char c, int c_size);
59  void processInline(const char *data,int size);
60  void writeMarkdownImage(const char *fmt, bool inline_img, bool explicitTitle,
61  const QCString &title, const QCString &content,
62  const QCString &link, const QCString &attributes,
63  const FileDef *fd);
64  int isHeaderline(const char *data, int size, bool allowAdjustLevel);
65  int isAtxHeader(const char *data,int size,
66  QCString &header,QCString &id,bool allowAdjustLevel,
67  bool *pIsIdGenerated=nullptr);
68  void writeOneLineHeaderOrRuler(const char *data,int size);
69  void writeFencedCodeBlock(const char *data,const char *lng,
70  int blockStart,int blockEnd);
71  int writeBlockQuote(const char *data,int size);
72  int writeCodeBlock(const char *data,int size,int refIndent);
73  int writeTableBlock(const char *data, int size);
74  QCString extractTitleId(QCString &title, int level,bool *pIsIdGenerated=nullptr);
75 
76  private:
77  struct LinkRef
78  {
79  LinkRef(const QCString &l,const QCString &t) : link(l), title(t) {}
80  QCString link;
81  QCString title;
82  };
83  using Action_t = std::function<int(const char *,int,int)>;
84 
85  std::unordered_map<std::string,LinkRef> m_linkRefs;
86  QCString m_fileName;
87  int m_lineNr = 0;
88  int m_indentLevel=0; // 0 is outside markdown, -1=page level
89  GrowBuf m_out;
90  Markdown::Action_t m_actions[256];
91 };
92 
94 {
95  public:
97  virtual ~MarkdownOutlineParser();
98  void parseInput(const QCString &fileName,
99  const char *fileBuf,
100  const std::shared_ptr<Entry> &root,
101  ClangTUParser *clangParser);
102  bool needsPreprocessing(const QCString &) const { return FALSE; }
103  void parsePrototype(const QCString &text);
104  private:
105  struct Private;
106  std::unique_ptr<Private> p;
107 };
108 
109 
110 #endif
Represents an unstructured piece of information, about an entity found in the sources.
Definition: entry.h:61
A model of a file symbol.
Definition: filedef.h:73
Abstract interface for outline parsers.
Definition: parserintf.h:42
Class representing a string buffer optimised for growing.
Definition: growbuf.h:27
QCString fileName
file this entry was extracted from
Definition: entry.h:290
Definition: bin_to_hex.h:104
bool needsPreprocessing(const QCString &) const
Returns TRUE if the language identified by extension needs the C preprocessor to be run before feed t...
Definition: markdown.h:102
This is an alternative implementation of QCString.
Definition: qcstring.h:92
Definition: markdown.h:93
Definition: markdown.cpp:3343
Definition: format.h:1544
Helper class to process markdown formatted text.
Definition: markdown.h:32
Clang parser object for a single translation unit, which consists of a source file and the directly o...
Definition: clangparser.h:22