From 9b38842cfa46371d58541b46f2401160c101aba5 Mon Sep 17 00:00:00 2001 From: Xavier Mendez Date: Sun, 10 Aug 2014 00:26:35 +0200 Subject: [PATCH] document: Add render_inline(...) --- src/document.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/document.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/src/document.c b/src/document.c index c68aa20..61ce07e 100644 --- a/src/document.c +++ b/src/document.c @@ -2821,6 +2821,48 @@ hoedown_document_render(hoedown_document *doc, hoedown_buffer *ob, const uint8_t assert(doc->work_bufs[BUFFER_BLOCK].size == 0); } +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) { diff --git a/src/document.h b/src/document.h index 217b0be..8fec835 100644 --- a/src/document.h +++ b/src/document.h @@ -148,6 +148,9 @@ hoedown_document_new( 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);