|
|
|
@ -37,6 +37,11 @@ namespace lex {
@@ -37,6 +37,11 @@ namespace lex {
|
|
|
|
|
#include <lexbor/dom/dom.h> |
|
|
|
|
#include "lexbor_base.h" |
|
|
|
|
|
|
|
|
|
struct serializer_result { |
|
|
|
|
size_t len; |
|
|
|
|
const lxb_char_t *data; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -139,11 +144,9 @@ class duktape {
@@ -139,11 +144,9 @@ class duktape {
|
|
|
|
|
|
|
|
|
|
std::string eval_katex(std::string math_text) { |
|
|
|
|
|
|
|
|
|
spdlog::info("fuicking help math_text {}", math_text); |
|
|
|
|
|
|
|
|
|
math_text = math_text.substr(2, math_text.length() - 4); |
|
|
|
|
|
|
|
|
|
spdlog::info("fuicking help math_text {}", math_text); |
|
|
|
|
|
|
|
|
|
const char *matht = math_text.c_str(); |
|
|
|
|
|
|
|
|
@ -151,7 +154,6 @@ class duktape {
@@ -151,7 +154,6 @@ class duktape {
|
|
|
|
|
line += matht; |
|
|
|
|
line += "', {throwOnError: false });"; |
|
|
|
|
|
|
|
|
|
spdlog::info("fuicking help me {}", line); |
|
|
|
|
|
|
|
|
|
duk_push_lstring(ctx, line.c_str(), line.length()); |
|
|
|
|
if (duk_peval(ctx) != 0) { |
|
|
|
@ -230,7 +232,6 @@ class builder {
@@ -230,7 +232,6 @@ class builder {
|
|
|
|
|
|
|
|
|
|
duk::duktape dukengine {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const std::set<std::string> apply_templates_exts {"md","html", "txt", "markdown", "xml", "atom", "rss"}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -328,8 +329,18 @@ class builder {
@@ -328,8 +329,18 @@ class builder {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lxb_inline lex::lxb_status_t |
|
|
|
|
serializer_callback_s(const lex::lxb_char_t *data, size_t len, void *ctx) |
|
|
|
|
{ |
|
|
|
|
lex::serializer_result * res = (lex::serializer_result *)ctx; |
|
|
|
|
res->len = len; |
|
|
|
|
res->data = data; |
|
|
|
|
|
|
|
|
|
void postprocess_math(const std::string &html_text) { |
|
|
|
|
return lex::LXB_STATUS_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string postprocess_math(const std::string &html_text) { |
|
|
|
|
using namespace lex; |
|
|
|
|
|
|
|
|
|
lxb_html_document_t *document =
|
|
|
|
@ -342,7 +353,7 @@ class builder {
@@ -342,7 +353,7 @@ class builder {
|
|
|
|
|
if (collection == nullptr) { |
|
|
|
|
spdlog::warn("failed to parse html?"); |
|
|
|
|
// messy
|
|
|
|
|
return; |
|
|
|
|
return html_text; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -353,7 +364,10 @@ class builder {
@@ -353,7 +364,10 @@ class builder {
|
|
|
|
|
|
|
|
|
|
if (err != LXB_STATUS_OK) { |
|
|
|
|
spdlog::warn("failed to parse html?"); |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
lxb_dom_collection_destroy(collection, true); |
|
|
|
|
lxb_html_document_destroy(document); |
|
|
|
|
return html_text; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < lxb_dom_collection_length(collection); i++) { |
|
|
|
@ -363,13 +377,27 @@ class builder {
@@ -363,13 +377,27 @@ class builder {
|
|
|
|
|
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); |
|
|
|
|
auto hn = lxb_dom_node_text_content_set(&element->node, (const unsigned char *)mathtext.c_str(), mathtext.length()); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lexbor_str_t res {}; |
|
|
|
|
|
|
|
|
|
err = lxb_html_serialize_tree_str(lxb_dom_interface_node(document), |
|
|
|
|
&res); |
|
|
|
|
|
|
|
|
|
if (err != LXB_STATUS_OK) { |
|
|
|
|
FAILED("Failed to serialization HTML tree"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
serialize(lxb_dom_interface_node(document)); |
|
|
|
|
std::string result = {res.data, res.data + res.length}; |
|
|
|
|
|
|
|
|
|
lxb_dom_collection_destroy(collection, true); |
|
|
|
|
lxb_html_document_destroy(document); |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -704,7 +732,7 @@ class builder {
@@ -704,7 +732,7 @@ class builder {
|
|
|
|
|
|
|
|
|
|
if (ext == "md" || ext == "markdown") { |
|
|
|
|
text = parser.parse_to_html(text);
|
|
|
|
|
postprocess_math(text); |
|
|
|
|
text = postprocess_math(text); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|