2026-07-18 18:48:23 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "klammer_base.h"
|
|
|
|
|
#include "html_util.h"
|
|
|
|
|
#include "latex_util.h"
|
|
|
|
|
#include "machine.h"
|
|
|
|
|
#include "heading.h"
|
Typed arguments, calculated tables, spans, closed-world fonts, top-level fnt/ and env/
Sync with klammertext-dev through b90b0e09:
- Argument types end to end: :python_cast values are applied (Python
@eval receives real bools/numbers/lists), argument values are
validated against their argtype patterns with the argtype's
description as the error message, argtypes can declare :default
(overridable per declaration), and parameterized type families are
supported: rest(N) casts a rest argument to an N-dimensional list
(bar-count = dimension).
- Unified indexed_range syntax (selector with parenthesized subsets,
composable mnemonic names) for table lines and spans.
- Table klammer: caption fonts fixed in both targets, :column_width /
:leading / :colsep wired, :colspan and :rowspan render (HTML
attributes; \multicolumn / \multirow), calculated cell values (:calc)
with prefix operators, display-precision semantics, :calc_format and
:decimal period|comma.
- Fonts: closed-world resolution on the Klammertext font store
(infrastructure in mac/font_store; no Google Fonts links or fetch).
Default fonts live in the top-level fnt/; additional fonts install
into KLAMMERTEXT_FONTS directories via kdesc --font (list, samples,
preview, install — classification by font metadata). CSS font family
names are quoted (digit-initial families were silently lost).
- Environment files moved from mac/env/ to the top-level env/; shell
profiles source env/runtime.env. Dead per-host variants removed.
- Container: fnt/ ships in the image; curl removed (no network use).
2026-07-22 18:17:43 +02:00
|
|
|
#include "font_store.h"
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
const std::string closed_symbol { "&^#9656;" };
|
|
|
|
|
const std::string open_symbol { "&^#9662;" };
|
|
|
|
|
inline std::map<std::string, int> html_tags {
|
|
|
|
|
{"kt-part", 0}, {"kt-chapter", 1}, {"h1", 2},
|
|
|
|
|
{"h2", 3}, {"h3", 4}, {"h4", 5},
|
|
|
|
|
{"h5", 6}, {"h6", 7}, {"h7", 8}};
|
|
|
|
|
|
|
|
|
|
using string_pairs_t = std::vector<std::pair<std::string,std::string>>;
|
|
|
|
|
|
|
|
|
|
std::string unescape_newlines(std::string s);
|
|
|
|
|
|
|
|
|
|
enum class docstruct_t {
|
|
|
|
|
plain,
|
|
|
|
|
article,
|
|
|
|
|
book
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
inline docstruct_t docstruct(std::string name)
|
|
|
|
|
{
|
|
|
|
|
if (name == "plain") {
|
|
|
|
|
return docstruct_t::plain;
|
|
|
|
|
} else if (name == "article") {
|
|
|
|
|
return docstruct_t::article;
|
|
|
|
|
} else {
|
|
|
|
|
return docstruct_t::book;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Document_class : public Klammer_base {
|
|
|
|
|
public:
|
|
|
|
|
Document_class(Machine& machine);
|
|
|
|
|
~Document_class() = default;
|
|
|
|
|
|
|
|
|
|
void save_string_input_as_file();
|
|
|
|
|
|
|
|
|
|
//void create_directory(std::string directory);
|
|
|
|
|
void write(std::string filename, std::string contents);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
strings_t get_css_files(
|
|
|
|
|
std::string output_dir,
|
|
|
|
|
std::string css_text, strings_t css_files, bool write_file);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
strings_t get_js_files(
|
|
|
|
|
bool nav, bool include_sks_js,
|
|
|
|
|
std::string pages_basenames_filename); // , std::string output_dir, bool write_file);
|
|
|
|
|
|
|
|
|
|
argmap m_args {};
|
|
|
|
|
void write_basenames_js_file(std::string filename, std::vector<std::string> basenames);
|
|
|
|
|
std::string create_html_output_directories();
|
|
|
|
|
std::string create_tex_output_directories();
|
|
|
|
|
|
|
|
|
|
std::pair<std::vector<std::string>, std::vector<std::string>>
|
|
|
|
|
html_auxiliary_files(std::string output_directory, std::string pages_basename_filename,
|
|
|
|
|
std::vector<std::string> custom_css_files);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void process_input_files();
|
|
|
|
|
std::vector<Heading> insert_section_numbers(std::string marker="___NUM___", bool add_to_toc=true);
|
|
|
|
|
void insert_html_caption_numbers();
|
|
|
|
|
std::vector<std::tuple<std::string, std::string, std::string>> reference_list(std::string target_marker);
|
|
|
|
|
std::map<std::string, std::string> id_to_caption_number();
|
|
|
|
|
std::map<std::string, std::vector<std::pair<std::string, std::string>>> html_references();
|
|
|
|
|
void resolve_html_references();
|
|
|
|
|
std::string single_page_toc();
|
|
|
|
|
elements_t page(std::string body, std::string output_dir, int max_level);
|
|
|
|
|
|
|
|
|
|
std::string make_single_html_page(std::string output_directory);
|
|
|
|
|
std::string make_html_navigation_structure(
|
|
|
|
|
std::string output_directory, std::vector<Heading> headings);
|
|
|
|
|
std::string html();
|
|
|
|
|
std::string tex();
|
|
|
|
|
std::string make_help_page();
|
|
|
|
|
std::string color_definitions();
|
|
|
|
|
std::string font_definitions();
|
|
|
|
|
strings_t resolved_font_names();
|
|
|
|
|
|
|
|
|
|
Machine m_machine {};
|
|
|
|
|
|
|
|
|
|
std::string m_title {};
|
|
|
|
|
std::string m_subtitle {};
|
|
|
|
|
std::string m_page_title {};
|
|
|
|
|
std::string m_author {};
|
|
|
|
|
std::string m_date {};
|
|
|
|
|
std::string m_version {};
|
|
|
|
|
std::string m_logo {};
|
|
|
|
|
|
|
|
|
|
// bool m_nav = false;
|
|
|
|
|
// bool m_toc = false;
|
|
|
|
|
docstruct_t m_structure = docstruct_t::plain;
|
|
|
|
|
|
|
|
|
|
std::string m_text {};
|
|
|
|
|
strings_t m_files {};
|
|
|
|
|
|
|
|
|
|
std::string m_output_dir {};
|
|
|
|
|
|
|
|
|
|
bool include_css = true;
|
|
|
|
|
bool include_js = true;
|
|
|
|
|
|
|
|
|
|
std::string m_css_text {};
|
|
|
|
|
strings_t m_css_filenames {};
|
|
|
|
|
bool m_include_sks_css = true;
|
|
|
|
|
std::string frame_background_color {};
|
|
|
|
|
std::string frame_text_color {};
|
|
|
|
|
std::string nav_background_color {};
|
|
|
|
|
std::string nav_text_color {};
|
|
|
|
|
|
|
|
|
|
std::string js_text {};
|
|
|
|
|
strings_t m_js_filenames {};
|
|
|
|
|
bool m_include_sks_js = true;
|
|
|
|
|
|
|
|
|
|
strings_t m_font_dirs {};
|
|
|
|
|
|
|
|
|
|
std::string m_serif_font {};
|
|
|
|
|
std::string m_sans_font {};
|
|
|
|
|
std::string m_mono_font {};
|
|
|
|
|
float m_font_scale = 1.0f;
|
|
|
|
|
Resolved_font m_resolved_serif {};
|
|
|
|
|
Resolved_font m_resolved_sans {};
|
|
|
|
|
Resolved_font m_resolved_mono {};
|
|
|
|
|
|
|
|
|
|
std::string prolog {};
|
|
|
|
|
std::string paper_size {};
|
|
|
|
|
bool m_two_column = false;
|
|
|
|
|
bool landscape = false;
|
|
|
|
|
float leading = 1.0;
|
|
|
|
|
int point_size = 10;
|
|
|
|
|
bool ragged_right = false;
|
|
|
|
|
std::string cover {};
|
|
|
|
|
|
|
|
|
|
std::string m_copyright {};
|
|
|
|
|
std::string m_bottom {};
|
|
|
|
|
|
|
|
|
|
bool create_output_directory = true;
|
|
|
|
|
std::string output_directory_name {};
|
|
|
|
|
bool resources_in_file = false;
|
|
|
|
|
//bool use_pages_dir = true;
|
|
|
|
|
|
|
|
|
|
bool m_toc_only = false;
|
|
|
|
|
std::string m_kt_root_filename {};
|
|
|
|
|
|
|
|
|
|
bool m_no_cache = false;
|
|
|
|
|
|
|
|
|
|
bool write_files = true;
|
|
|
|
|
std::string m_input_dir {};
|
|
|
|
|
|
|
|
|
|
// strings_t sources {};
|
|
|
|
|
Locator loc {};
|
|
|
|
|
std::string sloc {};
|
|
|
|
|
|
|
|
|
|
bool m_html_only = false;
|
|
|
|
|
|
|
|
|
|
std::vector<std::pair<std::string, std::string>> m_file_components {};
|
|
|
|
|
std::vector<std::pair<std::string, std::string>> m_string_components {};
|
|
|
|
|
std::vector<std::tuple<std::string,std::string,std::string,std::string>> m_toc_components {};
|
|
|
|
|
|
|
|
|
|
std::string m_cache_dir {};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
fs::path parse_input_filename(std::string s, std::string input_dir);
|
|
|
|
|
void write_file(std::string filename, std::string contents, bool write_files);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
std::vector<std::string> combine_files(
|
|
|
|
|
std::vector<std::string> filenames, std::string output_filename,
|
|
|
|
|
std::string prolog="", std::string epilog="",
|
|
|
|
|
bool write_file_p=true,
|
|
|
|
|
std::function <std::string(std::string)> processor=nullptr);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|