|
|
|
@ -32,6 +32,14 @@
@@ -32,6 +32,14 @@
|
|
|
|
|
#include "markdown.h" |
|
|
|
|
#include "templater.hpp" |
|
|
|
|
|
|
|
|
|
extern "C" { |
|
|
|
|
namespace lex { |
|
|
|
|
#include <lexbor/dom/dom.h> |
|
|
|
|
#include "lexbor_base.h" |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const std::string SITE_CONFIG_FNAME = "stgen.json"; |
|
|
|
|
const std::string DEFAULT_PUBLISH_ROOT = "public"; |
|
|
|
@ -321,6 +329,50 @@ class builder {
@@ -321,6 +329,50 @@ class builder {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void postprocess_math(const std::string &html_text) { |
|
|
|
|
using namespace lex; |
|
|
|
|
|
|
|
|
|
lxb_html_document_t *document =
|
|
|
|
|
parse((const unsigned char *)html_text.c_str(), html_text.length()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lxb_dom_collection_t *collection =
|
|
|
|
|
lxb_dom_collection_make(&document->dom_document, 128); |
|
|
|
|
|
|
|
|
|
if (collection == nullptr) { |
|
|
|
|
spdlog::warn("failed to parse html?"); |
|
|
|
|
// messy
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto err = lxb_dom_elements_by_class_name( |
|
|
|
|
lxb_dom_interface_element(document->body), |
|
|
|
|
collection, (const lxb_char_t *) "math", 4); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (err != LXB_STATUS_OK) { |
|
|
|
|
spdlog::warn("failed to parse html?"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < lxb_dom_collection_length(collection); i++) { |
|
|
|
|
lxb_dom_element_t *element = lxb_dom_collection_element(collection, i); |
|
|
|
|
//serialize_node(lxb_dom_interface_node(element));
|
|
|
|
|
size_t len; |
|
|
|
|
lxb_char_t *text = lxb_dom_node_text_content(&element->node, &len); |
|
|
|
|
const std::string tt {(const char *)text, (const char *)text + len}; |
|
|
|
|
std::string mathtext = dukengine.eval_katex(tt); |
|
|
|
|
spdlog::warn("math text: {}", mathtext); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lxb_dom_collection_destroy(collection, true); |
|
|
|
|
lxb_html_document_destroy(document); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** BRoken and ridiculous and wont work why did i write this. */ |
|
|
|
|
std::string replace_math(const std::string &text) { |
|
|
|
|
|
|
|
|
@ -651,9 +703,8 @@ class builder {
@@ -651,9 +703,8 @@ class builder {
|
|
|
|
|
auto job_t = job_type::TEMPLATE; |
|
|
|
|
|
|
|
|
|
if (ext == "md" || ext == "markdown") { |
|
|
|
|
replace_math(text); |
|
|
|
|
text = parser.parse_to_html(text);
|
|
|
|
|
// text = postprocess_js(text);
|
|
|
|
|
postprocess_math(text); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|