Infer is_tight from context when rendering paragraphs
Previously, the document parser had to propagate is_tight across paragraphs so we could render paragraphs inside tight lists correctly. Now that we are passing context to the renderers, the hack is no longer needed; the renderer can "mark" objects of tight list items and render their paragraphs differently based on that.
This commit is contained in:
parent
b10fe4d9da
commit
36780e9471
5 changed files with 16 additions and 16 deletions
|
@ -3,7 +3,7 @@
|
|||
#include <string.h>
|
||||
|
||||
/* Block constructs */
|
||||
static void rndr_paragraph(void *target, void *content, int is_tight, const hoedown_renderer_data *data) {}
|
||||
static void rndr_paragraph(void *target, void *content, const hoedown_renderer_data *data) {}
|
||||
static void rndr_indented_code_block(void *target, const hoedown_buffer *code, const hoedown_renderer_data *data) {}
|
||||
static void rndr_fenced_code_block(void *target, const hoedown_buffer *code, const hoedown_buffer *info, const hoedown_renderer_data *data) {}
|
||||
static void rndr_horizontal_rule(void *target, const hoedown_renderer_data *data) {}
|
||||
|
|
|
@ -103,7 +103,6 @@ struct hoedown_document {
|
|||
block_char_entry *block_chars [256];
|
||||
hoedown_pool block_chars__pool;
|
||||
parsing_mode mode;
|
||||
size_t is_tight;
|
||||
size_t inside_footnote;
|
||||
|
||||
// Inline parsing
|
||||
|
@ -1984,7 +1983,7 @@ static inline void parse_paragraph(hoedown_document *doc, void *target, const ui
|
|||
parse_inline(doc, content, data + content_start, content_end - content_start, 0);
|
||||
set_buffer_data(&doc->data.src[0], data, 0, size);
|
||||
set_buffer_data(&doc->data.src[1], data, content_start, content_end);
|
||||
doc->rndr.paragraph(target, content, doc->is_tight == doc->current_nesting, &doc->data);
|
||||
doc->rndr.paragraph(target, content, &doc->data);
|
||||
doc->rndr.object_pop(content, 1, &doc->data);
|
||||
}
|
||||
|
||||
|
@ -2828,7 +2827,7 @@ static size_t collect_list_items(hoedown_document *doc, const uint8_t *data, siz
|
|||
// through `work` and `slices` and renders each individual item, then the list
|
||||
// itself.
|
||||
static size_t parse_list(hoedown_document *doc, void *target, const uint8_t *data, size_t parsed, size_t start, size_t size) {
|
||||
size_t i = start, slice, current_is_tight = doc->is_tight;
|
||||
size_t i = start, slice;
|
||||
enum parsing_mode current_mode = doc->mode;
|
||||
int is_ordered, is_loose = (current_mode == NORMAL_PARSING) ? 0 : 1, number = 0;
|
||||
void *content;
|
||||
|
@ -2861,8 +2860,6 @@ static size_t parse_list(hoedown_document *doc, void *target, const uint8_t *dat
|
|||
set_buffer_data(&doc->data.src[0], data, start, i);
|
||||
content = doc->rndr.object_get(0, HOEDOWN_FT_LIST, flags, target, &doc->data);
|
||||
}
|
||||
if (!is_loose)
|
||||
doc->is_tight = doc->current_nesting + 1;
|
||||
|
||||
size_t offset = 0, source = 0;
|
||||
for (slice = 0; slice < slices->size; slice += 2*sizeof(size_t)) {
|
||||
|
@ -2883,8 +2880,6 @@ static size_t parse_list(hoedown_document *doc, void *target, const uint8_t *dat
|
|||
source = new_source;
|
||||
}
|
||||
|
||||
doc->is_tight = current_is_tight;
|
||||
|
||||
|
||||
// 3. Render the list itself
|
||||
if (current_mode == NORMAL_PARSING) {
|
||||
|
@ -3421,7 +3416,6 @@ hoedown_document *hoedown_document_new(
|
|||
hoedown_pool_init(&doc->block_chars__pool, 4, _new_block_char_entry, _free_pool_item, NULL);
|
||||
set_block_chars(doc, features);
|
||||
doc->mode = NORMAL_PARSING;
|
||||
doc->is_tight = 0;
|
||||
doc->inside_footnote = 0;
|
||||
|
||||
// Inline parsing
|
||||
|
@ -3505,7 +3499,6 @@ void *hoedown_document_render(
|
|||
assert(doc->current_nesting == 0);
|
||||
assert(doc->mode == NORMAL_PARSING);
|
||||
assert(doc->block_buffers.size == doc->block_buffers.isize);
|
||||
assert(!doc->is_tight);
|
||||
assert(!doc->inside_footnote);
|
||||
assert(doc->inline_buffers.size == doc->inline_buffers.isize);
|
||||
assert(doc->inline_data == NULL);
|
||||
|
|
|
@ -185,18 +185,22 @@ typedef struct hoedown_document hoedown_document;
|
|||
|
||||
typedef struct hoedown_internal hoedown_internal;
|
||||
|
||||
typedef struct hoedown_renderer hoedown_renderer;
|
||||
|
||||
typedef struct hoedown_renderer_data {
|
||||
hoedown_buffer src [5];
|
||||
void *opaque;
|
||||
void *request;
|
||||
hoedown_buffer src [5];
|
||||
hoedown_features ft;
|
||||
hoedown_renderer *self;
|
||||
hoedown_internal *doc;
|
||||
} hoedown_renderer_data;
|
||||
|
||||
typedef struct hoedown_renderer {
|
||||
struct hoedown_renderer {
|
||||
void *opaque;
|
||||
|
||||
/* Block constructs */
|
||||
void (*paragraph)(void *target, void *content, int is_tight, const hoedown_renderer_data *data);
|
||||
void (*paragraph)(void *target, void *content, const hoedown_renderer_data *data);
|
||||
void (*indented_code_block)(void *target, const hoedown_buffer *code, const hoedown_renderer_data *data);
|
||||
void (*fenced_code_block)(void *target, const hoedown_buffer *code, const hoedown_buffer *info, const hoedown_renderer_data *data);
|
||||
void (*horizontal_rule)(void *target, const hoedown_renderer_data *data);
|
||||
|
@ -233,7 +237,7 @@ typedef struct hoedown_renderer {
|
|||
|
||||
void (*render_start)(int is_inline, const hoedown_renderer_data *data);
|
||||
void *(*render_end)(void *target, int is_inline, const hoedown_renderer_data *data);
|
||||
} hoedown_renderer;
|
||||
};
|
||||
|
||||
|
||||
/*************
|
||||
|
|
|
@ -21,12 +21,14 @@ static void *object_get(int is_inline, hoedown_features ft, hoedown_preview_flag
|
|||
hoedown_html_renderer_state *state = data->opaque;
|
||||
hoedown_html_renderer_object *target = hoedown_pool_get(&state->objects);
|
||||
target->ob->size = 0;
|
||||
target->is_tight = (ft == HOEDOWN_FT_LIST) && (flags & HOEDOWN_PF_LIST_TIGHT);
|
||||
return target;
|
||||
}
|
||||
|
||||
static void object_merge(void *target_, void *content_, int is_inline, const hoedown_renderer_data *data) {
|
||||
hoedown_html_renderer_object *target = target_, *content = content_;
|
||||
hoedown_buffer_put(target->ob, content->ob->data, content->ob->size);
|
||||
target->is_tight = content->is_tight;
|
||||
}
|
||||
|
||||
static void object_pop(void *target_, int is_inline, const hoedown_renderer_data *data) {
|
||||
|
@ -60,10 +62,10 @@ static void *render_end(void *target_, int is_inline, const hoedown_renderer_dat
|
|||
|
||||
// BLOCK CONSTRUCTS
|
||||
|
||||
static void rndr_paragraph(void *target_, void *content_, int is_tight, const hoedown_renderer_data *data) {
|
||||
static void rndr_paragraph(void *target_, void *content_, const hoedown_renderer_data *data) {
|
||||
hoedown_html_renderer_object *target = target_, *content = content_;
|
||||
|
||||
if (is_tight) {
|
||||
if (target->is_tight) {
|
||||
hoedown_buffer_put(target->ob, content->ob->data, content->ob->size);
|
||||
hoedown_buffer_putc(target->ob, '\n');
|
||||
} else {
|
||||
|
|
|
@ -26,6 +26,7 @@ typedef struct hoedown_html_renderer_state {
|
|||
typedef struct hoedown_html_renderer_object {
|
||||
void *opaque;
|
||||
hoedown_buffer *ob;
|
||||
int is_tight;
|
||||
} hoedown_html_renderer_object;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue