diff options
author | Xavier Mendez <jmendeth@gmail.com> | 2014-08-10 00:26:35 +0200 |
---|---|---|
committer | Xavier Mendez <jmendeth@gmail.com> | 2014-08-10 00:26:35 +0200 |
commit | 9b38842cfa46371d58541b46f2401160c101aba5 (patch) | |
tree | 4fa76433d38b31d1c0bbb0f8a30ad62bef3aca5a | |
parent | 0610117f44b173a4e2112afb2f510156a32355b5 (diff) | |
download | rust-hoedown-9b38842cfa46371d58541b46f2401160c101aba5.tar.gz |
document: Add render_inline(...)
-rw-r--r-- | src/document.c | 42 | ||||
-rw-r--r-- | src/document.h | 3 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/document.c b/src/document.c index c68aa20..61ce07e 100644 --- a/src/document.c +++ b/src/document.c @@ -2822,6 +2822,48 @@ hoedown_document_render(hoedown_document *doc, hoedown_buffer *ob, const uint8_t } void +hoedown_document_render_inline(hoedown_document *doc, hoedown_buffer *ob, const uint8_t *document, size_t doc_size) +{ + size_t i = 0, mark; + hoedown_buffer *text = hoedown_buffer_new(64); + if (!text) + return; + + /* reset the references table */ + memset(&doc->refs, 0x0, REF_TABLE_SIZE * sizeof(void *)); + + /* first pass: convert all spacing to spaces */ + hoedown_buffer_grow(text, doc_size); + while (1) { + mark = i; + while (i < doc_size && document[i] != '\n' && document[i] != '\r') + i++; + + expand_tabs(text, document + mark, i - mark); + + if (i >= doc_size) + break; + + while (i < doc_size && (document[i] == '\n' || document[i] == '\r')) { + /* add one \n per newline */ + if (document[i] == '\n' || (i + 1 < doc_size && document[i + 1] != '\n')) + hoedown_buffer_putc(text, '\n'); + i++; + } + } + + /* second pass: actual rendering */ + hoedown_buffer_grow(ob, doc_size + (doc_size >> 1)); + parse_inline(ob, doc, text->data, text->size); + + /* clean-up */ + hoedown_buffer_free(text); + + assert(doc->work_bufs[BUFFER_SPAN].size == 0); + assert(doc->work_bufs[BUFFER_BLOCK].size == 0); +} + +void hoedown_document_free(hoedown_document *doc) { size_t i; diff --git a/src/document.h b/src/document.h index 217b0be..8fec835 100644 --- a/src/document.h +++ b/src/document.h @@ -149,6 +149,9 @@ extern void hoedown_document_render(hoedown_document *doc, hoedown_buffer *ob, const uint8_t *document, size_t doc_size); extern void +hoedown_document_render_inline(hoedown_document *doc, hoedown_buffer *ob, const uint8_t *document, size_t doc_size); + +extern void hoedown_document_free(hoedown_document *doc); #ifdef __cplusplus |