| 2802 | } |
| 2803 | |
| 2804 | void |
| 2805 | hoedown_document_render(hoedown_document *doc, hoedown_buffer *ob, const uint8_t *data, size_t size) |
| 2806 | { |
| 2807 | static const uint8_t UTF8_BOM[] = {0xEF, 0xBB, 0xBF}; |
| 2808 | |
| 2809 | hoedown_buffer *text; |
| 2810 | size_t beg, end; |
| 2811 | |
| 2812 | int footnotes_enabled; |
| 2813 | |
| 2814 | text = hoedown_buffer_new(64); |
| 2815 | |
| 2816 | /* Preallocate enough space for our buffer to avoid expanding while copying */ |
| 2817 | hoedown_buffer_grow(text, size); |
| 2818 | |
| 2819 | /* reset the references table */ |
| 2820 | memset(&doc->refs, 0x0, REF_TABLE_SIZE * sizeof(void *)); |
| 2821 | |
| 2822 | footnotes_enabled = doc->ext_flags & HOEDOWN_EXT_FOOTNOTES; |
| 2823 | |
| 2824 | /* reset the footnotes lists */ |
| 2825 | if (footnotes_enabled) { |
| 2826 | memset(&doc->footnotes_found, 0x0, sizeof(doc->footnotes_found)); |
| 2827 | memset(&doc->footnotes_used, 0x0, sizeof(doc->footnotes_used)); |
| 2828 | } |
| 2829 | |
| 2830 | /* first pass: looking for references, copying everything else */ |
| 2831 | beg = 0; |
| 2832 | |
| 2833 | /* Skip a possible UTF-8 BOM, even though the Unicode standard |
| 2834 | * discourages having these in UTF-8 documents */ |
| 2835 | if (size >= 3 && memcmp(data, UTF8_BOM, 3) == 0) |
| 2836 | beg += 3; |
| 2837 | |
| 2838 | while (beg < size) /* iterating over lines */ |
| 2839 | if (footnotes_enabled && is_footnote(data, beg, size, &end, &doc->footnotes_found)) |
| 2840 | beg = end; |
| 2841 | else if (is_ref(data, beg, size, &end, doc->refs)) |
| 2842 | beg = end; |
| 2843 | else { /* skipping to the next line */ |
| 2844 | end = beg; |
| 2845 | while (end < size && data[end] != '\n' && data[end] != '\r') |
| 2846 | end++; |
| 2847 | |
| 2848 | /* adding the line body if present */ |
| 2849 | if (end > beg) |
| 2850 | expand_tabs(text, data + beg, end - beg); |
| 2851 | |
| 2852 | while (end < size && (data[end] == '\n' || data[end] == '\r')) { |
| 2853 | /* add one \n per newline */ |
| 2854 | if (data[end] == '\n' || (end + 1 < size && data[end + 1] != '\n')) |
| 2855 | hoedown_buffer_putc(text, '\n'); |
| 2856 | end++; |
| 2857 | } |
| 2858 | |
| 2859 | beg = end; |
| 2860 | } |
| 2861 |
no test coverage detected