bypass-core-1.0
|
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) |
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:
These definitions coincide with those used in John Gruber's Markdown Syntax documentation.
Bypass::Parser::Parser | ( | ) |
Creates a Parser
.
Bypass::Parser::~Parser | ( | ) |
Destroys the Parser
.
Document Bypass::Parser::parse | ( | const char * | markdown | ) |
Document Bypass::Parser::parse | ( | const std::string & | 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.
ob | The designated output buffer. |
text | The 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.
ob | The designated output buffer. |
text | The 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.
ob | The designated output buffer. |
text | The parsed text. |
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.
ob | The designated output buffer. |
text | The parsed text. |
c |
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.
ob | The designated output buffer. |
text | The parsed text. |
c |
void Bypass::Parser::parsedHeader | ( | struct buf * | ob, |
struct buf * | text, | ||
int | level | ||
) |
Handles the header parser callback.
A header
element is a block element.
ob | The designated output buffer. |
text | The parsed text. |
level | The 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.
ob | The designated output buffer. |
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.
ob | The designated output buffer. |
link | The URL for the link. |
title | The title of the link. |
content | The content of the link. |
void Bypass::Parser::parsedList | ( | struct buf * | ob, |
struct buf * | text, | ||
int | flags | ||
) |
Handles the list parser callback.
A list
element is a block element.
ob | The designated output buffer. |
text | The parsed text. |
flags | The 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.
ob | The designated output buffer. |
text | The parsed text. |
flags | The 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.
ob | The designated output buffer. |
text | The text. |
void Bypass::Parser::parsedParagraph | ( | struct buf * | ob, |
struct buf * | text | ||
) |
Handles the paragraph parser callback.
A list item
element is a block element.
ob | The designated output buffer. |
text | The 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.
ob | The designated output buffer. |
text | The parsed text. |
c |
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
.
tokens | The set of tokens produced by splitting around the sep character. |
text | The text to split. |
sep | A character separator. |