Hoedown


Next: , Up: (dir)

Hoedown

This document describes version 3.0.3 of Hoedown, a C language library implementing a template library. This distribution is an repackaging of the original Hoedown package, using the GNU Autotools.

The latest release of the repackaged Hoedown can be downloaded from:

https://bitbucket.org/marcomaggi/hoedown/downloads

the original package development takes place at:

http://github.com/hoedown/hoedown

development takes place at:

http://github.com/marcomaggi/hoedown

and as backup at:

https://bitbucket.org/marcomaggi/hoedown

Copyright © 2008, Natacha Porte
Copyright © 2011, Vicent Marti
Copyright © 2014, Xavier Mendez, Devin Torres and the Hoedown authors

Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Appendices

Indexes


Next: , Previous: Top, Up: Top

1 Overview of the package

This document describes version 3.0.3 of Hoedown, a C language library implementing a Markdown parser. This distribution is an repackaging of the original Hoedown package, using the GNU Autotools.

Hoedown is a revived fork of Sundown, the Markdown parser based on the original code of the Upskirt library by Natacha Porte.

Features:

Fully standards compliant
Hoedown passes out of the box the official Markdown v1.0.0 and v1.0.3 test suites, and has been extensively tested with additional corner cases to make sure its output is as sane as possible at all times.
Massive extension support
Hoedown has optional support for several (unofficial) Markdown extensions, such as non–strict emphasis, fenced code blocks, tables, autolinks, strikethrough and more.
UTF-8 aware
Hoedown is fully UTF-8 aware, both when parsing the source document and when generating the resulting (X)HTML code.
Tested and Ready to be used on production
Hoedown has been extensively security audited, and includes protection against all possible DOS attacks (stack overflows, out of memory situations, malformed Markdown syntax...).

We've worked very hard to make Hoedown never leak or crash under any input.

Warning: Hoedown doesn't validate or post–process the HTML in Markdown documents. Unless you use ‘HTML_ESCAPE’ or ‘HTML_SKIP’, you should strongly consider using a good post–processor in conjunction with Hoedown to prevent client–side attacks.

Customizable renderers
Hoedown is not stuck with XHTML output: the Markdown parser of the library is decoupled from the renderer, so it's trivial to extend the library with custom renderers. A fully functional (X)HTML renderer is included.
Optimized for speed
Hoedown is written in C, with a special emphasis on performance. When wrapped on a dynamic language such as Python or Ruby, it has shown to be up to 40 times faster than other native alternatives.
Zero–dependency
Hoedown is a zero–dependency library composed of some ‘.c’ files and their headers. No dependencies, no bullshit. Only standard C99 that builds everywhere.
Additional features
Hoedown comes with a fully functional implementation of SmartyPants, a separate autolinker, escaping utilities, buffers and stacks.

Hoedown installs multiple header files under the directory $(includedir)/hoedown. All the function names in the API are prefixed with hoedown_; all the constant names are prefixed with HOEDOWN_; all the type names are prefixed with hoedown_.


Up: overview

1.1 Linking code with the library

This package installs a data file for pkg-config, so when searching for the installed library with the GNU Autotools, we can:

Alternatively we can use the raw GNU Autoconf macros:

     AC_CHECK_LIB([hoedown],[hoedown_version],,
       [AC_MSG_FAILURE([test for Hoedown library failed])])
     AC_CHECK_HEADERS([hoedown/version.h],,
       [AC_MSG_FAILURE([test for Hoedown header failed])])


Next: , Previous: overview, Up: Top

2 The hoedown program

The package compiles and installs the program hoedown, which can process input Markdown documents and generate HTML output using the built–in HTML renderer. Synopsis:

     hoedown [OPTION]... [FILE]

Process the Markdown in ‘FILE’ (or standard input) and render it to standard output, using the Hoedown library. Parsing and rendering can be customized through the options below. The default is to parse pure markdown and output HTML.

Main options:

-n N
--max-nesting=N
Maximum level of block nesting parsed. Default is 16.
-t
--toc-level=N
Maximum level for headers included in the Table of Contents. Zero disables the inclusion of Table of Contents in the output (the default).
--html
Render (X)HTML. The default.
--html-toc
Render the Table of Contents in (X)HTML.
-T
--time
Show time spent in rendering.
-i N
--input-unit=N
Reading block size. Default is 1024.
-o N
--output-unit=N
Writing block size. Default is 64.
-h
--help
Print this help text.
-v
--version
Print Hoedown version.

Block extensions:

--tables
Parse PHP-Markdown style tables.
--fenced-code
Parse fenced code blocks.
--footnotes
Parse footnotes.
--all-block
Enable all of the above.

Span extensions:

--autolink
Automatically turn safe URLs into links.
--strikethrough
Parse ‘~~stikethrough~~’ spans.
--underline
Parse ‘_underline_’ instead of emphasis.
--highlight
Parse ‘==highlight==’ spans.
--quote
Render “quotes” as ‘<q>quotes</q>’.
--superscript
Parse ‘super^script’.
--math
Parse TeX ‘$$math$$’ syntax, Kramdown style.
--all-span
Enable all of the above.

Other flags:

--disable-intra-emphasis
Disable ‘emphasis_between_words’.
--space-headers
Require a space after ‘#’ in headers.
--math-explicit
Instead of guessing by context, parse ‘$inline math$’ and ‘$$always block math$$’ (requires --math).
--all-flags
Enable all of the above.

Negative flags:

--disable-indented-code
Don't parse indented code blocks.
--all-negative
Enable all of the above.

HTML-specific options:

--skip-html
Strip all HTML tags.
--escape
Escape all HTML.
--hard-wrap
Render each linebreak as ‘<br>’.
--xhtml
Render XHTML.

Flags and extensions can be negated by prepending ‘no’ to them, as in --no-tables, --no-span or --no-escape. Options are processed in order, so in case of contradictory options the last specified stands.

When ‘FILE’ is ‘-’, read standard input. If no ‘FILE’ was given, read standard input. Use -- to signal end of option parsing. Exit status is: ‘0’ if no errors occurred, ‘1’ with option parsing errors, ‘4’ with memory allocation errors or ‘5’ with I/O errors.


Next: , Previous: hoedown, Up: Top

3 The smartypants program

The package compiles and installs the program smartypants, which translates plain ASCII punctuation characters into “smart” typographic punctuation HTML entities. smartypants performs the following transformations:

Synopsis:

     smartypants [OPTION]... [FILE]

Apply SmartyPants smart punctuation to the HTML in ‘FILE’ (or standard input), and output the resulting HTML to standard output.

Main options:

-T
--time
Show time spent in SmartyPants processing.
-i N
--input-unit=N
Reading block size. Default is 1024.
-o N
--output-unit=N
Writing block size. Default is 64.
-h
--help
Print this help text.
-v
--version
Print Hoedown version.

Options are processed in order, so in case of contradictory options the last specified stands.

When ‘FILE’ is ‘-’, read standard input. If no ‘FILE’ was given, read standard input. Use ‘--’ to signal end of option parsing. Exit status is: ‘0’ if no errors occurred, ‘1’ with option parsing errors, ‘4’ with memory allocation errors or ‘5’ with I/O errors.


Next: , Previous: smartypants, Up: Top

4 The hoedown library


Next: , Up: lib

4.1 Version functions

The definitions of the buffers API are in the header file hoedown/version.h.

— Function: void hoedown_version (int * major, int * minor, int * revision)

Retrieve version numbers, storing them in the referenced int locations.

— Preprocessor Constant: HOEDOWN_VERSION

A string representing the full version number.

— Preprocessor Constant: HOEDOWN_MAJOR
— Preprocessor Constant: HOEDOWN_MINOR
— Preprocessor Constant: HOEDOWN_REVISION

Integers representing version number components.


Next: , Previous: lib version, Up: lib

4.2 Data buffers


Next: , Up: lib buffers

4.2.1 Memory handling in data buffers

The definitions of the buffers API are in the header file hoedown/buffer.h.

— Function Pointer Typedef: hoedown_realloc_callback

Type definition for function pointers implementing a memory reallocation callback. It is meant to be used as follows:

          void *
          realloc_callback (void * ptr, size_t len)
          {
            ...
          }
          
          hoedown_realloc_callback R = realloc_callback;

This function pointer type is meant to match the one of the C Language Standard function realloc().

— Function Pointer Typedef: hoedown_free_callback

Type definition for function pointers implementing a memory release callback. It is meant to be used as follows:

          void
          free_callback (void * ptr)
          {
            ...
          }
          
          hoedown_free_callback F = free_callback;

This function pointer type is meant to match the one of the C Language Standard function free().

— Function: void * hoedown_malloc (size_t size)

Wrapper for the C Language Standard malloc(). If memory allocation fails: abort the process by calling abort().

— Function: void * hoedown_calloc (size_t nmemb, size_t size)

Wrapper for the C Language Standard calloc(). If memory allocation fails: abort the process by calling abort().

— Function: void * hoedown_realloc (void * ptr, size_t size)

Wrapper for the C Language Standard realloc(). If memory reallocation fails: abort the process by calling abort().


Next: , Previous: lib buffers memory, Up: lib buffers

4.2.2 Data buffer structure

The definitions of the buffers API are in the header file hoedown/buffer.h.

— Struct Typedef: hoedown_buffer

Type of structures representing data buffers. Instances of this type must be initialised by hoedown_buffer_init() and finalised by hoedown_buffer_uninit().

Basic allocation, initialisation and finalisation can be performed as:

          hoedown_buffer          B;
          
          hoedown_buffer_init(&B, 1, realloc, free, free);
          hoedown_buffer_uninit(&B);

or as:

          hoedown_buffer *        B;
          
          B = hoedown_buffer_new(1);
          hoedown_buffer_free(B);

Public fields in the data structure:

size
The number of octets used in the internal data area. It is the length in octets of the contained data.

— Function: void hoedown_buffer_init (hoedown_buffer * buffer, size_t reallocation-unit, hoedown_realloc_callback data_realloc, hoedown_free_callback data_free, hoedown_free_callback buffer_free)

Initialise a buffer with custom memory allocators.

buffer must be a pointer referencing an already allocated data structure. When the internal data area is reallocated to make it bigger: reallocation-unit is the minimum increase in the area size, measured in number of bytes.

data_realloc must reference a function used to allocate and/or reallocate a memory block. data_free must reference a function used to release the data area of the buffer. buffer_free must reference a function used to release the hoedown_buffer structure itself.

— Function: void hoedown_buffer_uninit (hoedown_buffer * buf)

Finalise the given buffer structure. Memory allocated for the internal data area is released using the registered data_free function. The memory block referenced by buf is not released.

— Function: hoedown_buffer * hoedown_buffer_new (size_t reallocation-unit)

Convenience function that allocates a new hoedown_buffer structure and initialises it with default memory handlers; internally it makes use of hoedown_buffer_init(). Return a pointer to the newly allocated structure.

The structure memory block is allocated with the C Language Standard malloc(). hoedown_realloc() is registered as data_realloc function. The C Language Standard free() is registered as both data_free and buffer_free function.

— Function: void hoedown_buffer_free (hoedown_buffer * buf)

Convenience function that finalises and releases the given buffer structure; internally it is similar to hoedown_buffer_uninit(). Release both the data area memory and the structure memory using the registered memory handlers.

— Function: void hoedown_buffer_reset (hoedown_buffer * buf)

Reset to empty the given buffer structure. Release the internal data area using the registered memory handlers.

— Function: void hoedown_buffer_grow (hoedown_buffer * buf, size_t neosz)

Increase the allocated data area size to the given value. Memory for the data area is allocated and reallocated with the registered memory handlers.

          hoedown_buffer              B;
          hoedown_buffer_init(&B, 1, realloc, free, free);
          {
            hoedown_buffer_grow(&B, 4096);
          }
          hoedown_buffer_uninit(&B);


Next: , Previous: lib buffers struct, Up: lib buffers

4.2.3 Appending data to buffers

The definitions of the buffers API are in the header file hoedown/buffer.h.

— Function: void hoedown_buffer_put (hoedown_buffer * buf, const uint8_t * data, size_t size)

Append raw data to a buffer. The internal data area is resized as needed and octets referenced by data are copied into it.

          hoedown_buffer              B;
          static const char *         str = "Hello World!";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_buffer_put(&B, (const uint8_t*)str, strlen(str));
          }
          hoedown_buffer_uninit(&B);
— Function: void hoedown_buffer_puts (hoedown_buffer * buf, const char * str)

Append a NUL–terminated string to a buffer.

          hoedown_buffer              B;
          static const char *         str = "Hello World!";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_buffer_puts(&B, str);
          }
          hoedown_buffer_uninit(&B);
— Preprocessor Macro: void HOEDOWN_BUFPUTSL (hoedown_buffer * buf, const char * str)

Optimized hoedown_buffer_put() of a string literal. It is meant to be used when str references a literal string, as in:

          hoedown_buffer              B;
          static const char *         str  = "Hello World!";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            HOEDOWN_BUFPUTSL(&B, "Hello ");
            HOEDOWN_BUFPUTSL(&B, "World!");
          }
          hoedown_buffer_uninit(&B);
— Function: void hoedown_buffer_putc (hoedown_buffer * buf, uint8_t c)

Append a single char to a buffer.

          hoedown_buffer              B;
          static const char *         str = "Hello World!";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            for (int i=0; i<strlen(str); ++i) {
              hoedown_buffer_putc(&B, str[i]);
            }
          }
          hoedown_buffer_uninit(&B);
— Function: int hoedown_buffer_putf (hoedown_buffer * buf, FILE * file)

Read from a file and append to a buffer, until EOF or error.

          hoedown_buffer              B;
          FILE *                      M;
          char                        str[32];
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          M = fopen("file.ext", "r");
          {
            hoedown_buffer_putf(&B, M);
          }
          fclose(M);
          hoedown_buffer_uninit(&B);
— Function: void hoedown_buffer_put_utf8 (hoedown_buffer * buf, unsigned int codepoint)

Put a Unicode character encoded as UTF-8.

          hoedown_buffer              B;
          uint32_t                    cp    = 0x10FFFF;
          uint8_t                     buf[] = {
            244, 143, 191, 191
          };
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_buffer_put_utf8(&B, cp);
            assert(0 == memcmp(buf, B.data, B.size));
          }
          hoedown_buffer_uninit(&B);


Next: , Previous: lib buffers append, Up: lib buffers

4.2.4 Setting data in buffers

The definitions of the buffers API are in the header file hoedown/buffer.h.

— Function: void hoedown_buffer_set (hoedown_buffer * buf, const uint8_t * data, size_t size)

Replace the buffer's contents with raw data.

          hoedown_buffer              B;
          static const char *         str1 = "Hello World!";
          static const char *         str2 = "Ciao Mondo!";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_buffer_put(&B, (const uint8_t*)str1, strlen(str1));
            hoedown_buffer_set(&B, (const uint8_t*)str2, strlen(str2));
          }
          hoedown_buffer_uninit(&B);
— Function: void hoedown_buffer_sets (hoedown_buffer * buf, const char * str)

Replace the buffer's contents with a NUL-terminated string.

          hoedown_buffer              B;
          static const char *         str1 = "Hello World!";
          static const char *         str2 = "Ciao Mondo!";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_buffer_puts(&B, str1);
            assert(0 == memcmp(str1, B.data, B.size));
            hoedown_buffer_sets(&B, str2);
            assert(0 == memcmp(str2, B.data, B.size));
          }
          hoedown_buffer_uninit(&B);
— Preprocessor Macro: void HOEDOWN_BUFSETSL (hoedown_buffer * buf, const char * str)

Optimized hoedown_buffer_sets() of a string literal. It is meant to be used when str references a literal string, as in:

          hoedown_buffer              B;
          static const char *         str1 = "Hello World!";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_buffer_puts(&B, str1);
            HOEDOWN_BUFSETSL(&B, "Ciao Mondo!");
          }
          hoedown_buffer_uninit(&B);


Next: , Previous: lib buffers set, Up: lib buffers

4.2.5 Comparing data in buffers

The definitions of the buffers API are in the header file hoedown/buffer.h.

— Function: int hoedown_buffer_eq (const hoedown_buffer * buf, const uint8_t * data, size_t size)

Compare a buffer's data with other data for equality: return true (non–zero) if the octets are equal, return false (zero) otherwise.

          hoedown_buffer              B;
          static const char *         str = "Hello World!";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_buffer_puts(&B, str);
            assert(0 != hoedown_buffer_eq(&B,
                          (const uint8_t*)str, strlen(str)));
          }
          hoedown_buffer_uninit(&B);
— Function: int hoedown_buffer_eqs (const hoedown_buffer * buf, const char * str)

Compare a buffer's data with a NUL–terminated string for equality: return true (non–zero) if the octets are equal, return false (zero) otherwise.

          hoedown_buffer              B;
          static const char *         str = "Hello World!";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_buffer_puts(&B, str);
            assert(0 != hoedown_buffer_eqs(&B, str));
          }
          hoedown_buffer_uninit(&B);
— Preprocessor Macro: int HOEDOWN_BUFEQSL (hoedown_buffer * buf, const char * str)

Optimized hoedown_buffer_eqs() of a string literal. It is meant to be used when str references a literal string, as in:

          hoedown_buffer              B;
          static const char *         str = "Hello World!";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_buffer_puts(&B, str);
            assert(0 != HOEDOWN_BUFEQSL(&B, "Hello World!"));
          }
          hoedown_buffer_uninit(&B);
— Function: int hoedown_buffer_prefix (const hoedown_buffer * buf, const char * prefix)

Compare the beginning of a buffer with a string: return zero if the octets are equal; return greater than zero if an octet in buf is found to be greater than the octet in prefix; return less than zero if an octet in buf is found to be less than the octet in prefix.

          hoedown_buffer              B;
          static const char *         str1 = "Hello World!";
          static const char *         str2 = "Hello";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_buffer_puts(&B, str1);
            assert(0 == hoedown_buffer_prefix(&B, str2));
          }
          hoedown_buffer_uninit(&B);


Previous: lib buffers compar, Up: lib buffers

4.2.6 Miscellaneous functions

The definitions of the buffers API are in the header file hoedown/buffer.h.

— Function: void hoedown_buffer_slurp (hoedown_buffer * buf, size_t size)

Remove a given number of bytes from the head of the buffer.

          hoedown_buffer              B;
          static const char *         str = "Hello World!";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_buffer_puts(&B, str);
            hoedown_buffer_slurp(&B, strlen("Hello "));
            assert(0 != hoedown_buffer_eqs(&B, "World!"));
          }
          hoedown_buffer_uninit(&B);
— Function: const char * hoedown_buffer_cstr (hoedown_buffer * buf)

Mutate the internal data area so that it valid as NUL-terminated C string. Return a pointer to the data area.

— Function: void hoedown_buffer_printf (hoedown_buffer * buf, const char * fmt, ...)

Formatted printing to a buffer.

          hoedown_buffer              B;
          static const char *         str1 = "Hello";
          static const char *         str2 = "World";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_buffer_printf(&B, "%s %s!", str1, str2);
            assert(0 != hoedown_buffer_eqs(&B, "Hello World!"));
          }
          hoedown_buffer_uninit(&B);


Next: , Previous: lib buffers, Up: lib

4.3 Stack containers


Next: , Up: lib stacks

4.3.1 Stack structures

The definitions of the stacks API are in the header file hoedown/stack.h.

— Struct Typedef: hoedown_stack

Type of structures representing stacks of pointers. Instances of this type must be initialised by hoedown_stack_init() and finalised by hoedown_stack_uninit().

Basic allocation, initialisation and finalisation can be performed as:

          hoedown_stack          B;
          
          hoedown_stack_init(&B, 123);
          hoedown_stack_uninit(&B);

The data area of stack structures is allocated and reallocated with hoedown_realloc() and released with C Language Standard free().

— Function: void hoedown_stack_init (hoedown_stack * st, size_t initial_size)

Initialize an already allocated stack structures.

— Function: void hoedown_stack_uninit (hoedown_stack * st)

Free internal data of the stack.

— Function: void hoedown_stack_grow (hoedown_stack * st, size_t neosz)

Increase the allocated size to the given value.


Previous: lib stacks struct, Up: lib stacks

4.3.2 Operations on stack structures

The definitions of the stacks API are in the header file hoedown/stack.h.

— Function: void hoedown_stack_push (hoedown_stack * st, void * item)

Push an item to the top of the stack.

— Function: void * hoedown_stack_pop (hoedown_stack * st)

Retrieve and remove the item at the top of the stack. If the stack is empty: return NULL.

— Function: void * hoedown_stack_top (const hoedown_stack * st)

Retrieve the item at the top of the stack. If the stack is empty: return NULL.


Next: , Previous: lib stacks, Up: lib

4.4 Escaping text elements

The definitions of the escaping API are in the header file hoedown/escape.h.

— Function: void hoedown_escape_href (hoedown_buffer * ob, const uint8_t * data, size_t size)

Escape (part of) a URL inside HTML. Escape all the characters in the data memory block that cannot appear in a URL; append the result to the buffer ob.

          hoedown_buffer      B;
          const char *        str1 = "Father & Son";
          const char *        str2 = "Father%20&amp;%20Son";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_escape_href(&B, (const uint8_t *)str1, strlen(str1));
            print_buffer(&B);
            assert(0 != hoedown_buffer_eqs(&B, str2));
          }
          hoedown_buffer_uninit(&B);
— Function: void hoedown_escape_html (hoedown_buffer * ob, const uint8_t * data, size_t size, int secure)

Escape HTML text from data and write the result in the buffer ob.

          hoedown_buffer      B;
          const char *        str1 = "Father & Son";
          const char *        str2 = "Father &amp; Son";
          hoedown_buffer_init(&B, 1024, realloc, free, free);
          {
            hoedown_escape_html(&B, (const uint8_t *)str1, strlen(str1), 1);
            print_buffer(&B);
            assert(0 != hoedown_buffer_eqs(&B, str2));
          }
          hoedown_buffer_uninit(&B);


Next: , Previous: lib escape, Up: lib

4.5 Autolink helpers

The definitions of the autolink API are in the header file hoedown/autolink.h.

— Enum Typedef: hoedown_autolink_flags

Type of constants used to configure the behaviour of the autolink helper functions. The following constants are defined:

HOEDOWN_AUTOLINK_SHORT_DOMAINS
When checking the presence of a domain specification: do not enforce validation of a domain in the strict sense (with least one dot); so just make sure it's composed of valid domain characters and return the length of the the valid sequence.

— Function: int hoedown_autolink_is_safe (const uint8_t * data, size_t size)

Verify that a URL has a safe protocol. Assume data references a memory block holding a string of UTF-8 encoded characters. Return true (non–zero) if the prefix of the string matches one among:

          http://
          https://
          /
          #
          ftp://
          mailto:

case insensitively, and the first octet after the prefix represents an alphanumeric character; otherwise return false (zero).

— Function: size_t hoedown_autolink__www (size_t * rewind_p, hoedown_buffer * link, uint8_t * w_ptr, size_t input_offset, size_t input_len, hoedown_autolink_flags flags)

Find the limits of a WWW link in the input Markdown buffer.

This function assumes that:

This function scans the input text starting at w_ptr looking for a sequence of octets representing, in UTF-8 encoding, a web link. The sequence must begin with the prefix ‘www.’ (of which w_ptr[0] is the first ‘w’) followed by a string of octets representing:

the string after ‘www.’ must contain at least one dot or one colon to be considered a valid web link.

If a valid web link is found:

If a valid web link is not found: the return value is zero.

          char *              input_text   = \
             "the URL is www.hoedown.org/index.html, got it?";
          size_t              input_len    = strlen(input_text);
          size_t              input_offset = strlen("the URL is ");
          
          uint8_t *           w_ptr = (uint8_t*)(input_text+input_offset);
          
          hoedown_buffer      link;
          size_t              offset_delta;
          size_t              rewind;
          
          assert('w' == input_text[input_offset]);
          assert('w' == w_ptr[0]);
          
          hoedown_buffer_init(&link, 1024, realloc, free, free);
          {
            offset_delta = hoedown_autolink__www(&rewind, &link,
               w_ptr, input_offset, input_len, 0);
            assert(strlen("www.hoedown.org/index.html") == offset_delta);
            assert(0 == rewind);
            assert(hoedown_buffer_eqs(&link, "www.hoedown.org/index.html"));
            assert(0 == strcmp((char *)(w_ptr+offset_delta), ", got it?"));
          }
          hoedown_buffer_uninit(&link);
— Function: size_t hoedown_autolink__email (size_t * rewind_p, hoedown_buffer * link, uint8_t * at_ptr, size_t input_offset, size_t input_len, hoedown_autolink_flags flags)

Find the limits of an email address link in the input Markdown buffer.

This function assumes that:

This function scans the input text starting at at_ptr, both in the left and right directions, looking for a sequence of octets representing, in UTF-8 encoding, an email address. The sequence must begin, to the left of the ‘@’ character, with a non–empty prefix composed of:

the sequence must end, to the right of the ‘@’ character, with a non–empty suffix composed of:

the suffix must represent a valid host name.

If a valid email address is found:

If a valid email address is not found: the return value is zero.

          char *              input_text   = \
            "the address is kate.beckinsale@underworld.earth, got it?";
          size_t              input_len    = strlen(input_text);
          size_t              input_offset = \
            strlen("the address is kate.beckinsale");
          
          uint8_t *           at_ptr = (uint8_t *)(input_text+input_offset);
          
          hoedown_buffer      link;
          size_t              offset_delta;
          size_t              rewind;
          
          assert('@' == input_text[input_offset]);
          assert('@' == at_ptr[0]);
          
          hoedown_buffer_init(&link, 1024, realloc, free, free);
          {
            offset_delta = hoedown_autolink__email(&rewind, &link,
               at_ptr, input_offset, input_len, 0);
            assert(strlen("@underworld.earth") == offset_delta);
            assert(strlen("kate.beckinsale") == rewind);
            assert(hoedown_buffer_eqs(&link,
               "kate.beckinsale@underworld.earth"));
            assert(rewind + offset_delta == link.size);
            assert(0 == strcmp((char *)(at_ptr+offset_delta), ", got it?"));
          }
          hoedown_buffer_uninit(&link);
— Function: size_t hoedown_autolink__url (size_t * rewind_p, hoedown_buffer * link, uint8_t * colon_ptr, size_t input_offset, size_t input_len, hoedown_autolink_flags flags)

Find the limits of a URL in the input Markdown buffer.

This function assumes that:

This function scans the input text starting at colon_ptr, both in the left and right directions, looking for a sequence of octets representing, in UTF-8 encoding, a URL. The sequence must begin, to the left of the colon character, with a non–empty prefix composed by alphabetic characters, according to the C Standard Library function isalpha(). The sequence must end, to the right of the colon character, with a non–empty suffix composed of:

If a valid URL is found:

If a valid URL is not found: the return value is zero.

This function honours the ‘HOEDOWN_AUTOLINK_SHORT_DOMAINS’ flag in the flags argument.

          char *              input_text   = \
             "the URL is http://www.hoedown.org/index.html, got it?";
          size_t              input_len    = strlen(input_text);
          size_t              input_offset = strlen("the URL is http");
          
          uint8_t *           colon_ptr = \
             (uint8_t *)(input_text+input_offset);
          
          hoedown_buffer      link;
          size_t              offset_delta;
          size_t              rewind;
          
          assert(':' == input_text[input_offset]);
          assert(':' == colon_ptr[0]);
          
          hoedown_buffer_init(&link, 1024, realloc, free, free);
          {
            offset_delta = hoedown_autolink__url(&rewind, &link,
               colon_ptr, input_offset, input_len, 0);
            assert(strlen("://www.hoedown.org/index.html") == offset_delta);
            assert(4 == rewind);
            assert(hoedown_buffer_eqs(&link,
               "http://www.hoedown.org/index.html"));
            assert(rewind + offset_delta == link.size);
            assert(0 == strcmp((char *)(colon_ptr+offset_delta),
                               ", got it?"));
          }
          hoedown_buffer_uninit(&link);


Next: , Previous: lib autolink, Up: lib

4.6 Processing Markdown documents


Next: , Up: lib document

4.6.1 Markdown processing introduction

The basic structure of code processing Markdown is this:

     #include <hoedown/buffer.h>
     #include <hoedown/document.h>
     #include <hoedown/html.h>
     
     void
     html_rend (const char * in_str, const char * ou_str)
     {
       hoedown_buffer                B;
       hoedown_document *            D;
       hoedown_renderer *            R;
     
       hoedown_buffer_init(&B, 1024, realloc, free, free);
       R = hoedown_html_renderer_new(0, 0);
       D = hoedown_document_new(R, 0, 16);
       {
         hoedown_document_render(D, &B,
            (const uint8_t *)in_str, strlen(in_str));
         /* Here the HTML output is in B.*/
       }
       hoedown_document_free(D);
       hoedown_html_renderer_free(R);
       hoedown_buffer_uninit(&B);
     }

and it can be used as follows:

     char *  in_str = "Hello World!";
     char *  ou_str = "<p>Hello World!</p>\n";
     html_rend (in_str, ou_str);


Next: , Previous: lib document intro, Up: lib document

4.6.2 Markdown processing API

The definitions of the document API are in the header file hoedown/document.h.

— Opaque Struct Typedef: hoedown_document

Type of structure used to represent the processing of a Markdown document. Instances of this type are allocated with hoedown_document_new() and released with hoedown_document_free().

— Struct Typedef: hoedown_renderer_data

Type of structure used to represent custom state of Markdown processing. It has the following public fields:

void * opaque
A pointer that can be used for anything by client code.

Pointers to a structure of this type are handed as last argument to all the document rendering callbacks registered in instances of hoedown_renderer. In particular: the callback doc_header can be used to initialise this state, and the callback doc_footer can be used to finalise it. Custom renderer data structure, for details on the renderer.

— Function: hoedown_document * hoedown_document_new (const hoedown_renderer * renderer, hoedown_extensions extensions, size_t max_nesting)

Allocate a new document processor instance.

The renderer argument must be a pointer to an renderer instance, for example the built–in HTML renderers created by hoedown_html_renderer_new() and hoedown_html_toc_renderer_new() (see lib html renderer).

The argument extensions must be an OR combination of the enumeration constants hoedown_extensions (see Markdown processing extensions).

The argument max_nesting represents the maximum nesting level of Markdown blocks. This limit exists for security purposes: it avoids malicious input to cause runaways of nested function calls in an attempt to cripple the internal state of the parser. Most likely, setting this operand to 16 is fine for all the legitimate input documents.

— Function: void hoedown_document_free (hoedown_document * doc)

Deallocate a document processor instance.

— Function: void hoedown_document_render (hoedown_document * doc, hoedown_buffer * ob, const uint8_t * data, size_t size)
— Function: void hoedown_document_render_inline (hoedown_document * doc, hoedown_buffer * ob, const uint8_t * data, size_t size)

Render regular Markdown or inline Markdown using the document processor.

The argument doc must reference an already initialised Markdown document renderer. The argument ob must reference an already initialised buffer to which the output will be appended. The argument data must reference an array of size octets containing the input Markdown text.

The input Markdown text is processed with the following rules:


Next: , Previous: lib document api, Up: lib document

4.6.3 Markdown processing extensions

The definitions of the document API are in the header file hoedown/document.h.

— Enum Typedef: hoedown_extensions

Enumeration typedef representing a combination of extensions to Markdown text processing. It defines the following constants:

— Preprocessor Constant: HOEDOWN_EXT_BLOCK

An OR combination of the following constants:

          HOEDOWN_EXT_TABLES
          HOEDOWN_EXT_FENCED_CODE
          HOEDOWN_EXT_FOOTNOTES
— Preprocessor Constant: HOEDOWN_EXT_SPAN

An OR combination of the following constants:

          HOEDOWN_EXT_AUTOLINK
          HOEDOWN_EXT_STRIKETHROUGH
          HOEDOWN_EXT_UNDERLINE
          HOEDOWN_EXT_HIGHLIGHT
          HOEDOWN_EXT_QUOTE
          HOEDOWN_EXT_SUPERSCRIPT
          HOEDOWN_EXT_MATH
— Preprocessor Constant: HOEDOWN_EXT_FLAGS

An OR combination of the following constants:

          HOEDOWN_EXT_NO_INTRA_EMPHASIS
          HOEDOWN_EXT_SPACE_HEADERS
          HOEDOWN_EXT_MATH_EXPLICIT
— Preprocessor Constant: HOEDOWN_EXT_NEGATIVE

An OR combination of the following constants:

          HOEDOWN_EXT_DISABLE_INDENTED_CODE


Previous: lib document ext, Up: lib document

4.6.4 Defining custom renderers


Next: , Up: lib document renderer
4.6.4.1 Custom renderer data structure

The definitions of the document API are in the header file hoedown/document.h.

— Struct Typedef: hoedown_renderer

Data structure typedef used to represent output renderers. Instances of this type must be dynamically allocated; the structure definition contains both public fields and private fields. When a struct field is unused: it must be set to NULL.

The following fields are defined:

blockcode
Block level callback; when set to NULL the block is skipped.
blockquote
Block level callback; when set to NULL the block is skipped.
header
Block level callback; when set to NULL the block is skipped.
hrule
Block level callback; when set to NULL the block is skipped.
list
Block level callback; when set to NULL the block is skipped.
listitem
Block level callback; when set to NULL the block is skipped.
paragraph
Block level callback; when set to NULL the block is skipped.
table
Block level callback; when set to NULL the block is skipped.
table_header
Block level callback; when set to NULL the block is skipped.
table_body
Block level callback; when set to NULL the block is skipped.
table_row
Block level callback; when set to NULL the block is skipped.
table_cell
Block level callback; when set to NULL the block is skipped.
footnotes
Block level callback; when set to NULL the block is skipped.
footnote_def
Block level callback; when set to NULL the block is skipped.
blockhtml
Block level callback; when set to NULL the block is skipped.
autolink
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
codespan
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
double_emphasis
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
emphasis
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
underline
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
highlight
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
quote
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
image
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
linebreak
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
link
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
triple_emphasis
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
strikethrough
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
superscript
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
footnote_ref
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
math
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
raw_html
Span level callback; when set to NULL or set to a function pointer returning 0: the span is printed verbatim.
entity
Low level callback; when set to NULL: copy the input directly into the output.
normal_text
Low level callback; when set to NULL: copy the input directly into the output.
doc_header
When set to NULL: no document header is generated.
doc_footer
When set to NULL: no document footer is generated.


Next: , Previous: lib document renderer struct, Up: lib document renderer
4.6.4.2 Rendering code blocks callback

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void blockcode (hoedown_buffer * ob, const hoedown_buffer * text, const hoedown_buffer * lang, const hoedown_renderer_data * data)

Callbacks used to render code blocks:

          

are set in the field blockcode of structures of type howdown_renderer.

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer blockcode, Up: lib document renderer
4.6.4.3 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void blockquote (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Callbacks used to render ???:

          

are set in the field blockquote of structures of type howdown_renderer.

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer blockquote, Up: lib document renderer
4.6.4.4 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void header (hoedown_buffer * ob, const hoedown_buffer * content, int level, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer header, Up: lib document renderer
4.6.4.5 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void hrule (hoedown_buffer * ob, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer hrule, Up: lib document renderer
4.6.4.6 Rendering lists

The definitions of the document API are in the header file hoedown/document.h.

— Enum Typedef: hoedown_list_flags

Enumeration typedef for constants describing numbered lists. It defines the following constants:

HOEDOWN_LIST_ORDERED
HOEDOWN_LI_BLOCK
<li>’ containing block data.

Bitwise OR compositions of these constants are used as argument to the list and listitem renderer callbacks.

— Callback Signature: void list (hoedown_buffer * ob, const hoedown_buffer * content, hoedown_list_flags flags, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer list, Up: lib document renderer
4.6.4.7 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void listitem (hoedown_buffer * ob, const hoedown_buffer * content, hoedown_list_flags flags, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer listitem, Up: lib document renderer
4.6.4.8 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void paragraph (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer paragraph, Up: lib document renderer
4.6.4.9 Rendering tables

The definitions of the document API are in the header file hoedown/document.h.

— Enum Typedef: hoedown_table_flags

Enumeration typedef for constants describing tables. It defines the following constants:

HOEDOWN_TABLE_ALIGN_LEFT

HOEDOWN_TABLE_ALIGN_RIGHT

HOEDOWN_TABLE_ALIGN_CENTER

HOEDOWN_TABLE_ALIGNMASK

HOEDOWN_TABLE_HEADER

Bitwise OR compositions of these constants are used as argument to the table_cell renderer callback.

— Callback Signature: void table (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer table, Up: lib document renderer
4.6.4.10 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void table_header (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer table_header, Up: lib document renderer
4.6.4.11 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void table_body (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer table_body, Up: lib document renderer
4.6.4.12 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void table_row (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer table_row, Up: lib document renderer
4.6.4.13 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void table_cell (hoedown_buffer * ob, const hoedown_buffer * content, hoedown_table_flags flags, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer table_cell, Up: lib document renderer
4.6.4.14 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void footnotes (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer footnotes, Up: lib document renderer
4.6.4.15 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void footnote_def (hoedown_buffer * ob, const hoedown_buffer * content, unsigned int num, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer footnote_def, Up: lib document renderer
4.6.4.16 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void blockhtml (hoedown_buffer * ob, const hoedown_buffer * text, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer blockhtml, Up: lib document renderer
4.6.4.17 Rendering autilinks

The definitions of the document API are in the header file hoedown/document.h.

— Enum Typedef: hoedown_autolink_type

Enumeration typedef for constants describing tables. It defines the following constants:

HOEDOWN_AUTOLINK_NONE

HOEDOWN_AUTOLINK_NORMAL

HOEDOWN_AUTOLINK_EMAIL

Bitwise OR compositions of these constants are used as argument to the autolink renderer callback.

— Callback Signature: int autolink (hoedown_buffer * ob, const hoedown_buffer *link, hoedown_autolink_type type, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer autolink, Up: lib document renderer
4.6.4.18 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int codespan (hoedown_buffer * ob, const hoedown_buffer * text, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer codespan, Up: lib document renderer
4.6.4.19 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int double_emphasis (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer double_emphasis, Up: lib document renderer
4.6.4.20 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int emphasis (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer emphasis, Up: lib document renderer
4.6.4.21 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int underline (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer underline, Up: lib document renderer
4.6.4.22 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int highlight (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer highlight, Up: lib document renderer
4.6.4.23 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int quote (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer quote, Up: lib document renderer
4.6.4.24 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int image (hoedown_buffer * ob, const hoedown_buffer * link, const hoedown_buffer * title, const hoedown_buffer * alt, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer image, Up: lib document renderer
4.6.4.25 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int linebreak (hoedown_buffer * ob, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer linebreak, Up: lib document renderer
4.6.4.26 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int link (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_buffer * link, const hoedown_buffer * title, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer link, Up: lib document renderer
4.6.4.27 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int triple_emphasis (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer triple_emphasis, Up: lib document renderer
4.6.4.28 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int strikethrough (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer strikethrough, Up: lib document renderer
4.6.4.29 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int superscript (hoedown_buffer * ob, const hoedown_buffer * content, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer superscript, Up: lib document renderer
4.6.4.30 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int footnote_ref (hoedown_buffer * ob, unsigned int num, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer footnote_ref, Up: lib document renderer
4.6.4.31 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int math (hoedown_buffer * ob, const hoedown_buffer * text, int displaymode, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer math, Up: lib document renderer
4.6.4.32 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: int raw_html (hoedown_buffer * ob, const hoedown_buffer * text, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer raw_html, Up: lib document renderer
4.6.4.33 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void entity (hoedown_buffer * ob, const hoedown_buffer * text, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer entity, Up: lib document renderer
4.6.4.34 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void normal_text (hoedown_buffer * ob, const hoedown_buffer * text, const hoedown_renderer_data * data)

Output text must be appended to the output buffer ob. The pointer data references a custom rendering data.


Next: , Previous: lib document renderer normal_text, Up: lib document renderer
4.6.4.35 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void doc_header (hoedown_buffer * ob, int inline_render, const hoedown_renderer_data * data)

Signature of callback functions used to render document headers; this callback is called before processing the input document. When the corresponding field in the hoedown_renderer is set to NULL: no document footer is generated.

Output text must be appended to the output buffer ob. The argument inline_render is true if this callback has been called while rendering an inline Markdown document; otherwise it is false. The pointer data references a custom rendering data.


Previous: lib document renderer doc_header, Up: lib document renderer
4.6.4.36 Rendering

The definitions of the document API are in the header file hoedown/document.h.

— Callback Signature: void doc_footer (hoedown_buffer * ob, int inline_render, const hoedown_renderer_data * data)

Signature of callback functions used to render document footers; this callback is called after processing the input document. When the corresponding field in the hoedown_renderer is set to NULL: no document footer is generated.

Output text must be appended to the output buffer ob. The argument inline_render is true if this callback has been called while rendering an inline Markdown document; otherwise it is false. The pointer data references a custom rendering data.


Previous: lib document, Up: lib

4.7 HTML generation

For examples of using the built–in HTML renderer HTML rendering examples.


Next: , Up: lib html

4.7.1 HTML from Markdown renderer

The basic structure of code using the built–in HTML renderer is this:

     void
     html_rend (const char * in_str, const char * ou_str)
     {
       hoedown_buffer                B;
       hoedown_document *            D;
       hoedown_renderer *            R;
     
       hoedown_buffer_init(&B, 1024, realloc, free, free);
       R = hoedown_html_renderer_new(0, 0);
       D = hoedown_document_new(R, 0, 16);
       {
         hoedown_document_render(D, &B,
            (const uint8_t *)in_str, strlen(in_str));
         assert(hoedown_buffer_eqs(&B, ou_str));
       }
       hoedown_document_free(D);
       hoedown_html_renderer_free(R);
       hoedown_buffer_uninit(&B);
     }

and it can be used as follows:

     /* Simple text. */
     {
       char *  in_str = "Hello World!";
       char *  ou_str = "<p>Hello World!</p>\n";
       html_rend (in_str, ou_str);
     }
     
     /* Code markup. */
     {
       char *  in_str = "```Hello World!```";
       char *  ou_str = "<p><code>Hello World!</code></p>\n";
       html_rend (in_str, ou_str);
     }
     
     /* Emphasis markup. */
     {
       char *  in_str = "*Hello World!*";
       char *  ou_str = "<p><em>Hello World!</em></p>\n";
       html_rend (in_str, ou_str);
     }
     
     /* Emphasis markup. */
     {
       char *  in_str = "[Hello World!]()";
       char *  ou_str = \
         "<p><a href=\"http://localhost/\">Hello World!</a></p>\n";
       html_rend (in_str, ou_str);
     }

The definitions of the HTML generation API are in the header file hoedown/html.h.

— Enum Typedef: hoedown_html_flags

Enumeration typedef used to configure the HTML renderer. It defines the following symbols:

HOEDOWN_HTML_SKIP_HTML

HOEDOWN_HTML_ESCAPE

HOEDOWN_HTML_HARD_WRAP

HOEDOWN_HTML_USE_XHTML

— Function: hoedown_renderer * hoedown_html_renderer_new (hoedown_html_flags render_flags, int nesting_level)

Allocate a regular HTML renderer.

The argument nesting_level is the maximum header nesting level to include in the table of contents: when set to ‘1’ only the top headers are included (‘<h1>’); when set to ‘2’ only the top headers and the subheaders are included (‘<h1>’ and ‘<h2>’); and so on. Here “inclusion in the table of contents” means that ‘<h1>’ and similar markups are generated with the anchor:

          <h1 id="toc_0">Heading</h1>

so that the table of contents can reference them using the fragment identifier:

          <a href="#toc_0">Heading</a>
— Function: hoedown_renderer * hoedown_html_toc_renderer_new (int nesting_level)

Like hoedown_html_renderer_new(), but the returned renderer produces the “Table of Contents” rather than a normal document.

The argument nesting_level is the maximum header nesting level to include in the table of contents: when set to ‘1’ only the top headers are included (‘<h1>’); when set to ‘2’ only the top headers and the subheaders are included (‘<h1>’ and ‘<h2>’); and so on.

We must be careful to generate a table of contents with nesting_level less than or equal to the value used when generating the full HTML document.

Rendering tables of contents, for examples of generating table of contents.

— Function: void hoedown_html_renderer_free (hoedown_renderer * renderer)

Deallocate an HTML renderer.


Next: , Previous: lib html renderer, Up: lib html

4.7.2 Processing HTML text with SmartyPants

The definitions of the HTML generation API are in the header file hoedown/html.h.

— Function: void hoedown_html_smartypants (hoedown_buffer * ob, const uint8_t * data, size_t size)

Take the memory block referenced by data, containing size octets, and process it as HTML text; the resulting output is appended to the buffer ob.

Translate plain ASCII punctuation characters into “smart” typographic punctuation HTML entities. SmartyPants performs the following transformations:


Previous: lib html smartypants, Up: lib html

4.7.3 Miscellaneous HTML helpers

The definitions of the HTML generation API are in the header file hoedown/html.h.

— Enum Typedef: hoedown_html_tag

Enumeration type definitions used to qualify HTML markups. It includes the following symbols:

OEDOWN_HTML_TAG_NONE
Defined to be ‘0’. It means the analysed text is not a HTML markup.
HOEDOWN_HTML_TAG_OPEN,
It means the analysed text is not an opening HTML markup.
HOEDOWN_HTML_TAG_CLOSE
It means the analysed text is not a closing HTML markup.

— Function: hoedown_html_tag hoedown_html_is_tag (const uint8_t * data, size_t size, const char * tagname)

Check if data starts with a specific HTML markup whose name is tagname; return the markup type or ‘OEDOWN_HTML_TAG_NONE’ if the text is not a markup.

          static const char *  str = "Hello World!";
          assert(HOEDOWN_HTML_TAG_NONE == \
            hoedown_html_is_tag((const uint8_t *) str, strlen(str), "p"));
          
          static const char *  str = "<p>Hello World!</p>";
          assert(HOEDOWN_HTML_TAG_OPEN == \
            hoedown_html_is_tag((const uint8_t *) str, strlen(str), "p"));
          
          static const char *  str = "</p><p>Hello World!</p>";
          assert(HOEDOWN_HTML_TAG_CLOSE == \
            hoedown_html_is_tag((const uint8_t *) str, strlen(str), "p"));


Next: , Previous: lib, Up: Top

Appendix A Bibliography and references

The latest release of the repackaged Hoedown can be downloaded from:

https://bitbucket.org/marcomaggi/hoedown/downloads

the original package development takes place at:

http://github.com/hoedown/hoedown

development of the repackaging takes place at:

http://github.com/marcomaggi/hoedown

and as backup at:

https://bitbucket.org/marcomaggi/hoedown


Next: , Previous: references, Up: Top

Appendix B HTML rendering examples


Up: htmlex

B.1 Rendering table of contents

Let's consider the following code that renders and prints a table of contents:

     void
     print_buffer (hoedown_buffer * B)
     {
       fwrite(B->data, B->size, 1, stderr);
       fprintf(stderr, "\n");
     }
     static void
     html_toc_rend (const char * in_str, int nesting_level)
     {
       hoedown_buffer                B;
       hoedown_document *            D;
       hoedown_renderer *            R;
     
       hoedown_buffer_init(&B, 1024, realloc, free, free);
       R = hoedown_html_toc_renderer_new(nesting_level);
       D = hoedown_document_new(R, 0, 16);
       {
         hoedown_document_render(D, &B, (const uint8_t *)in_str, strlen(in_str));
         print_buffer(&B);
       }
       hoedown_document_free(D);
       hoedown_html_renderer_free(R);
       hoedown_buffer_uninit(&B);
     }

Let's see what it generates:


Next: , Previous: htmlex, Up: Top

Appendix C An entry for each concept


Next: , Previous: concept index, Up: Top

Appendix D An entry for each function.


Next: , Previous: function index, Up: Top

Appendix E An entry for each variable.


Previous: variable index, Up: Top

Appendix F An entry for each type.

Table of Contents