Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/markdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,8 @@ parse_blockquote(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t
beg = end;
}

if (rndr->cb.enter_blockquote)
rndr->cb.enter_blockquote(ob, rndr->opaque);
parse_block(out, rndr, work_data, work_size);
if (rndr->cb.blockquote)
rndr->cb.blockquote(ob, out, rndr->opaque);
Expand Down Expand Up @@ -1745,6 +1747,9 @@ parse_listitem(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t s
while (end < size && data[end - 1] != '\n')
end++;

if (rndr->cb.enter_listitem)
rndr->cb.enter_listitem(ob, rndr->opaque);

/* getting working buffers */
work = rndr_newbuf(rndr, BUFFER_SPAN);
inter = rndr_newbuf(rndr, BUFFER_SPAN);
Expand Down Expand Up @@ -1865,6 +1870,9 @@ parse_list(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t size,
struct buf *work = 0;
size_t i = 0, j;

if (rndr->cb.enter_list)
rndr->cb.enter_list(ob, rndr->opaque);

work = rndr_newbuf(rndr, BUFFER_BLOCK);

while (i < size) {
Expand Down Expand Up @@ -2092,6 +2100,9 @@ parse_table_row(
if (!rndr->cb.table_cell || !rndr->cb.table_row)
return;

if (rndr->cb.enter_table_row)
rndr->cb.enter_table_row(ob, header_flag, rndr->opaque);

row_work = rndr_newbuf(rndr, BUFFER_SPAN);

if (i < size && data[i] == '|')
Expand All @@ -2101,6 +2112,9 @@ parse_table_row(
size_t cell_start, cell_end;
struct buf *cell_work;

if (rndr->cb.enter_table_cell)
rndr->cb.enter_table_cell(ob, header_flag, rndr->opaque);

cell_work = rndr_newbuf(rndr, BUFFER_SPAN);

while (i < size && _isspace(data[i]))
Expand All @@ -2125,6 +2139,8 @@ parse_table_row(

cols_left = columns - col;
if (cols_left > 0) {
if (rndr->cb.enter_table_cell)
rndr->cb.enter_table_cell(ob, header_flag, rndr->opaque);
struct buf empty_cell = { 0, 0, 0, 0 };
rndr->cb.table_cell(row_work, &empty_cell, col_data[col] | header_flag, rndr->opaque, cols_left);
}
Expand Down Expand Up @@ -2215,6 +2231,9 @@ parse_table_header(
if (col < *columns)
return 0;

if (rndr->cb.enter_table)
rndr->cb.enter_table(ob, rndr->opaque);

parse_table_row(
ob, rndr, data,
header_end,
Expand Down Expand Up @@ -2246,7 +2265,6 @@ parse_table(

i = parse_table_header(header_work, rndr, data, size, &columns, &col_data);
if (i > 0) {

while (i < size) {
size_t row_start;
int pipes = 0;
Expand Down
8 changes: 8 additions & 0 deletions src/markdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ struct sd_callbacks {
/* header and footer */
void (*doc_header)(struct buf *ob, void *opaque);
void (*doc_footer)(struct buf *ob, void *opaque);

/* enter_X callbacks for use in widget toolkits */
void (*enter_blockquote)(struct buf *ob, void *opaque);
void (*enter_list)(struct buf *ob, void *opaque);
void (*enter_listitem)(struct buf *ob, void *opaque);
void (*enter_table)(struct buf *ob, void *opaque);
void (*enter_table_row)(struct buf *ob, int header_flags, void *opaque);
void (*enter_table_cell)(struct buf *ob, int header_flags, void *opaque);
};

struct sd_markdown;
Expand Down