2023-07-13 14:29:58 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright:
|
|
|
|
(C) 2022-2023 Daniele 'dzonerzy' Linguaglossa - http://libdzonerzy.so
|
|
|
|
|
|
|
|
This file is part of libdzonerzy.so.
|
|
|
|
|
|
|
|
GNU GENERAL PUBLIC LICENSE
|
|
|
|
Version 3, 29 June 2007
|
|
|
|
|
|
|
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
|
|
Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
of this license document, but changing it is not allowed.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#define EXPORT_SYMBOL(return, name) __attribute__((visibility("default"))) return name
|
|
|
|
#define HIDE_SYMBOL __attribute__((visibility("hidden")))
|
|
|
|
|
|
|
|
#define SECTION(x) __attribute__((section(x)))
|
|
|
|
// section name should be like "articles/article_name.md"
|
|
|
|
#define ARTICLE(x) SECTION("articles/" x ".md")
|
|
|
|
|
|
|
|
/* CSS macros */
|
|
|
|
// comment macros
|
|
|
|
#define CSS_COMMENT(x) "/* " x " */\n"
|
|
|
|
// property macros
|
|
|
|
#define CSS_PROPERTY(n, v) " " n ": " v ";\n"
|
|
|
|
// property macros with unescaped values
|
|
|
|
#define CSS_PROPERTY_UNESCAPED(n, v) " " n " : " v ";\n"
|
|
|
|
// selector macros
|
|
|
|
#define CSS_SELECTOR(n) n "{\n"
|
|
|
|
// end selector macros
|
|
|
|
#define CSS_END_SELECTOR() "}\n"
|
|
|
|
// rgb macros
|
|
|
|
#define CSS_RGB(r, g, b) "rgb(" #r "," #g "," #b ")"
|
|
|
|
// rgba macros
|
|
|
|
#define CSS_RGBA(r, g, b, a) "rgba(" #r "," #g "," #b "," #a ")"
|
|
|
|
// hsl macros
|
|
|
|
#define CSS_HSL(h, s, l) "hsl(" #h "," #s "," #l ")"
|
|
|
|
// hsla macros
|
|
|
|
#define CSS_HSLA(h, s, l, a) "hsla(" #h "," #s "," #l "," #a ")"
|
|
|
|
// url macros
|
|
|
|
#define CSS_URL(x) "url(" #x ")"
|
|
|
|
// new line macros
|
|
|
|
#define CSS_NEWLINE() "\n"
|
|
|
|
|
|
|
|
/* MD macros */
|
|
|
|
// meta info
|
|
|
|
#define MD_META(title, author) "% " title "\n" \
|
|
|
|
"% " author "\n"
|
|
|
|
#define MD_META_CUSTOM(v) "% " v "\n"
|
|
|
|
#define MD_META_NAMED(p, v) "% " p ": " v "\n"
|
|
|
|
#define MD_COMMENT(x) "<!-- " x " -->\n"
|
|
|
|
// section macros from 1 to 4
|
|
|
|
#define MD_SECTION1(x) "# " x "\n"
|
|
|
|
#define MD_SECTION2(x) "## " x "\n"
|
|
|
|
#define MD_SECTION3(x) "### " x "\n"
|
|
|
|
#define MD_SECTION4(x) "#### " x "\n"
|
|
|
|
// bold macros
|
|
|
|
#define MD_BOLD(x) "**" x "**"
|
|
|
|
// italic macros
|
|
|
|
#define MD_ITALIC(x) "*" x "*"
|
|
|
|
// link macros
|
|
|
|
#define MD_LINK(x, y) "[" x "](" y ")"
|
|
|
|
// image macros
|
|
|
|
#define MD_IMAGE(x, y) "![" x "](" y ")\n\n"
|
2023-07-13 22:00:51 +00:00
|
|
|
// image macros with attributes
|
|
|
|
#define MD_IMAGE_ATTR(x, y, a, v) "![" x "](" y "){" a "=\"" v "\"}\n\n"
|
2023-07-13 14:29:58 +00:00
|
|
|
// raw html tag macros
|
|
|
|
#define MD_RAWTAG(t, c) "<" t ">" c "</" t ">"
|
|
|
|
// new line macros
|
|
|
|
#define MD_NEWLINE() "\n\n"
|
|
|
|
// code macros
|
|
|
|
#define MD_CODE(x) "`" x "`"
|
|
|
|
// code block macros
|
|
|
|
#define MD_CODEBLOCK(x) "```" x "```"
|
|
|
|
// code block macros with language
|
|
|
|
#define MD_CODEBLOCK_LANG(l, c) "```" l "\n" c "\n```"
|
|
|
|
// text macros
|
|
|
|
#define MD_TEXT(x) x
|
|
|
|
// list macros
|
|
|
|
#define MD_LIST(x) "- " x "\n"
|
|
|
|
|
|
|
|
// XML macros
|
|
|
|
// urlset macros
|
|
|
|
#define XML_URLSET() "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"
|
|
|
|
// url macros
|
|
|
|
#define XML_URL(x) " <url>\n" \
|
|
|
|
" <loc>" x "</loc>\n" \
|
|
|
|
" <lastmod>" __DATE__ "</lastmod>\n" \
|
|
|
|
" </url>\n"
|
|
|
|
// end urlset macros
|
|
|
|
#define XML_END_URLSET() "</urlset>\n"
|
|
|
|
|
2023-07-13 22:00:51 +00:00
|
|
|
// HTML macros
|
|
|
|
// html tag macros
|
|
|
|
#define HTML_TAG(t, c) "<" t ">\n" c "</" t ">\n"
|
|
|
|
// html tag macros open
|
|
|
|
#define HTML_TAG_OPEN(t, a) "<" t " " a ">\n"
|
|
|
|
// html tag macros with attributes and content
|
|
|
|
#define HTML_TAG_OPEN_CONTENT(t, a, c) "<" t " " a ">\n" c "</" t ">\n"
|
|
|
|
// html tag macros close
|
|
|
|
#define HTML_TAG_CLOSE(t) "</" t ">"
|
|
|
|
// html raw text macros
|
|
|
|
#define HTML_RAWTEXT(x) x
|
|
|
|
// html new line macros
|
|
|
|
#define HTML_NEWLINE() "\n"
|