--- lbbs/src/article_cache.c 2025/06/02 10:33:25 1.10 +++ lbbs/src/article_cache.c 2025/06/04 13:42:53 1.13 @@ -16,6 +16,7 @@ #include "article_cache.h" #include "log.h" +#include "lml.h" #include #include #include @@ -28,6 +29,7 @@ #include #define ARTICLE_HEADER_MAX_LEN 4096 +#define ARTICLE_CONTENT_MAX_LEN 1024 * 1024 * 4 // 4MB #define ARTICLE_FOOTER_MAX_LEN 4096 #define SUB_DT_MAX_LEN 50 @@ -66,6 +68,7 @@ int article_cache_generate(const char *c char header[ARTICLE_HEADER_MAX_LEN]; size_t header_len; long header_line_cnt; + char content_f[ARTICLE_CONTENT_MAX_LEN]; char footer[ARTICLE_FOOTER_MAX_LEN]; size_t footer_len; long footer_line_cnt; @@ -115,22 +118,23 @@ int article_cache_generate(const char *c header_len = strnlen(header, sizeof(header)); footer_len = strnlen(footer, sizeof(footer)); - cache.data_len = header_len + strlen(content); - header_line_cnt = split_data_lines(header, SCREEN_COLS, cache.line_offsets, MAX_SPLIT_FILE_LINES); if (header_len != cache.line_offsets[header_line_cnt]) { - log_std("Header of article(aid=%d) is truncated from %ld to %ld\n", p_article->aid, header_len, cache.line_offsets[header_line_cnt]); + log_common("Header of article(aid=%d) is truncated from %ld to %ld\n", p_article->aid, header_len, cache.line_offsets[header_line_cnt]); header_len = (size_t)cache.line_offsets[header_line_cnt]; } + // Apply LML render to content body + cache.data_len = header_len + (size_t)lml_plain(content, content_f, ARTICLE_CONTENT_MAX_LEN); + cache.line_total = header_line_cnt + - split_data_lines(content, SCREEN_COLS, cache.line_offsets + header_line_cnt, MAX_SPLIT_FILE_LINES - header_line_cnt); + split_data_lines(content_f, SCREEN_COLS, cache.line_offsets + header_line_cnt, MAX_SPLIT_FILE_LINES - header_line_cnt); if (cache.data_len - header_len != (size_t)cache.line_offsets[cache.line_total]) { - log_std("Body of article(aid=%d) is truncated from %ld to %ld\n", + log_common("Body of article(aid=%d) is truncated from %ld to %ld\n", p_article->aid, cache.data_len - header_len, cache.line_offsets[cache.line_total]); cache.data_len = header_len + (size_t)(cache.line_offsets[cache.line_total]); } @@ -144,7 +148,7 @@ int article_cache_generate(const char *c if (footer_len != cache.line_offsets[cache.line_total + footer_line_cnt]) { - log_std("Footer of article(aid=%d) is truncated from %ld to %ld\n", + log_common("Footer of article(aid=%d) is truncated from %ld to %ld\n", p_article->aid, footer_len, cache.line_offsets[cache.line_total + footer_line_cnt]); footer_len = (size_t)(cache.line_offsets[cache.line_total + footer_line_cnt]); } @@ -170,7 +174,7 @@ int article_cache_generate(const char *c close(fd); return -3; } - if (write(fd, content, cache.data_len - header_len - footer_len) == -1) + if (write(fd, content_f, cache.data_len - header_len - footer_len) == -1) { log_error("write(%s, content) error (%d)\n", data_file, errno); close(fd);