Skip to content

Commit

Permalink
Add a 'dirty' flag to the Document structure & set it whenever a call…
Browse files Browse the repository at this point in the history
…back

changes (github issue #136) so that the next mkd_compile will regenerate
the document.
  • Loading branch information
Orc committed Jan 28, 2017
1 parent aa7384c commit b39005d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
3 changes: 2 additions & 1 deletion markdown.c
Expand Up @@ -1356,9 +1356,10 @@ mkd_compile(Document *doc, DWORD flags)
flags &= USER_FLAGS;

if ( doc->compiled ) {
if ( doc->ctx->flags == flags )
if ( doc->ctx->flags == flags && !doc->dirty)
return 1;
else {
doc->compiled = doc->dirty = 0;
if ( doc->code)
___mkd_freeParagraph(doc->code);
if ( doc->ctx->footnotes )
Expand Down
1 change: 1 addition & 0 deletions markdown.h
Expand Up @@ -165,6 +165,7 @@ typedef struct document {
ANCHOR(Line) content; /* uncompiled text, not valid after compile() */
Paragraph *code; /* intermediate code generated by compile() */
int compiled; /* set after mkd_compile() */
int dirty; /* flags or callbacks changed */
int html; /* set after (internal) htmlify() */
int tabstop; /* for properly expanding tabs (ick) */
char *ref_prefix;
Expand Down
25 changes: 20 additions & 5 deletions mkdio.c
Expand Up @@ -328,8 +328,11 @@ mkd_generateline(char *bfr, int size, FILE *output, DWORD flags)
void
mkd_e_url(Document *f, mkd_callback_t edit)
{
if ( f )
if ( f ) {
if ( f->cb.e_url != edit )
f->dirty = 1;
f->cb.e_url = edit;
}
}


Expand All @@ -338,8 +341,11 @@ mkd_e_url(Document *f, mkd_callback_t edit)
void
mkd_e_flags(Document *f, mkd_callback_t edit)
{
if ( f )
if ( f ) {
if ( f->cb.e_flags != edit )
f->dirty = 1;
f->cb.e_flags = edit;
}
}


Expand All @@ -348,8 +354,11 @@ mkd_e_flags(Document *f, mkd_callback_t edit)
void
mkd_e_free(Document *f, mkd_free_t dealloc)
{
if ( f )
if ( f ) {
if ( f->cb.e_free != dealloc )
f->dirty = 1;
f->cb.e_free = dealloc;
}
}


Expand All @@ -358,8 +367,11 @@ mkd_e_free(Document *f, mkd_free_t dealloc)
void
mkd_e_data(Document *f, void *data)
{
if ( f )
if ( f ) {
if ( f->cb.e_data != data )
f->dirty = 1;
f->cb.e_data = data;
}
}


Expand All @@ -368,6 +380,9 @@ mkd_e_data(Document *f, void *data)
void
mkd_ref_prefix(Document *f, char *data)
{
if ( f )
if ( f ) {
if ( f->ref_prefix != data )
f->dirty = 1;
f->ref_prefix = data;
}
}

0 comments on commit b39005d

Please sign in to comment.