aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremias Stotter <jeremias@stotter.eu>2021-10-25 21:34:31 +0200
committerJeremias Stotter <jeremias@stotter.eu>2021-10-25 21:34:31 +0200
commitddfb7a10ffc6099b57c19f247855ced7ba7e55d2 (patch)
treeb10cf65ec59dd70c6602092528d3d8733fd6d00b
parent2daca69de1a8ec8fcdad3644aa24b5b437d217be (diff)
downloadJBlog-ddfb7a10ffc6099b57c19f247855ced7ba7e55d2.tar.gz
JBlog-ddfb7a10ffc6099b57c19f247855ced7ba7e55d2.tar.bz2
JBlog-ddfb7a10ffc6099b57c19f247855ced7ba7e55d2.zip
Markdown does what I want it to do
Next thing up are the index files
-rw-r--r--blog/test.jblog10
-rw-r--r--md.c90
-rw-r--r--readme.html11
3 files changed, 108 insertions, 3 deletions
diff --git a/blog/test.jblog b/blog/test.jblog
index 98e29cf..23e2899 100644
--- a/blog/test.jblog
+++ b/blog/test.jblog
@@ -19,12 +19,20 @@ Linebreak
###### Header 6
I am **bold**
+
I am \*escaped bold\*!
+
I am _italic_
+
I am ___both___
+
I am `monospace`
+
I have been ~~CUT~~
+Cutting only works with two ~
+
+
CODE
WOW
UH CODE WITH TABS, FANCY :P
@@ -53,7 +61,7 @@ Uh a fancy line
See [my homepage](https://jeremias.stotter.eu) \
And look at my logo
-![Image](https://jeremias.stotter.eu/logo100.png "Logo")
+![Image](https://jeremias.stotter.eu/logo100.png)
> Whoever is happy will make others happy too.
> -Anne Frank
diff --git a/md.c b/md.c
index 9a9b187..235f826 100644
--- a/md.c
+++ b/md.c
@@ -66,6 +66,45 @@ size_t prepend(char* in_dest, char* in_src) {
return strlen(in_dest);
}
+// start is the first curly bracket we have
+// Returns pointer to last round bracket
+// free the returned pointers yourself
+char* get_link_components(char* start, char** out_text, char** out_loc, size_t* out_len) {
+ // Search for the next closing bracket
+ bool no_link = false;
+ char* closing_sqr_bracket = strchr(start, ']');
+ if(closing_sqr_bracket == NULL) {
+ no_link = true;
+ }
+ if(*(closing_sqr_bracket + 1) != '(') {
+ no_link = true;
+ }
+ char* closing_rnd_bracket = strchr(closing_sqr_bracket + 1, ')');
+ if(closing_rnd_bracket == NULL) {
+ no_link = true;
+ }
+ if(no_link) {
+ return NULL;
+ }
+ size_t link_text_len = closing_sqr_bracket - start - 1;
+ size_t link_loc_len = closing_rnd_bracket - closing_sqr_bracket - 2;
+
+ char* link_text = calloc(link_text_len + 1, 1);
+ char* link_loc = calloc(link_loc_len + 1, 1);
+
+ if(link_text == NULL || link_loc == NULL) {
+ perror("calloc error");
+ return NULL;
+ }
+
+ memcpy(link_text, start + 1, link_text_len);
+ memcpy(link_loc, closing_sqr_bracket + 2, link_loc_len);
+ *out_text = link_text;
+ *out_loc = link_loc;
+ *out_len = link_text_len + link_loc_len;
+
+ return closing_rnd_bracket;
+}
// @todo NEXT
// The program needs to loop through the loop again to cose all the open things at the end, THIS NEEDS TO BE IMPLEMENTED for xhtml
@@ -394,6 +433,28 @@ int parse_markdown(char* input, char* buffer, size_t buffer_size) {
// brackets
case '[':
{
+ char* link_text = NULL;
+ char* link_loc = NULL;
+ size_t link_loctxt_len = 0;
+ char* closing_rnd_bracket = get_link_components(line_position, &link_text, &link_loc, &link_loctxt_len);
+ // This is 16 characters long (add one for good measure (: ):
+ //<a href=""></a>\0
+ char* link_html = calloc(link_loctxt_len + 17, 1);
+ if(link_html == NULL || closing_rnd_bracket == NULL) {
+ strncat(format_line_buffer, "[", LINE_MAX);
+ if(link_html != NULL) free(link_html);
+ if(link_text != NULL) free(link_text);
+ if(link_loc != NULL) free(link_loc);
+ break;
+ }
+
+ sprintf(link_html, "<a href=\"%s\">%s</a>", link_loc, link_text);
+
+ strncat(format_line_buffer, link_html, LINE_MAX - 1);
+ line_position = closing_rnd_bracket;
+ free(link_html);
+ free(link_text);
+ free(link_loc);
}
break;
case ']':
@@ -411,6 +472,35 @@ int parse_markdown(char* input, char* buffer, size_t buffer_size) {
// Images
case '!':
{
+ char* img_alt = NULL;
+ char* img_src = NULL;
+ size_t img_altsrc_len = 0;
+ if(*(line_position + 1) == '\0') {
+ strncat(format_line_buffer, "!", LINE_MAX);
+ break;
+ }
+ char* closing_rnd_bracket = get_link_components(line_position + 1, &img_alt, &img_src, &img_altsrc_len);
+ // This is 21 characters long, again we add one more to be safe
+ //<img alt="" src=""/>\0
+ char* img_html = calloc(img_altsrc_len + 22, 1);
+ if(img_html == NULL || closing_rnd_bracket == NULL) {
+ strncat(format_line_buffer, "!", LINE_MAX);
+ if(img_html != NULL) free(img_html);
+ if(img_alt != NULL) free(img_alt);
+ if(img_src != NULL) free(img_src);
+ break;
+ }
+
+ printf("Go on\n");
+ printf("%s %s\n", img_alt, img_src);
+
+ sprintf(img_html, "<img alt=\"%s\" src=\"%s\"/>", img_alt, img_src);
+
+ strncat(format_line_buffer, img_html, LINE_MAX - 1);
+ line_position = closing_rnd_bracket;
+ free(img_html);
+ free(img_alt);
+ free(img_src);
}
break;
// escape
diff --git a/readme.html b/readme.html
index bc2c237..c573508 100644
--- a/readme.html
+++ b/readme.html
@@ -14,9 +14,9 @@
</ol>
<p>After you did that, start the webserver, make sure the config file of the webserver has a valid user and points to the right socket!</p>
<h3>The pattern file</h3>
-<p>The pattern file is a html/xhtml (currently only xhtml, but I will allow both in the very near future) file that tells JBLOG what to put around the actual content of the blog. You mark where JBLOG can put its dynamic content with $BLOG$ and do whatever you want with the rest of the file!</p>
+<p>The pattern file is a html/xhtml file that tells JBLOG what to put around the actual content of the blog. You mark where JBLOG can put its dynamic content with $BLOG$ and do whatever you want with the rest of the file!</p>
<h3>The blog files</h3>
-<p>The Blog files are text files stored in the directory you defined above. They have a header that contains metadata like the author, release date and so on. The actual content starts after a delimiter "///" and is just markdown (although a limited subset of that).</p>
+<p>The Blog files are text files stored in the directory you defined above. They have a header that contains metadata like the author, release date and so on. The actual content starts after a delimiter "///" and is just markdown (although a limited subset of that, see LIMITATIONS).</p>
<h3>blog Index files</h3>
<p>Obviously a blog is no good if you cant find other entries, so there are index files. JBLOG will server a list of blog entries that match what a few criteria specified in the index file. (For example subdirectory)</p>
<p><b><em>NOTE: This is not yet implemented</b></em></p>
@@ -28,5 +28,12 @@
<li>Tag support for better organization</li>
<li>Primitive keyword based search</li>
</ul>
+<h2>LIMITATIONS</h2>
+<p>I am lazy, therefore a few markdown things are currently not implemented and I do not plan on implementing these unless absolutely necessary. Here is an uncomplete list of missing markdown features you might know from other implementations:</p>
+<ul>
+ <li>setext headers, they require me to go back up the lines, my markdown parser was NOT designed to do this<sup>honestly it wasn't really designed to do anything properly</sup></li>
+ <li>Image titles are not supported, in most markdown implementations you can do this: <code>![alternative text](src "title text")</code>. In this implementation you may only put the src in the round brackets, otherwise you will either get no image or your browser will complain and not show any page at all in the case you are using xhtml.</li>
+</ul>
+<h3>THIS IS NOT PRODUCTION READY AT ALL</h3>
<h2>License</h2>
<p>This program and all the files in this repository are licensed under the GPL v3 License, see LICENSE or <a href="https://www.gnu.org/licenses/gpl-3.0.en.html">https://www.gnu.org/licenses/gpl-3.0.en.html</a> for more details.</p>
Jeremias Stotters git repositories generated by CGIT