bypass-core-1.0
Bypass::Parser Class Reference

A parser that converts textual markdown into a Document object. More...

#include <src/parser.h>

Public Member Functions

 Parser ()
 Creates a Parser.
 
 ~Parser ()
 Destroys the Parser.
 
Document parse (const char *markdown)
 Parses the given markdown into a Document.
 
Document parse (const std::string &markdown)
 Parses the given markdown into a Document.
 
void split (std::vector< std::string > &tokens, const std::string &text, char sep)
 Populates the given tokens with the result of splitting the given text around the given sep.
 
void parsedBlockCode (struct buf *ob, struct buf *text)
 Handles the block code parser callback.
 
void parsedBlockQuote (struct buf *ob, struct buf *text)
 Handles the block quote parser callback.
 
void parsedHeader (struct buf *ob, struct buf *text, int level)
 Handles the header parser callback.
 
void parsedList (struct buf *ob, struct buf *text, int flags)
 Handles the list parser callback.
 
void parsedListItem (struct buf *ob, struct buf *text, int flags)
 Handles the list item parser callback.
 
void parsedParagraph (struct buf *ob, struct buf *text)
 Handles the paragraph parser callback.
 
int parsedCodeSpan (struct buf *ob, struct buf *text)
 Handles the code span parser callback.
 
int parsedDoubleEmphasis (struct buf *ob, struct buf *text, char c)
 Handles the double emphasis parser callback.
 
int parsedEmphasis (struct buf *ob, struct buf *text, char c)
 Handles the emphasis parser callback.
 
int parsedTripleEmphasis (struct buf *ob, struct buf *text, char c)
 Handles the triple emphasis parser callback.
 
int parsedLinebreak (struct buf *ob)
 Handles an explicit line break parser callback.
 
int parsedLink (struct buf *ob, struct buf *link, struct buf *title, struct buf *content)
 Handles a link parser callback.
 
void parsedNormalText (struct buf *ob, struct buf *text)
 Handles the event of normal text being extracted.
 
void printBuf (struct buf *b)
 

Detailed Description

A parser that converts textual markdown into a Document object.

The Document object can subsequently be interpreted in whatever way makes most sense to the applicable platform based on individual needs and idiosyncrasies. This object is not a "parser" proper, but is instead an abstraction of the libsoldout markdown parser. The Parser's primary purpose is to receive and interpret callbacks from libsoldout so that a Document object can be effectively constructed.

When constructing a Document object, there are basically two types of elements that nodes in the Document tree can consist of:

  • those that move the cursor downward vertically (known as block elements),
  • and those that follow text runs horizontally (known as span elements).

These definitions coincide with those used in John Gruber's Markdown Syntax documentation.

Constructor & Destructor Documentation

Bypass::Parser::Parser ( )

Creates a Parser.

Bypass::Parser::~Parser ( )

Destroys the Parser.

Member Function Documentation

Document Bypass::Parser::parse ( const char *  markdown)

Parses the given markdown into a Document.

Parameters
markdownThe textual representation of the markdown as a character array.
Returns
A Document object that represents the supplied markdown.
Document Bypass::Parser::parse ( const std::string &  markdown)

Parses the given markdown into a Document.

Parameters
markdownThe textual representation of the markdown as a string.
Returns
A Document object that represents the supplied markdown.
void Bypass::Parser::parsedBlockCode ( struct buf *  ob,
struct buf *  text 
)

Handles the block code parser callback.

A block code element is a block element.

Parameters
obThe designated output buffer.
textThe parsed text.
void Bypass::Parser::parsedBlockQuote ( struct buf *  ob,
struct buf *  text 
)

Handles the block quote parser callback.

A block quote element is a block element.

Parameters
obThe designated output buffer.
textThe parsed text.
int Bypass::Parser::parsedCodeSpan ( struct buf *  ob,
struct buf *  text 
)

Handles the code span parser callback.

A list item element is a span element.

Parameters
obThe designated output buffer.
textThe parsed text.
Returns
whether or not the callback was handled
int Bypass::Parser::parsedDoubleEmphasis ( struct buf *  ob,
struct buf *  text,
char  c 
)

Handles the double emphasis parser callback.

Text that is treated with double emphasis is emboldened. A double emphasis element is a span element.

Parameters
obThe designated output buffer.
textThe parsed text.
c
Returns
whether or not the callback was handled
int Bypass::Parser::parsedEmphasis ( struct buf *  ob,
struct buf *  text,
char  c 
)

Handles the emphasis parser callback.

Text that is treated with emphasis is italicized. An emphasis element is a span element.

Parameters
obThe designated output buffer.
textThe parsed text.
c
Returns
whether or not the callback was handled
void Bypass::Parser::parsedHeader ( struct buf *  ob,
struct buf *  text,
int  level 
)

Handles the header parser callback.

A header element is a block element.

Parameters
obThe designated output buffer.
textThe parsed text.
levelThe level of the header; ie. 1-6
int Bypass::Parser::parsedLinebreak ( struct buf *  ob)

Handles an explicit line break parser callback.

A line break element is similar to a span element in the it can be a sibling to other span elements, but it's also like a block element in that it adds vertical space.

Parameters
obThe designated output buffer.
Returns
whether or not the callback was handled
int Bypass::Parser::parsedLink ( struct buf *  ob,
struct buf *  link,
struct buf *  title,
struct buf *  content 
)

Handles a link parser callback.

A link element is a span element.

Note that there is no special treatment for inline links like http://www.google.com. You must explicitly demarcate links with one of the approaches outlined in the link above.

Parameters
obThe designated output buffer.
linkThe URL for the link.
titleThe title of the link.
contentThe content of the link.
Returns
whether or not the callback was handled
void Bypass::Parser::parsedList ( struct buf *  ob,
struct buf *  text,
int  flags 
)

Handles the list parser callback.

A list element is a block element.

Parameters
obThe designated output buffer.
textThe parsed text.
flagsThe kind of list that has been parsed, ie. ordered, block, etc.
void Bypass::Parser::parsedListItem ( struct buf *  ob,
struct buf *  text,
int  flags 
)

Handles the list item parser callback.

A list item element is a block element.

Parameters
obThe designated output buffer.
textThe parsed text.
flagsThe kind of list that has been parsed, ie. ordered, block, etc.
void Bypass::Parser::parsedNormalText ( struct buf *  ob,
struct buf *  text 
)

Handles the event of normal text being extracted.

Normal text is given its own span element in a Document and can be a sibling to other span elements. For example, the following markdown...

Hello, *my* name is Damian.

...would produce a text, emphasis, and another text element that were children of a paragraph element.

Parameters
obThe designated output buffer.
textThe text.
void Bypass::Parser::parsedParagraph ( struct buf *  ob,
struct buf *  text 
)

Handles the paragraph parser callback.

A list item element is a block element.

Parameters
obThe designated output buffer.
textThe parsed text.
int Bypass::Parser::parsedTripleEmphasis ( struct buf *  ob,
struct buf *  text,
char  c 
)

Handles the triple emphasis parser callback.

Text that is treated with triple emphasis is both italicized and emboldened. A triple emphasis element is a span element.

Parameters
obThe designated output buffer.
textThe parsed text.
c
Returns
whether or not the callback was handled
void Bypass::Parser::printBuf ( struct buf *  b)
void Bypass::Parser::split ( std::vector< std::string > &  tokens,
const std::string &  text,
char  sep 
)

Populates the given tokens with the result of splitting the given text around the given sep.

Parameters
tokensThe set of tokens produced by splitting around the sep character.
textThe text to split.
sepA character separator.

The documentation for this class was generated from the following file: