diff options
| -rw-r--r-- | CMakeLists.txt | 4 | ||||
| -rw-r--r-- | application/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | application/dialogs/UpdateDialog.cpp | 201 | ||||
| -rw-r--r-- | depends/hoedown/CMakeLists.txt | 29 | ||||
| -rw-r--r-- | depends/hoedown/LICENSE | 15 | ||||
| -rw-r--r-- | depends/hoedown/README.md | 9 | ||||
| -rw-r--r-- | depends/hoedown/hoedown/autolink.h | 46 | ||||
| -rw-r--r-- | depends/hoedown/hoedown/buffer.h | 134 | ||||
| -rw-r--r-- | depends/hoedown/hoedown/document.h | 172 | ||||
| -rw-r--r-- | depends/hoedown/hoedown/escape.h | 28 | ||||
| -rw-r--r-- | depends/hoedown/hoedown/html.h | 84 | ||||
| -rw-r--r-- | depends/hoedown/hoedown/stack.h | 52 | ||||
| -rw-r--r-- | depends/hoedown/hoedown/version.h | 33 | ||||
| -rw-r--r-- | depends/hoedown/src/autolink.c | 281 | ||||
| -rw-r--r-- | depends/hoedown/src/buffer.c | 308 | ||||
| -rw-r--r-- | depends/hoedown/src/document.c | 2958 | ||||
| -rw-r--r-- | depends/hoedown/src/escape.c | 188 | ||||
| -rw-r--r-- | depends/hoedown/src/html.c | 754 | ||||
| -rw-r--r-- | depends/hoedown/src/html_blocks.c | 240 | ||||
| -rw-r--r-- | depends/hoedown/src/html_smartypants.c | 435 | ||||
| -rw-r--r-- | depends/hoedown/src/stack.c | 79 | ||||
| -rw-r--r-- | depends/hoedown/src/version.c | 9 |
22 files changed, 5915 insertions, 145 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a21f23c3..fde28a4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,7 +92,9 @@ else() set(QUAZIP_LIBRARIES -L"${CMAKE_BINARY_DIR}/External/Install/QuaZIP/lib" quazip) endif() - +# Add the markdown parser thing +add_subdirectory(depends/hoedown) +include_directories(${HOEDOWN_INCLUDE_DIR}) # Add the java launcher and checker add_subdirectory(depends/launcher) diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index f0dc8460..b179927f 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -345,6 +345,7 @@ qt5_add_resources(MULTIMC_RESOURCES ${MULTIMC_QRCS}) add_executable(MultiMC MACOSX_BUNDLE WIN32 ${MULTIMC_SOURCES} ${MULTIMC_UI} ${MULTIMC_RESOURCES} ${MULTIMC_RCS}) target_link_libraries(MultiMC MultiMC_logic xz-embedded unpack200 iconfix libUtil LogicalGui ${QUAZIP_LIBRARIES} Qt5::Core Qt5::Xml Qt5::Widgets Qt5::Network Qt5::Concurrent + hoedown ${MultiMC_LINK_ADDITIONAL_LIBS}) ################################ INSTALLATION AND PACKAGING ################################ diff --git a/application/dialogs/UpdateDialog.cpp b/application/dialogs/UpdateDialog.cpp index 37e44b1e..d8f5d8ac 100644 --- a/application/dialogs/UpdateDialog.cpp +++ b/application/dialogs/UpdateDialog.cpp @@ -5,6 +5,9 @@ #include "MultiMC.h" #include <settings/SettingsObject.h> +#include <hoedown/html.h> +#include <hoedown/document.h> + UpdateDialog::UpdateDialog(bool hasUpdate, QWidget *parent) : QDialog(parent), ui(new Ui::UpdateDialog) { MultiMCPlatform::fixWM_CLASS(this); @@ -39,166 +42,76 @@ void UpdateDialog::loadChangelog() dljob->start(); } -// TODO: this will be replaced. -QString reprocessMarkdown(QString markdown) +/** + * hoedown wrapper, because dealing with resource lifetime in C is stupid + */ +class HoeDown { - QString htmlData; - QTextStream html(&htmlData); - auto lines = markdown.split(QRegExp("[\r]?[\n]"),QString::KeepEmptyParts); - enum - { - BASE, - LIST1, - LIST2 - }state = BASE; - html << "<html>"; - int i = 0; - auto procLine = [&](QString line) -> QString +public: + class buffer { - // [GitHub issues](https://github.com/MultiMC/MultiMC5/issues) - line.replace(QRegExp("\\[([^\\]]+)\\]\\(([^\\)]+)\\)"), "<a href=\"\\2\">\\1</a>"); - line.replace(QRegExp("GH-([0-9]+)"), "<a href=\"https://github.com/MultiMC/MultiMC5/issues/\\1\">GH-\\1</a>"); - line.replace(QRegExp("\\*\\*([^*]+)\\*\\*"), "<b>\\1</b>"); - line.replace(QRegExp("\\*([^*]+)\\*"), "<i>\\1</i>"); - return line; - }; - for(auto line: lines) - { - if(line.isEmpty()) + public: + buffer(size_t unit = 4096) { - // html << "<br />\n"; + buf = hoedown_buffer_new(unit); } - else switch (state) + ~buffer() { - case BASE: - if(line.startsWith("####")) - { - html << "<h4>" << procLine(line.mid(4)) << "</h4>\n"; - } - if(line.startsWith("###")) - { - html << "<h3>" << procLine(line.mid(3)) << "</h3>\n"; - } - if(line.startsWith("##")) - { - html << "<h2>" << procLine(line.mid(2)) << "</h2>\n"; - } - else if(line.startsWith("#")) - { - html << "<h1>" << procLine(line.mid(1)) << "</h1>\n"; - } - else if(line.startsWith("- ")) - { - state = LIST1; - html << "<ul>\n"; - html << "<li>" << procLine(line.mid(2)) << "</li>\n"; - } - else qCritical() << "Invalid input on line " << i << ": " << line; - break; - case LIST1: - if(line.startsWith("####")) - { - state = BASE; - html << "</ul>\n"; - html << "<h4>" << procLine(line.mid(4)) << "</h4>\n"; - } - else if(line.startsWith("###")) - { - state = BASE; - html << "</ul>\n"; - html << "<h3>" << procLine(line.mid(3)) << "</h3>\n"; - } - if(line.startsWith("##")) - { - state = BASE; - html << "</ul>\n"; - html << "<h2>" << procLine(line.mid(2)) << "</h2>\n"; - } - else if(line.startsWith("#")) - { - state = BASE; - html << "</ul>\n"; - html << "<h1>" << procLine(line.mid(1)) << "</h1>\n"; - } - else if(line.startsWith("- ")) - { - html << "<li>" << procLine(line.mid(2)) << "</li>\n"; - } - else if(line.startsWith(" - ")) - { - state = LIST2; - html << "<ul>\n"; - html << "<li>" << procLine(line.mid(4)) << "</li>\n"; - } - else qCritical() << "Invalid input on line " << i << ": " << line; - break; - case LIST2: - if(line.startsWith("####")) - { - state = BASE; - html << "</ul>\n"; - html << "</ul>\n"; - html << "<h4>" << procLine(line.mid(4)) << "</h4>\n"; - } - else if(line.startsWith("###")) - { - state = BASE; - html << "</ul>\n"; - html << "</ul>\n"; - html << "<h3>" << procLine(line.mid(3)) << "</h3>\n"; - } - if(line.startsWith("##")) - { - state = BASE; - html << "</ul>\n"; - html << "</ul>\n"; - html << "<h2>" << procLine(line.mid(2)) << "</h2>\n"; - } - else if(line.startsWith("#")) - { - state = BASE; - html << "</ul>\n"; - html << "</ul>\n"; - html << "<h1>" << procLine(line.mid(1)) << "</h1>\n"; - } - else if(line.startsWith("- ")) - { - state = LIST1; - html << "</ul>\n"; - html << "<li>" << procLine(line.mid(2)) << "</li>\n"; - } - else if(line.startsWith(" - ")) - { - html << "<li>" << procLine(line.mid(4)) << "</li>\n"; - } - else qCritical() << "Invalid input on line " << i << ": " << line; - break; + hoedown_buffer_free(buf); } - i++; - } - if(state == LIST2) + const char * cstr() + { + return hoedown_buffer_cstr(buf); + } + void put(QByteArray input) + { + hoedown_buffer_put(buf, (uint8_t *) input.data(), input.size()); + } + const uint8_t * data() const + { + return buf->data; + } + size_t size() const + { + return buf->size; + } + hoedown_buffer * buf; + } ib, ob; + HoeDown() { - html << "</ul>\n"; - state = LIST1; + renderer = hoedown_html_renderer_new((hoedown_html_flags) 0,0); + document = hoedown_document_new(renderer, (hoedown_extensions) 0, 8); } - if(state == LIST1) + ~HoeDown() { - html << "</ul>\n"; - state = BASE; + hoedown_document_free(document); + hoedown_html_renderer_free(renderer); } - if (state != BASE) + QString process(QByteArray input) { - qCritical() << "Reprocessing markdown didn't end in a final state!"; + ib.put(input); + hoedown_document_render(document, ob.buf, ib.data(), ib.size()); + return ob.cstr(); } - html << "</html>\n"; - qDebug() << htmlData; - return htmlData; +private: + hoedown_document * document; + hoedown_renderer * renderer; +}; + +QString reprocessMarkdown(QByteArray markdown) +{ + HoeDown hoedown; + QString output = hoedown.process(markdown); + + // HACK: easier than customizing hoedown + output.replace(QRegExp("GH-([0-9]+)"), "<a href=\"https://github.com/MultiMC/MultiMC5/issues/\\1\">GH-\\1</a>"); + qDebug() << output; + return output; } void UpdateDialog::changelogLoaded() { - auto rawMarkdown = QString::fromUtf8(changelogDownload->m_data); - auto html = reprocessMarkdown(rawMarkdown); + auto html = reprocessMarkdown(changelogDownload->m_data); ui->changelogBrowser->setHtml(html); } diff --git a/depends/hoedown/CMakeLists.txt b/depends/hoedown/CMakeLists.txt new file mode 100644 index 00000000..b4ef8ef9 --- /dev/null +++ b/depends/hoedown/CMakeLists.txt @@ -0,0 +1,29 @@ +# hoedown 3.0.2 - https://github.com/hoedown/hoedown/archive/3.0.2.tar.gz +project(hoedown) + +set(HOEDOWN_SOURCES +hoedown/autolink.h +hoedown/buffer.h +hoedown/document.h +hoedown/escape.h +hoedown/html.h +hoedown/stack.h +hoedown/version.h +src/autolink.c +src/buffer.c +src/document.c +src/escape.c +src/html.c +src/html_blocks.c +src/html_smartypants.c +src/stack.c +src/version.c +) + +# Set the include dir path. +set(HOEDOWN_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE) + +# Include self. +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +add_library(hoedown STATIC ${HOEDOWN_SOURCES}) diff --git a/depends/hoedown/LICENSE b/depends/hoedown/LICENSE new file mode 100644 index 00000000..4e75de4d --- /dev/null +++ b/depends/hoedown/LICENSE @@ -0,0 +1,15 @@ +Copyright (c) 2008, Natacha Porté +Copyright (c) 2011, Vicent Martí +Copyright (c) 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. diff --git a/depends/hoedown/README.md b/depends/hoedown/README.md new file mode 100644 index 00000000..abe2b6ca --- /dev/null +++ b/depends/hoedown/README.md @@ -0,0 +1,9 @@ +Hoedown +======= + +This is Hoedown 3.0.2, taken from [the hoedown github repo](https://github.com/hoedown/hoedown). + +`Hoedown` is a revived fork of [Sundown](https://github.com/vmg/sundown), +the Markdown parser based on the original code of the +[Upskirt library](http://fossil.instinctive.eu/libupskirt/index) +by Natacha Porté. diff --git a/depends/hoedown/hoedown/autolink.h b/depends/hoedown/hoedown/autolink.h new file mode 100644 index 00000000..528885c9 --- /dev/null +++ b/depends/hoedown/hoedown/autolink.h @@ -0,0 +1,46 @@ +/* autolink.h - versatile autolinker */ + +#ifndef HOEDOWN_AUTOLINK_H +#define HOEDOWN_AUTOLINK_H + +#include "buffer.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/************* + * CONSTANTS * + *************/ + +typedef enum hoedown_autolink_flags { + HOEDOWN_AUTOLINK_SHORT_DOMAINS = (1 << 0) +} hoedown_autolink_flags; + + +/************* + * FUNCTIONS * + *************/ + +/* hoedown_autolink_is_safe: verify that a URL has a safe protocol */ +int hoedown_autolink_is_safe(const uint8_t *data, size_t size); + +/* hoedown_autolink__www: search for the next www link in data */ +size_t hoedown_autolink__www(size_t *rewind_p, hoedown_buffer *link, + uint8_t *data, size_t offset, size_t size, hoedown_autolink_flags flags); + +/* hoedown_autolink__email: search for the next email in data */ +size_t hoedown_autolink__email(size_t *rewind_p, hoedown_buffer *link, + uint8_t *data, size_t offset, size_t size, hoedown_autolink_flags flags); + +/* hoedown_autolink__url: search for the next URL in data */ +size_t hoedown_autolink__url(size_t *rewind_p, hoedown_buffer *link, + uint8_t *data, size_t offset, size_t size, hoedown_autolink_flags flags); + + +#ifdef __cplusplus +} +#endif + +#endif /** HOEDOWN_AUTOLINK_H **/ diff --git a/depends/hoedown/hoedown/buffer.h b/depends/hoedown/hoedown/buffer.h new file mode 100644 index 00000000..d7703f8d --- /dev/null +++ b/depends/hoedown/hoedown/buffer.h @@ -0,0 +1,134 @@ +/* buffer.h - simple, fast buffers */ + +#ifndef HOEDOWN_BUFFER_H +#define HOEDOWN_BUFFER_H + +#include <stdio.h> +#include <stddef.h> +#include <stdarg.h> +#include <stdint.h> +#include <stdlib.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_MSC_VER) +#define __attribute__(x) +#define inline __inline +#define __builtin_expect(x,n) x +#endif + + +/********* + * TYPES * + *********/ + +typedef void *(*hoedown_realloc_callback)(void *, size_t); +typedef void (*hoedown_free_callback)(void *); + +struct hoedown_buffer { + uint8_t *data; /* actual character data */ + size_t size; /* size of the string */ + size_t asize; /* allocated size (0 = volatile buffer) */ + size_t unit; /* reallocation unit size (0 = read-only buffer) */ + + hoedown_realloc_callback data_realloc; + hoedown_free_callback data_free; + hoedown_free_callback buffer_free; +}; + +typedef struct hoedown_buffer hoedown_buffer; + + +/************* + * FUNCTIONS * + *************/ + +/* allocation wrappers */ +void *hoedown_malloc(size_t size) __attribute__ ((malloc)); +void *hoedown_calloc(size_t nmemb, size_t size) __attribute__ ((malloc)); +void *hoedown_realloc(void *ptr, size_t size) __attribute__ ((malloc)); + +/* hoedown_buffer_init: initialize a buffer with custom allocators */ +void hoedown_buffer_init( + hoedown_buffer *buffer, + size_t unit, + hoedown_realloc_callback data_realloc, + hoedown_free_callback data_free, + hoedown_free_callback buffer_free +); + +/* hoedown_buffer_uninit: uninitialize an existing buffer */ +void hoedown_buffer_uninit(hoedown_buffer *buf); + +/* hoedown_buffer_new: allocate a new buffer */ +hoedown_buffer *hoedown_buffer_new(size_t unit) __attribute__ ((malloc)); + +/* hoedown_buffer_reset: free internal data of the buffer */ +void hoedown_buffer_reset(hoedown_buffer *buf); + +/* hoedown_buffer_grow: increase the allocated size to the given value */ +void hoedown_buffer_grow(hoedown_buffer *buf, size_t neosz); + +/* hoedown_buffer_put: append raw data to a buffer */ +void hoedown_buffer_put(hoedown_buffer *buf, const uint8_t *data, size_t size); + +/* hoedown_buffer_puts: append a NUL-terminated string to a buffer */ +void hoedown_buffer_puts(hoedown_buffer *buf, const char *str); + +/* hoedown_buffer_putc: append a single char to a buffer */ +void hoedown_buffer_putc(hoedown_buffer *buf, uint8_t c); + +/* hoedown_buffer_putf: read from a file and append to a buffer, until EOF or error */ +int hoedown_buffer_putf(hoedown_buffer *buf, FILE* file); + +/* hoedown_buffer_set: replace the buffer's contents with raw data */ +void hoedown_buffer_set(hoedown_buffer *buf, const uint8_t *data, size_t size); + +/* hoedown_buffer_sets: replace the buffer's contents with a NUL-terminated string */ +void hoedown_buffer_sets(hoedown_buffer *buf, const char *str); + +/* hoedown_buffer_eq: compare a buffer's data with other data for equality */ +int hoedown_buffer_eq(const hoedown_buffer *buf, const uint8_t *data, size_t size); + +/* hoedown_buffer_eq: compare a buffer's data with NUL-terminated string for equality */ +int hoedown_buffer_eqs(const hoedown_buffer *buf, const char *str); + +/* hoedown_buffer_prefix: compare the beginning of a buffer with a string */ +int hoedown_buffer_prefix(const hoedown_buffer *buf, const char *prefix); + +/* hoedown_buffer_slurp: remove a given number of bytes from the head of the buffer */ +void hoedown_buffer_slurp(hoedown_buffer *buf, size_t size); + +/* hoedown_buffer_cstr: NUL-termination of the string array (making a C-string) */ +const char *hoedown_buffer_cstr(hoedown_buffer *buf); + +/* hoedown_buffer_printf: formatted printing to a buffer */ +void hoedown_buffer_printf(hoedown_buffer *buf, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); + +/* hoedown_buffer_put_utf8: put a Unicode character encoded as UTF-8 */ +void hoedown_buffer_put_utf8(hoedown_buffer *buf, unsigned int codepoint); + +/* hoedown_buffer_free: free the buffer */ +void hoedown_buffer_free(hoedown_buffer *buf); + + +/* HOEDOWN_BUFPUTSL: optimized hoedown_buffer_puts of a string literal */ +#define HOEDOWN_BUFPUTSL(output, literal) \ + hoedown_buffer_put(output, (const uint8_t *)literal, sizeof(literal) - 1) + +/* HOEDOWN_BUFSETSL: optimized hoedown_buffer_sets of a string literal */ +#define HOEDOWN_BUFSETSL(output, literal) \ + hoedown_buffer_set(output, (const uint8_t *)literal, sizeof(literal) - 1) + +/* HOEDOWN_BUFEQSL: optimized hoedown_buffer_eqs of a string literal */ +#define HOEDOWN_BUFEQSL(output, literal) \ + hoedown_buffer_eq(output, (const uint8_t *)literal, sizeof(literal) - 1) + + +#ifdef __cplusplus +} +#endif + +#endif /** HOEDOWN_BUFFER_H **/ diff --git a/depends/hoedown/hoedown/document.h b/depends/hoedown/hoedown/document.h new file mode 100644 index 00000000..a8178fec --- /dev/null +++ b/depends/hoedown/hoedown/document.h @@ -0,0 +1,172 @@ +/* document.h - generic markdown parser */ + +#ifndef HOEDOWN_DOCUMENT_H +#define HOEDOWN_DOCUMENT_H + +#include "buffer.h" +#include "autolink.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/************* + * CONSTANTS * + *************/ + +typedef enum hoedown_extensions { + /* block-level extensions */ + HOEDOWN_EXT_TABLES = (1 << 0), + HOEDOWN_EXT_FENCED_CODE = (1 << 1), + HOEDOWN_EXT_FOOTNOTES = (1 << 2), + + /* span-level extensions */ + HOEDOWN_EXT_AUTOLINK = (1 << 3), + HOEDOWN_EXT_STRIKETHROUGH = (1 << 4), + HOEDOWN_EXT_UNDERLINE = (1 << 5), + HOEDOWN_EXT_HIGHLIGHT = (1 << 6), + HOEDOWN_EXT_QUOTE = (1 << 7), + HOEDOWN_EXT_SUPERSCRIPT = (1 << 8), + HOEDOWN_EXT_MATH = (1 << 9), + + /* other flags */ + HOEDOWN_EXT_NO_INTRA_EMPHASIS = (1 << 11), + HOEDOWN_EXT_SPACE_HEADERS = (1 << 12), + HOEDOWN_EXT_MATH_EXPLICIT = (1 << 13), + + /* negative flags */ + HOEDOWN_EXT_DISABLE_INDENTED_CODE = (1 << 14) +} hoedown_extensions; + +#define HOEDOWN_EXT_BLOCK (\ + HOEDOWN_EXT_TABLES |\ + HOEDOWN_EXT_FENCED_CODE |\ + HOEDOWN_EXT_FOOTNOTES ) + +#define HOEDOWN_EXT_SPAN (\ + HOEDOWN_EXT_AUTOLINK |\ + HOEDOWN_EXT_STRIKETHROUGH |\ + HOEDOWN_EXT_UNDERLINE |\ + HOEDOWN_EXT_HIGHLIGHT |\ + HOEDOWN_EXT_QUOTE |\ + HOEDOWN_EXT_SUPERSCRIPT |\ + HOEDOWN_EXT_MATH ) + +#define HOEDOWN_EXT_FLAGS (\ + HOEDOWN_EXT_NO_INTRA_EMPHASIS |\ + HOEDOWN_EXT_SPACE_HEADERS |\ + HOEDOWN_EXT_MATH_EXPLICIT ) + +#define HOEDOWN_EXT_NEGATIVE (\ + HOEDOWN_EXT_DISABLE_INDENTED_CODE ) + +typedef enum hoedown_list_flags { + HOEDOWN_LIST_ORDERED = (1 << 0), + HOEDOWN_LI_BLOCK = (1 << 1) /* <li> containing block data */ +} hoedown_list_flags; + +typedef enum hoedown_table_flags { + HOEDOWN_TABLE_ALIGN_LEFT = 1, + HOEDOWN_TABLE_ALIGN_RIGHT = 2, + HOEDOWN_TABLE_ALIGN_CENTER = 3, + HOEDOWN_TABLE_ALIGNMASK = 3, + HOEDOWN_TABLE_HEADER = 4 +} hoedown_table_flags; + +typedef enum hoedown_autolink_type { + HOEDOWN_AUTOLINK_NONE, /* used internally when it is not an autolink*/ + HOEDOWN_AUTOLINK_NORMAL, /* normal http/http/ftp/mailto/etc link */ + HOEDOWN_AUTOLINK_EMAIL /* e-mail link without explit mailto: */ +} hoedown_autolink_type; + + +/********* + * TYPES * + *********/ + +struct hoedown_document; +typedef struct hoedown_document hoedown_document; + +struct hoedown_renderer_data { + void *opaque; +}; +typedef struct hoedown_renderer_data hoedown_renderer_data; + +/* hoedown_renderer - functions for rendering parsed data */ +struct hoedown_renderer { + /* state object */ + void *opaque; + + /* block level callbacks - NULL skips the block */ + void (*blockcode)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_buffer *lang, const hoedown_renderer_data *data); + void (*blockquote)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + void (*header)(hoedown_buffer *ob, const hoedown_buffer *content, int level, const hoedown_renderer_data *data); + void (*hrule)(hoedown_buffer *ob, const hoedown_renderer_data *data); + void (*list)(hoedown_buffer *ob, const hoedown_buffer *content, hoedown_list_flags flags, const hoedown_renderer_data *data); + void (*listitem)(hoedown_buffer *ob, const hoedown_buffer *content, hoedown_list_flags flags, const hoedown_renderer_data *data); + void (*paragraph)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + void (*table)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + void (*table_header)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + void (*table_body)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + void (*table_row)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + void (*table_cell)(hoedown_buffer *ob, const hoedown_buffer *content, hoedown_table_flags flags, const hoedown_renderer_data *data); + void (*footnotes)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + void (*footnote_def)(hoedown_buffer *ob, const hoedown_buffer *content, unsigned int num, const hoedown_renderer_data *data); + void (*blockhtml)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data); + + /* span level callbacks - NULL or return 0 prints the span verbatim */ + int (*autolink)(hoedown_buffer *ob, const hoedown_buffer *link, hoedown_autolink_type type, const hoedown_renderer_data *data); + int (*codespan)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data); + int (*double_emphasis)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + int (*emphasis)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + int (*underline)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + int (*highlight)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + int (*quote)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + int (*image)(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_buffer *alt, const hoedown_renderer_data *data); + int (*linebreak)(hoedown_buffer *ob, const hoedown_renderer_data *data); + int (*link)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_renderer_data *data); + int (*triple_emphasis)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + int (*strikethrough)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + int (*superscript)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data); + int (*footnote_ref)(hoedown_buffer *ob, unsigned int num, const hoedown_renderer_data *data); + int (*math)(hoedown_buffer *ob, const hoedown_buffer *text, int displaymode, const hoedown_renderer_data *data); + int (*raw_html)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data); + + /* low level callbacks - NULL copies input directly into the output */ + void (*entity)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data); + void (*normal_text)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data); + + /* miscellaneous callbacks */ + void (*doc_header)(hoedown_buffer *ob, int inline_render, const hoedown_renderer_data *data); + void (*doc_footer)(hoedown_buffer *ob, int inline_render, const hoedown_renderer_data *data); +}; +typedef struct hoedown_renderer hoedown_renderer; + + +/************* + * FUNCTIONS * + *************/ + +/* hoedown_document_new: allocate a new document processor instance */ +hoedown_document *hoedown_document_new( + const hoedown_renderer *renderer, + hoedown_extensions extensions, + size_t max_nesting +) __attribute__ ((malloc)); + +/* hoedown_document_render: render regular Markdown using the document processor */ +void hoedown_document_render(hoedown_document *doc, hoedown_buffer *ob, const uint8_t *data, size_t size); + +/* hoedown_document_render_inline: render inline Markdown using the document processor */ +void hoedown_document_render_inline(hoedown_document *doc, hoedown_buffer *ob, const uint8_t *data, size_t size); + +/* hoedown_document_free: deallocate a document processor instance */ +void hoedown_document_free(hoedown_document *doc); + + +#ifdef __cplusplus +} +#endif + +#endif /** HOEDOWN_DOCUMENT_H **/ diff --git a/depends/hoedown/hoedown/escape.h b/depends/hoedown/hoedown/escape.h new file mode 100644 index 00000000..d7659c27 --- /dev/null +++ b/depends/hoedown/hoedown/escape.h @@ -0,0 +1,28 @@ +/* escape.h - escape utilities */ + +#ifndef HOEDOWN_ESCAPE_H +#define HOEDOWN_ESCAPE_H + +#include "buffer.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/************* + * FUNCTIONS * + *************/ + +/* hoedown_escape_href: escape (part of) a URL inside HTML */ +void hoedown_escape_href(hoedown_buffer *ob, const uint8_t *data, size_t size); + +/* hoedown_escape_html: escape HTML */ +void hoedown_escape_html(hoedown_buffer *ob, const uint8_t *data, size_t size, int secure); + + +#ifdef __cplusplus +} +#endif + +#endif /** HOEDOWN_ESCAPE_H **/ diff --git a/depends/hoedown/hoedown/html.h b/depends/hoedown/hoedown/html.h new file mode 100644 index 00000000..e46e7fd6 --- /dev/null +++ b/depends/hoedown/hoedown/html.h @@ -0,0 +1,84 @@ +/* html.h - HTML renderer and utilities */ + +#ifndef HOEDOWN_HTML_H +#define HOEDOWN_HTML_H + +#include "document.h" +#include "buffer.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/************* + * CONSTANTS * + *************/ + +typedef enum hoedown_html_flags { + HOEDOWN_HTML_SKIP_HTML = (1 << 0), + HOEDOWN_HTML_ESCAPE = (1 << 1), + HOEDOWN_HTML_HARD_WRAP = (1 << 2), + HOEDOWN_HTML_USE_XHTML = (1 << 3) +} hoedown_html_flags; + +typedef enum hoedown_html_tag { + HOEDOWN_HTML_TAG_NONE = 0, + HOEDOWN_HTML_TAG_OPEN, + HOEDOWN_HTML_TAG_CLOSE +} hoedown_html_tag; + + +/********* + * TYPES * + *********/ + +struct hoedown_html_renderer_state { + void *opaque; + + struct { + int header_count; + int current_level; + int level_offset; + int nesting_level; + } toc_data; + + hoedown_html_flags flags; + + /* extra callbacks */ + void (*link_attributes)(hoedown_buffer *ob, const hoedown_buffer *url, const hoedown_renderer_data *data); +}; +typedef struct hoedown_html_renderer_state hoedown_html_renderer_state; + + +/************* + * FUNCTIONS * + *************/ + +/* hoedown_html_smartypants: process an HTML snippet using SmartyPants for smart punctuation */ +void hoedown_html_smartypants(hoedown_buffer *ob, const uint8_t *data, size_t size); + +/* hoedown_html_is_tag: checks if data starts with a specific tag, returns the tag type or NONE */ +hoedown_html_tag hoedown_html_is_tag(const uint8_t *data, size_t size, const char *tagname); + + +/* hoedown_html_renderer_new: allocates a regular HTML renderer */ +hoedown_renderer *hoedown_html_renderer_new( + hoedown_html_flags render_flags, + int nesting_level +) __attribute__ ((malloc)); + +/* hoedown_html_toc_renderer_new: like hoedown_html_renderer_new, but the returned renderer produces the Table of Contents */ +hoedown_renderer *hoedown_html_toc_renderer_new( + int nesting_level +) __attribute__ ((malloc)); + +/* hoedown_html_renderer_free: deallocate an HTML renderer */ +void hoedown_html_renderer_free(hoedown_renderer *renderer); + + +#ifdef __cplusplus +} +#endif + +#endif /** HOEDOWN_HTML_H **/ diff --git a/depends/hoedown/hoedown/stack.h b/depends/hoedown/hoedown/stack.h new file mode 100644 index 00000000..bf9b439b --- /dev/null +++ b/depends/hoedown/hoedown/stack.h @@ -0,0 +1,52 @@ +/* stack.h - simple stacking */ + +#ifndef HOEDOWN_STACK_H +#define HOEDOWN_STACK_H + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + + +/********* + * TYPES * + *********/ + +struct hoedown_stack { + void **item; + size_t size; + size_t asize; +}; +typedef struct hoedown_stack hoedown_stack; + + +/************* + * FUNCTIONS * + *************/ + +/* hoedown_stack_init: initialize a stack */ +void hoedown_stack_init(hoedown_stack *st, size_t initial_size); + +/* hoedown_stack_uninit: free internal data of the stack */ +void hoedown_stack_uninit(hoedown_stack *st); + +/* hoedown_stack_grow: increase the allocated size to the given value */ +void hoedown_stack_grow(hoedown_stack *st, size_t neosz); + +/* hoedown_stack_push: push an item to the top of the stack */ +void hoedown_stack_push(hoedown_stack *st, void *item); + +/* hoedown_stack_pop: retrieve and remove the item at the top of the stack */ +void *hoedown_stack_pop(hoedown_stack *st); + +/* hoedown_stack_top: retrieve the item at the top of the stack */ +void *hoedown_stack_top(const hoedown_stack *st); + + +#ifdef __cplusplus +} +#endif + +#endif /** HOEDOWN_STACK_H **/ diff --git a/depends/hoedown/hoedown/version.h b/depends/hoedown/hoedown/version.h new file mode 100644 index 00000000..4938cae5 --- /dev/null +++ b/depends/hoedown/hoedown/version.h @@ -0,0 +1,33 @@ +/* version.h - holds Hoedown's version */ + +#ifndef HOEDOWN_VERSION_H +#define HOEDOWN_VERSION_H + +#ifdef __cplusplus +extern "C" { |
