/* parse_blockquote • hanldes parsing of a regular paragraph */ static size_t parse_paragraph(struct buf *ob, struct render *rndr, char *data, size_t size) { size_t i = 0, end = 0; int level = 0; struct buf work = { data, 0, 0, 0, 0 }; /* volatile working buffer */ while (i < size) { for (end = i + 1; end < size && data[end - 1] != '\n'; end += 1); if (is_empty(data + i, size - i) || (level = is_headerline(data + i, size - i)) != 0) break; if ((i && data[i] == '#') || is_hrule(data + i, size - i)) { end = i; break; } i = end; } work.size = i; while (work.size && data[work.size - 1] == '\n') work.size -= 1; if (!level) { struct buf *tmp = new_work_buffer(rndr); parse_inline(tmp, rndr, work.data, work.size); if (rndr->make.paragraph) rndr->make.paragraph(ob, tmp, rndr->make.opaque); release_work_buffer(rndr, tmp); } else { if (work.size) { size_t beg; i = work.size; work.size -= 1; while (work.size && data[work.size] != '\n') work.size -= 1; beg = work.size + 1; while (work.size && data[work.size - 1] == '\n') work.size -= 1; if (work.size) { struct buf *tmp = new_work_buffer(rndr); parse_inline(tmp, rndr, work.data, work.size); if (rndr->make.paragraph) rndr->make.paragraph(ob, tmp, rndr->make.opaque); release_work_buffer(rndr, tmp); work.data += beg; work.size = i - beg; } else work.size = i; } if (rndr->make.header) { struct buf *span = new_work_buffer(rndr); parse_inline(span, rndr, work.data, work.size); rndr->make.header(ob, span, level,rndr->make.opaque); release_work_buffer(rndr, span); } } return end; }
/* parse_blockquote • hanldes parsing of a regular paragraph */ static size_t parse_paragraph(struct buf *ob, struct render *rndr, char *data, size_t size) { size_t i = 0, end = 0; int level = 0; struct buf work = { data, 0, 0, 0, 0 }; /* volatile working buffer */ while (i < size) { for (end = i + 1; end < size && data[end - 1] != '\n'; end++) /* empty */; if (is_empty(data + i, size - i) || (level = is_headerline(data + i, size - i)) != 0) break; if (rndr->ext_flags & MKDEXT_LAX_HTML_BLOCKS) { if (data[i] == '<' && rndr->make.blockhtml && parse_htmlblock(ob, rndr, data + i, size - i, 0)) { end = i; break; } } if (data[i] == '#' || is_hrule(data + i, size - i)) { end = i; break; } i = end; } work.size = i; while (work.size && data[work.size - 1] == '\n') work.size--; if (!level) { struct buf *tmp = rndr_newbuf(rndr); parse_inline(tmp, rndr, work.data, work.size); if (rndr->make.paragraph) rndr->make.paragraph(ob, tmp, rndr->make.opaque); rndr_popbuf(rndr); } else { struct buf *header_work; if (work.size) { size_t beg; i = work.size; work.size -= 1; while (work.size && data[work.size] != '\n') work.size -= 1; beg = work.size + 1; while (work.size && data[work.size - 1] == '\n') work.size -= 1; if (work.size > 0) { struct buf *tmp = rndr_newbuf(rndr); parse_inline(tmp, rndr, work.data, work.size); if (rndr->make.paragraph) rndr->make.paragraph(ob, tmp, rndr->make.opaque); rndr_popbuf(rndr); work.data += beg; work.size = i - beg; } else work.size = i; } header_work = rndr_newbuf(rndr); parse_inline(header_work, rndr, work.data, work.size); if (rndr->make.header) rndr->make.header(ob, header_work, (int)level, rndr->make.opaque); rndr_popbuf(rndr); } return end; }