diff options
author | dx <aryadevchavali1@gmail.com> | 2020-05-06 03:09:57 +0100 |
---|---|---|
committer | dx <aryadevchavali1@gmail.com> | 2020-05-06 03:11:46 +0100 |
commit | 74dd237810d47e961f30ff8e9c3a10a4bb9ef7ac (patch) | |
tree | 487af2f5817de4e94d0b0ca9b15488680bf42267 /Converter | |
parent | f50d692e858d2479114a2ac3637120edf8a28d19 (diff) | |
download | mdhtml-74dd237810d47e961f30ff8e9c3a10a4bb9ef7ac.tar.gz mdhtml-74dd237810d47e961f30ff8e9c3a10a4bb9ef7ac.tar.bz2 mdhtml-74dd237810d47e961f30ff8e9c3a10a4bb9ef7ac.zip |
+header depth algorithm
This adds the functionality for arbitrary levels of header depth which
will be translated to depth based header tags.
\## -> <h2>
\### -> <h3>
etc
This also introduces a variable 'size_of_content' which presents the
size of the raw string without the header tags as added size.
Diffstat (limited to 'Converter')
-rw-r--r-- | Converter/src/main.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Converter/src/main.c b/Converter/src/main.c index e3603bb..e41304b 100644 --- a/Converter/src/main.c +++ b/Converter/src/main.c @@ -7,10 +7,25 @@ typedef char *string; string compile_line(string line, size_t size_of_line) { string compiled_line; + size_t size_of_content; + if (line[0] == '#') { // Compile a header + // Get the level of header (h1, h2, etc) + int depth; + for (depth = 1; line[depth] == '#'; ++depth); + size_of_content = size_of_line - depth; // remove hashes + + // Generate the header tags based on depth + const int tag_size = 4; + const int untag_size = 5; + string tag = malloc(sizeof(*tag) * 5); + sprintf(tag, "<h%d>", depth); + string untag = malloc(sizeof(*untag) * 6); + sprintf(untag, "</h%d>", depth); + // allocate buffer with extra 9 characters for the tags compiled_line = malloc(sizeof(*compiled_line) * (size_of_line + 9)); // write h1 to start of compiled_line |