forked from commonmark/cmark
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add baseline test * Some preliminary work. * cont'd * Add footnote reference * Start postprocessing * MVP: tests pass * commonmark footnote out * Factor out reference/footnote maps * fix a memory leak & some asserts * We don't assert/check snprintf elsewhere * Remove bad linear search, extend test case * cleanup * man page update * add footnotes as option * bugfix (found in comrak first!) * Shift static var into renderer struct
- Loading branch information
Ashe Connor
authored
Nov 16, 2017
1 parent
9188bdf
commit 59f7233
Showing
27 changed files
with
788 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "cmark.h" | ||
#include "parser.h" | ||
#include "footnotes.h" | ||
#include "inlines.h" | ||
#include "chunk.h" | ||
|
||
static void footnote_free(cmark_map *map, cmark_map_entry *_ref) { | ||
cmark_footnote *ref = (cmark_footnote *)_ref; | ||
cmark_mem *mem = map->mem; | ||
if (ref != NULL) { | ||
mem->free(ref->entry.label); | ||
if (ref->node) | ||
cmark_node_free(ref->node); | ||
mem->free(ref); | ||
} | ||
} | ||
|
||
void cmark_footnote_create(cmark_map *map, cmark_node *node) { | ||
cmark_footnote *ref; | ||
unsigned char *reflabel = normalize_map_label(map->mem, &node->as.literal); | ||
|
||
/* empty footnote name, or composed from only whitespace */ | ||
if (reflabel == NULL) | ||
return; | ||
|
||
assert(map->sorted == NULL); | ||
|
||
ref = (cmark_footnote *)map->mem->calloc(1, sizeof(*ref)); | ||
ref->entry.label = reflabel; | ||
ref->node = node; | ||
ref->entry.age = map->size; | ||
ref->entry.next = map->refs; | ||
|
||
map->refs = (cmark_map_entry *)ref; | ||
map->size++; | ||
} | ||
|
||
cmark_map *cmark_footnote_map_new(cmark_mem *mem) { | ||
return cmark_map_new(mem, footnote_free); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef CMARK_FOOTNOTES_H | ||
#define CMARK_FOOTNOTES_H | ||
|
||
#include "map.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct cmark_footnote { | ||
cmark_map_entry entry; | ||
cmark_node *node; | ||
unsigned int ix; | ||
}; | ||
|
||
typedef struct cmark_footnote cmark_footnote; | ||
|
||
void cmark_footnote_create(cmark_map *map, cmark_node *node); | ||
cmark_map *cmark_footnote_map_new(cmark_mem *mem); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
Oops, something went wrong.