Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a named, logically related group of klammer definitions — with an operative, idempotent declaration (:requires and :files load in order at the declaration point, relative to the declaring file). A bare symbol given to ktext -k, kdesc --input, or :requires resolves to x/x.k on the search path: the document's directory, then KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset lists the available sets. sks/sks.k is the first declared klammerset, so `-k sks` loads the SKS by name. The engine's lookup classes were renamed *_set → *_registry to keep the two concepts apart, and the whole C++ tree now follows standard const-correctness conventions. tst/ gains klammerset_test.sh (18 cases). (from dev 64b1abf23e56)
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
#include "log.h"
|
||||
#include "file.h"
|
||||
|
||||
bool strbool(std::string s, Locator loc)
|
||||
bool strbool(const std::string& s, const Locator& loc)
|
||||
{
|
||||
std::vector<std::string> values = {"false", "False", "0", "true", "True", "1"};
|
||||
if (is_not_in(s, values)) {
|
||||
@@ -136,7 +136,7 @@ void Document_class::save_string_input_as_file()
|
||||
}
|
||||
|
||||
|
||||
fs::path parse_input_filename(std::string s, std::string input_dir)
|
||||
fs::path parse_input_filename(const std::string& s, const std::string& input_dir)
|
||||
{
|
||||
fs::path p(s);
|
||||
if (p.extension() != ".kt") {
|
||||
@@ -160,13 +160,13 @@ fs::path parse_input_filename(std::string s, std::string input_dir)
|
||||
return p;
|
||||
}
|
||||
|
||||
void Document_class::write(std::string filename, std::string contents)
|
||||
void Document_class::write(const std::string& filename, const std::string& contents)
|
||||
{
|
||||
write_file(filename, contents, write_files);
|
||||
}
|
||||
|
||||
|
||||
void write_file(std::string filename, std::string contents, bool write_p)
|
||||
void write_file(const std::string& filename, const std::string& contents, bool write_p)
|
||||
{
|
||||
if (write_p) {
|
||||
string_to_file(filename, contents);
|
||||
@@ -177,14 +177,14 @@ void write_file(std::string filename, std::string contents, bool write_p)
|
||||
|
||||
|
||||
/*
|
||||
void output_msg(std::string msg)
|
||||
void output_msg(const std::string& msg)
|
||||
{
|
||||
std::cout << red;
|
||||
(void)K::log(1, msg);
|
||||
std::cout << black;
|
||||
}
|
||||
|
||||
void Document_class::create_directory(std::string directory)
|
||||
void Document_class::create_directory(const std::string& directory)
|
||||
{
|
||||
if (write_files) {
|
||||
fs::create_directories(directory);
|
||||
|
||||
@@ -16,7 +16,7 @@ inline std::map<std::string, int> html_tags {
|
||||
|
||||
using string_pairs_t = std::vector<std::pair<std::string,std::string>>;
|
||||
|
||||
std::string unescape_newlines(std::string s);
|
||||
std::string unescape_newlines(const std::string& s);
|
||||
|
||||
enum class docstruct_t {
|
||||
plain,
|
||||
@@ -24,7 +24,7 @@ enum class docstruct_t {
|
||||
book
|
||||
};
|
||||
|
||||
inline docstruct_t docstruct(std::string name)
|
||||
inline docstruct_t docstruct(const std::string& name)
|
||||
{
|
||||
if (name == "plain") {
|
||||
return docstruct_t::plain;
|
||||
@@ -43,41 +43,41 @@ public:
|
||||
void save_string_input_as_file();
|
||||
|
||||
//void create_directory(std::string directory);
|
||||
void write(std::string filename, std::string contents);
|
||||
void write(const std::string& filename, const std::string& contents);
|
||||
|
||||
/*
|
||||
strings_t get_css_files(
|
||||
std::string output_dir,
|
||||
std::string css_text, strings_t css_files, bool write_file);
|
||||
const std::string& output_dir,
|
||||
const std::string& css_text, const 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);
|
||||
const std::string& pages_basenames_filename); // , const std::string& output_dir, bool write_file);
|
||||
|
||||
argmap m_args {};
|
||||
void write_basenames_js_file(std::string filename, std::vector<std::string> basenames);
|
||||
void write_basenames_js_file(const std::string& filename, const 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);
|
||||
html_auxiliary_files(const std::string& output_directory, const std::string& pages_basename_filename,
|
||||
const 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);
|
||||
std::vector<Heading> insert_section_numbers(const 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::vector<std::tuple<std::string, std::string, std::string>> reference_list(const 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);
|
||||
elements_t page(const std::string& body, const std::string& output_dir, int max_level);
|
||||
|
||||
std::string make_single_html_page(std::string output_directory);
|
||||
std::string make_single_html_page(const std::string& output_directory);
|
||||
std::string make_html_navigation_structure(
|
||||
std::string output_directory, std::vector<Heading> headings);
|
||||
const std::string& output_directory, std::vector<Heading> headings);
|
||||
std::string html();
|
||||
std::string tex();
|
||||
std::string make_help_page();
|
||||
@@ -167,13 +167,13 @@ public:
|
||||
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);
|
||||
fs::path parse_input_filename(const std::string& s, const std::string& input_dir);
|
||||
void write_file(const std::string& filename, const 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="",
|
||||
const std::vector<std::string>& filenames, const std::string& output_filename,
|
||||
const std::string& prolog="", const std::string& epilog="",
|
||||
bool write_file_p=true,
|
||||
std::function <std::string(std::string)> processor=nullptr);
|
||||
*/
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "show.h"
|
||||
#include "file.h"
|
||||
|
||||
std::string unescape_newlines(std::string s)
|
||||
std::string unescape_newlines(const std::string& s)
|
||||
{
|
||||
return string_replace(s, " ___NL___ ", "\n");
|
||||
|
||||
@@ -44,7 +44,7 @@ std::string insert_missing_ids(std::smatch match)
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string insert_ids(std::string html_text)
|
||||
std::string insert_ids(const std::string& html_text)
|
||||
{
|
||||
(void)K::log(3);
|
||||
std::string result = html_text;
|
||||
@@ -154,7 +154,7 @@ std::string Document_class::font_definitions()
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void Document_class::write_basenames_js_file(std::string filename, std::vector<std::string> basenames)
|
||||
void Document_class::write_basenames_js_file(const std::string& filename, const std::vector<std::string>& basenames)
|
||||
{
|
||||
(void)K::log(3);
|
||||
std::string tab(" ");
|
||||
@@ -202,7 +202,7 @@ std::string Document_class::create_html_output_directories()
|
||||
return output_directory;
|
||||
}
|
||||
|
||||
strings_t get_css_files(strings_t custom_css_files)
|
||||
strings_t get_css_files(const strings_t& custom_css_files)
|
||||
{
|
||||
(void)K::log(3);
|
||||
strings_t result = sks_files_of_type("css");
|
||||
@@ -223,7 +223,7 @@ std::vector<std::string> js_basenames(bool nav)
|
||||
|
||||
strings_t Document_class::get_js_files(
|
||||
bool nav, bool include_sks_js,
|
||||
std::string pages_basenames_filename)
|
||||
const std::string& pages_basenames_filename)
|
||||
{
|
||||
(void)K::log(3);
|
||||
strings_t result {};
|
||||
@@ -244,13 +244,13 @@ strings_t Document_class::get_js_files(
|
||||
}
|
||||
|
||||
|
||||
strings_t link_filenames(strings_t& full_filenames, std::string page_dir)
|
||||
strings_t link_filenames(strings_t& full_filenames, const std::string& page_dir)
|
||||
{
|
||||
strings_t result {};
|
||||
fs::path page_dir_path(page_dir);
|
||||
// int i = 0;
|
||||
std::transform(full_filenames.begin(), full_filenames.end(), std::back_inserter(result),
|
||||
[&](std::string f) {
|
||||
[&](const std::string& f) {
|
||||
fs::path full(f);
|
||||
//msg() << i << full << " " << full.filename() << "\n";
|
||||
fs::path path(page_dir_path / full.filename());
|
||||
@@ -260,8 +260,8 @@ strings_t link_filenames(strings_t& full_filenames, std::string page_dir)
|
||||
}
|
||||
|
||||
std::pair<std::vector<std::string>, std::vector<std::string>>
|
||||
Document_class::html_auxiliary_files(std::string output_directory, std::string pages_basenames_filename,
|
||||
std::vector<std::string> custom_css_files)
|
||||
Document_class::html_auxiliary_files(const std::string& output_directory, const std::string& pages_basenames_filename,
|
||||
const std::vector<std::string>& custom_css_files)
|
||||
{
|
||||
(void)K::log(3);
|
||||
strings_t all_css_files = custom_css_files;
|
||||
@@ -352,7 +352,7 @@ std::string increment_level(int level, std::vector<int> &levels)
|
||||
}
|
||||
|
||||
|
||||
std::string extract_id(std::string attr)
|
||||
std::string extract_id(const std::string& attr)
|
||||
{
|
||||
std::smatch match {};
|
||||
if (!std::regex_match(attr, match, id_attr_rgx)) {
|
||||
@@ -362,7 +362,7 @@ std::string extract_id(std::string attr)
|
||||
}
|
||||
|
||||
std::vector<Heading>
|
||||
Document_class::insert_section_numbers(std::string marker, bool add_to_toc)
|
||||
Document_class::insert_section_numbers(const std::string& marker, bool add_to_toc)
|
||||
{
|
||||
std::vector<int> levels(9, 0);
|
||||
std::smatch match {};
|
||||
@@ -407,7 +407,7 @@ Document_class::insert_section_numbers(std::string marker, bool add_to_toc)
|
||||
return headings;
|
||||
}
|
||||
|
||||
int get_caption_number(std::map<std::string, int>& numbers, std::string label)
|
||||
int get_caption_number(std::map<std::string, int>& numbers, const std::string& label)
|
||||
{
|
||||
int result;
|
||||
if (numbers.count(label) == 0) {
|
||||
@@ -470,7 +470,7 @@ void Document_class::insert_html_caption_numbers()
|
||||
|
||||
|
||||
std::vector<std::tuple<std::string, std::string, std::string>>
|
||||
Document_class::reference_list(std::string target_marker)
|
||||
Document_class::reference_list(const std::string& target_marker)
|
||||
{
|
||||
std::regex reference_rgx("__REF__");
|
||||
std::regex target_rgx("<div id=\"(.*?)\" data-label=\"(.*?)\" class=\"caption_");
|
||||
@@ -519,7 +519,7 @@ std::map<std::string, std::string> Document_class::id_to_caption_number()
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, int> offset_spec_to_count(std::string spec)
|
||||
std::pair<int, int> offset_spec_to_count(const std::string& spec)
|
||||
{
|
||||
std::regex rgx(R"((\w+)\s*(\d*))");
|
||||
std::smatch match {};
|
||||
@@ -637,7 +637,7 @@ std::string Document_class::single_page_toc()
|
||||
}
|
||||
|
||||
|
||||
elements_t Document_class::page(std::string body_text, std::string output_dir, int max_level)
|
||||
elements_t Document_class::page(const std::string& body_text, const std::string& output_dir, int max_level)
|
||||
{
|
||||
(void)K::log(3);
|
||||
std::string toc {}; // Calculate
|
||||
@@ -674,7 +674,7 @@ elements_t Document_class::page(std::string body_text, std::string output_dir, i
|
||||
return page;
|
||||
}
|
||||
|
||||
std::string Document_class::make_single_html_page(std::string output_directory)
|
||||
std::string Document_class::make_single_html_page(const std::string& output_directory)
|
||||
{
|
||||
(void)K::log(3);
|
||||
std::stringstream ss {};;
|
||||
@@ -694,7 +694,7 @@ std::string Document_class::make_single_html_page(std::string output_directory)
|
||||
}
|
||||
|
||||
std::string Document_class::make_html_navigation_structure(
|
||||
std::string output_directory, std::vector<Heading> headings)
|
||||
const std::string& output_directory, std::vector<Heading> headings)
|
||||
{
|
||||
msg() << "Navigation format\n";
|
||||
std::vector<std::string> pages_basenames {};
|
||||
|
||||
@@ -40,7 +40,7 @@ int unnumbered_id = 0;
|
||||
|
||||
/*
|
||||
std::tuple<std::string, std::vector<Heading>, std::vector<unsigned int>, unsigned int>
|
||||
add_section_numbers(std::string s, std::string basename, std::vector<unsigned int> levels, unsigned int initial_id,
|
||||
add_section_numbers(const std::string& s, const std::string& basename, std::vector<unsigned int> levels, unsigned int initial_id,
|
||||
std::map<std::string, std::string>& section_id_map)
|
||||
{
|
||||
(void)K::log(3);
|
||||
@@ -155,7 +155,7 @@ std::string make_html_table_of_contents(std::vector<Heading> headings)
|
||||
}
|
||||
|
||||
std::string toc_link_attrs(
|
||||
std::string section, std::string title, std::string filename, std::string target, int level)
|
||||
const std::string& section, const std::string& title, const std::string& filename, const std::string& target, int level)
|
||||
{
|
||||
std::string basename = file_basename(filename);
|
||||
std::stringstream ss {};
|
||||
@@ -259,7 +259,7 @@ make_navigation_table_of_contents(std::vector<Heading> headings)
|
||||
}
|
||||
|
||||
void show_table_of_contents(
|
||||
std::string kt_root_filename, std::string title, std::vector<Heading> headings)
|
||||
const std::string& kt_root_filename, const std::string& title, std::vector<Heading> headings)
|
||||
{
|
||||
long unsigned int width = kt_root_filename.size();
|
||||
for (Heading h : headings) {
|
||||
@@ -285,7 +285,7 @@ void show_table_of_contents(
|
||||
}
|
||||
|
||||
std::string cache_table_of_contents(
|
||||
std::string kt_root_filename, std::string title, std::vector<Heading> headings)
|
||||
const std::string& kt_root_filename, const std::string& title, std::vector<Heading> headings)
|
||||
{
|
||||
long unsigned int width = kt_root_filename.size();
|
||||
for (Heading h : headings) {
|
||||
|
||||
@@ -8,8 +8,8 @@ const std::string link_delimiter { "%" };
|
||||
|
||||
class Heading {
|
||||
public:
|
||||
Heading(int level, std::string filename, std::string section, std::string id,
|
||||
std::string number, std::string title)
|
||||
Heading(int level, const std::string& filename, const std::string& section, const std::string& id,
|
||||
const std::string& number, const std::string& title)
|
||||
: m_level(level), m_filename(filename), m_section(section), m_id(id),
|
||||
m_number(number), m_title(title)
|
||||
{};
|
||||
@@ -25,7 +25,7 @@ std::ostream& operator<<(std::ostream& os, const Heading h);
|
||||
|
||||
/*
|
||||
std::tuple<std::string, std::vector<Heading>, std::vector<unsigned int>, unsigned int>
|
||||
add_section_numbers(std::string s, std::string basename, std::vector<unsigned int> levels, unsigned int initial_id,
|
||||
add_section_numbers(const std::string& s, const std::string& basename, std::vector<unsigned int> levels, unsigned int initial_id,
|
||||
std::map<std::string, std::string>& section_id_map);
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@ std::pair<int, std::string>
|
||||
make_navigation_table_of_contents(std::vector<Heading> headings);
|
||||
|
||||
void show_table_of_contents(
|
||||
std::string kt_filename, std::string title, std::vector<Heading> headings);
|
||||
const std::string& kt_filename, const std::string& title, std::vector<Heading> headings);
|
||||
|
||||
std::string cache_table_of_contents(
|
||||
std::string kt_root_filename, std::string title, std::vector<Heading> headings);
|
||||
const std::string& kt_root_filename, const std::string& title, std::vector<Heading> headings);
|
||||
|
||||
@@ -29,7 +29,7 @@ std::ostream& operator<<(std::ostream& os, const numbered_elements& line_states)
|
||||
return os;
|
||||
}
|
||||
|
||||
std::string add_latex_caption_numbers(std::string latex_text)
|
||||
std::string add_latex_caption_numbers(const std::string& latex_text)
|
||||
{
|
||||
std::string caption_delimiter { "__CAPTION__" }; // But also in kutil.py
|
||||
std::regex caption_delimiter_rgx(caption_delimiter);
|
||||
@@ -74,7 +74,7 @@ std::string add_latex_caption_numbers(std::string latex_text)
|
||||
return result;
|
||||
}
|
||||
|
||||
numbered_elements latex_line_states(std::vector<std::string> lines)
|
||||
numbered_elements latex_line_states(const std::vector<std::string>& lines)
|
||||
{
|
||||
// \hypertarget{Reference-Figure-0}{}\label{Label-Reference-Figure-0}
|
||||
std::regex element_container_rgx(BS + R"(hypertarget\{(Reference-(\w+)-\d+)\}.*)");
|
||||
@@ -96,9 +96,9 @@ numbered_elements latex_line_states(std::vector<std::string> lines)
|
||||
return states;
|
||||
}
|
||||
|
||||
std::string find_target(std::string target,
|
||||
std::vector<std::string>& lines, int start, numbered_elements states,
|
||||
std::string target_type, int target_count, std::string direction)
|
||||
std::string find_target(const std::string& target,
|
||||
const std::vector<std::string>& lines, int start, const numbered_elements& states,
|
||||
const std::string& target_type, int target_count, const std::string& direction)
|
||||
{
|
||||
// msg() << "find_target: " << target_type << " target_count: " << target_count
|
||||
// << " direction: " << direction << "\n";
|
||||
@@ -137,7 +137,7 @@ std::string find_target(std::string target,
|
||||
}
|
||||
|
||||
std::string resolve_caption_references(
|
||||
std::string target, std::vector<std::string> lines, numbered_elements states)
|
||||
const std::string& target, const std::vector<std::string>& lines, numbered_elements states)
|
||||
{
|
||||
//auto lines = regex_split(text, std::regex(R"(\n)"), false);
|
||||
// numbered_elements states = line_states(lines);
|
||||
|
||||
@@ -11,12 +11,12 @@ using numbered_element_spec = std::tuple<std::string, std::string, std::string>;
|
||||
//using numbered_elements = std::vector<std::vector<numbered_element_spec>>;
|
||||
using numbered_elements = std::vector<numbered_element_spec>;
|
||||
|
||||
numbered_elements html_line_states(std::vector<std::string> lines);
|
||||
numbered_elements latex_line_states(std::vector<std::string> lines);
|
||||
numbered_elements html_line_states(const std::vector<std::string>& lines);
|
||||
numbered_elements latex_line_states(const std::vector<std::string>& lines);
|
||||
|
||||
std::pair<std::string, int> add_html_caption_numbers(std::string html_text, int& chapter_number);
|
||||
std::string add_latex_caption_numbers(std::string text);
|
||||
std::pair<std::string, int> add_html_caption_numbers(const std::string& html_text, int& chapter_number);
|
||||
std::string add_latex_caption_numbers(const std::string& text);
|
||||
|
||||
std::string resolve_caption_references(
|
||||
std::string target, std::vector<std::string> lines, numbered_elements states);
|
||||
const std::string& target, const std::vector<std::string>& lines, numbered_elements states);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "klammer_base.h"
|
||||
#include "show.h"
|
||||
|
||||
std::string Klammer_base::get(std::string name)
|
||||
std::string Klammer_base::get(const std::string& name)
|
||||
{
|
||||
//std::cout << "GET " << name << "\n";
|
||||
std::string result = m_machine.m_state.value(name);
|
||||
@@ -49,7 +49,7 @@ std::string Klammer_base::result()
|
||||
throw Target_error("Unknown target: " + target);
|
||||
}
|
||||
|
||||
void Klammer_base::show(std::string klammer_name)
|
||||
void Klammer_base::show(const std::string& klammer_name)
|
||||
{
|
||||
std::cout << "Arguments of klammer \"" << klammer_name << "\"\n"
|
||||
<< m_machine.m_state.describe() << "\n";
|
||||
|
||||
@@ -18,14 +18,14 @@ public:
|
||||
{};
|
||||
virtual ~Klammer_base() {};
|
||||
|
||||
std::string get(std::string);
|
||||
std::string get(const std::string& name);
|
||||
std::string get(const char* name);
|
||||
virtual std::string html();
|
||||
virtual std::string tex();
|
||||
virtual std::string txt();
|
||||
|
||||
std::string result();
|
||||
void show(std::string klammer_name);
|
||||
void show(const std::string& klammer_name);
|
||||
|
||||
Machine m_machine;
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
std::string read_file(std::string filename)
|
||||
std::string read_file(const std::string& filename)
|
||||
{
|
||||
std::ifstream stream {};
|
||||
std::ostringstream buffer {};
|
||||
@@ -36,7 +36,7 @@ std::string klammertext_dir()
|
||||
return kdir;
|
||||
}
|
||||
|
||||
bool in_subset(std::string base, std::vector<std::string> subset)
|
||||
bool in_subset(const std::string& base, const std::vector<std::string>& subset)
|
||||
{
|
||||
return subset.empty() ||
|
||||
(std::find(subset.begin(), subset.end(), base) != subset.end());
|
||||
@@ -44,7 +44,7 @@ bool in_subset(std::string base, std::vector<std::string> subset)
|
||||
|
||||
|
||||
|
||||
std::vector<std::string> sks_files_of_type(std::string extension, std::vector<std::string> subset)
|
||||
std::vector<std::string> sks_files_of_type(const std::string& extension, const std::vector<std::string>& subset)
|
||||
{
|
||||
bool dbg = false;
|
||||
std::string kdir = klammertext_dir();
|
||||
@@ -85,7 +85,7 @@ std::vector<std::string> sks_files_of_type(std::string extension, std::vector<st
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string find_kt_file(std::string filename)
|
||||
std::string find_kt_file(const std::string& filename)
|
||||
{
|
||||
std::string result {};
|
||||
std::vector<std::string> prefix {"", "kt/"};
|
||||
@@ -117,7 +117,7 @@ std::string find_kt_file(std::string filename)
|
||||
}
|
||||
|
||||
|
||||
std::string caption_marker(std::string name, std::string caption, std::string delimiter)
|
||||
std::string caption_marker(const std::string& name, const std::string& caption, const std::string& delimiter)
|
||||
{
|
||||
std::string result {caption};
|
||||
if (caption.size() > 0) {
|
||||
@@ -128,7 +128,7 @@ std::string caption_marker(std::string name, std::string caption, std::string de
|
||||
}
|
||||
|
||||
/*
|
||||
std::string process(Machine& M, std::string target, fs::path source_filename,
|
||||
std::string process(Machine& M, const std::string& target, const fs::path& source_filename,
|
||||
bool post_process, bool unescape_chars)
|
||||
{
|
||||
// Text text(source_filename, false, false);
|
||||
@@ -144,7 +144,7 @@ std::string process(Machine& M, std::string target, fs::path source_filename,
|
||||
return processed;
|
||||
}
|
||||
|
||||
std::string process(Machine& M, std::string target, std::string source_text,
|
||||
std::string process(Machine& M, const std::string& target, const std::string& source_text,
|
||||
bool post_process, bool unescape_chars)
|
||||
{
|
||||
Text text(source_text, false, false);
|
||||
@@ -157,8 +157,8 @@ std::string process(Machine& M, std::string target, std::string source_text,
|
||||
return processed;
|
||||
}
|
||||
|
||||
std::string process(Machine& M, std::string target,
|
||||
std::string source_text, fs::path source_filename,
|
||||
std::string process(Machine& M, const std::string& target,
|
||||
const std::string& source_text, const fs::path& source_filename,
|
||||
bool post_process, bool unescape_chars)
|
||||
{
|
||||
Text text({source_text}, {source_filename}, false, false);
|
||||
|
||||
@@ -12,24 +12,24 @@ std::vector<std::string> sks_basenames { // removed "book"
|
||||
|
||||
const std::string caption_delimiter = "__CAPTION__";
|
||||
|
||||
std::string read_file(std::string filename);
|
||||
std::string read_file(const std::string& filename);
|
||||
|
||||
std::string klammertext_dir();
|
||||
|
||||
std::vector<std::string> old_sks_files_of_type(std::string extension);
|
||||
std::vector<std::string> sks_files_of_type(std::string extension, std::vector<std::string> subset={});
|
||||
std::vector<std::string> old_sks_files_of_type(const std::string& extension);
|
||||
std::vector<std::string> sks_files_of_type(const std::string& extension, const std::vector<std::string>& subset={});
|
||||
|
||||
std::string caption_marker(std::string name, std::string caption, std::string delimiter=" – ");
|
||||
std::string caption_marker(const std::string& name, const std::string& caption, const std::string& delimiter=" – ");
|
||||
|
||||
std::string find_kt_file(std::string filename);
|
||||
std::string find_kt_file(const std::string& filename);
|
||||
|
||||
std::string process(Machine& M, std::string target, std::string source_text,
|
||||
std::string process(Machine& M, const std::string& target, const std::string& source_text,
|
||||
bool post_process=false, bool unescape_chars=false);
|
||||
|
||||
std::string process(Machine& M, std::string target, fs::path source_filename,
|
||||
std::string process(Machine& M, const std::string& target, const fs::path& source_filename,
|
||||
bool post_process=false, bool unescape_chars=false);
|
||||
|
||||
std::string process(Machine& M, std::string target,
|
||||
std::string source_text, fs::path source_filename,
|
||||
std::string process(Machine& M, const std::string& target,
|
||||
const std::string& source_text, const fs::path& source_filename,
|
||||
bool post_process, bool unescape_chars);
|
||||
|
||||
|
||||
23
sks/sks.k
23
sks/sks.k
@@ -1,15 +1,10 @@
|
||||
# Standard Klammer Set
|
||||
@read kutil/kutil.k @
|
||||
@read target/target.k @
|
||||
@read font/font.k @
|
||||
@read section/section.k @
|
||||
@read image/image.k @
|
||||
@read code/code.k @
|
||||
@read list/list.k @
|
||||
@read link/link.k @
|
||||
@read table/table.k @
|
||||
@read date/date.k @
|
||||
@read block/block.k @
|
||||
@read color/color.k @
|
||||
@read document/document.k @
|
||||
@read book/book.k @
|
||||
@@@klammerset sks | Document production: formatting, structure, and layout for the html, tex, pdf, and txt targets
|
||||
:name Standard Klammer Set
|
||||
:author Andy Kopra
|
||||
:date 2026-07-30
|
||||
:files kutil/kutil.k target/target.k font/font.k section/section.k
|
||||
image/image.k code/code.k list/list.k link/link.k
|
||||
table/table.k date/date.k block/block.k color/color.k
|
||||
document/document.k book/book.k
|
||||
@@@
|
||||
|
||||
@@ -132,7 +132,7 @@ std::string to_string(elements_t e)
|
||||
|
||||
|
||||
|
||||
bool HTML::void_element(std::string tag) const
|
||||
bool HTML::void_element(const std::string& tag) const
|
||||
{
|
||||
if (tag == "!DOCTYPE")
|
||||
return true;
|
||||
@@ -141,7 +141,7 @@ bool HTML::void_element(std::string tag) const
|
||||
(m_void_tags.begin(), m_void_tags.end(), tag) != m_void_tags.end();
|
||||
}
|
||||
|
||||
bool HTML::empty_element(std::string tag) const
|
||||
bool HTML::empty_element(const std::string& tag) const
|
||||
{
|
||||
if (tag == preamble_tag)
|
||||
return true;
|
||||
@@ -151,13 +151,13 @@ bool HTML::empty_element(std::string tag) const
|
||||
}
|
||||
|
||||
//HTML& HTML::attr(std::string name, std::variant<int, float, std::string> value)
|
||||
HTML& HTML::attr(std::string name, attr_t value)
|
||||
HTML& HTML::attr(const std::string& name, attr_t value)
|
||||
{
|
||||
m_attrs.push_back({name, value});
|
||||
return *this;
|
||||
}
|
||||
|
||||
HTML& HTML::attrs(std::string s)
|
||||
HTML& HTML::attrs(const std::string& s)
|
||||
{
|
||||
static const std::regex attr_rgx(R"((\w+)\s*=\s*\"(.*?)\")");
|
||||
auto attrs_begin = std::sregex_iterator(s.begin(), s.end(), attr_rgx);
|
||||
@@ -177,25 +177,25 @@ HTML& HTML::attrs(std::string s)
|
||||
|
||||
namespace html {
|
||||
|
||||
HTML elt(std::string tag)
|
||||
HTML elt(const std::string& tag)
|
||||
{
|
||||
HTML h(tag);
|
||||
return h;
|
||||
}
|
||||
|
||||
HTML elt(std::string tag, std::string text)
|
||||
HTML elt(const std::string& tag, const std::string& text)
|
||||
{
|
||||
HTML h(tag, trim(text));
|
||||
return h;
|
||||
}
|
||||
|
||||
HTML elt(std::string tag, elements_t elements)
|
||||
HTML elt(const std::string& tag, elements_t elements)
|
||||
{
|
||||
HTML h(tag, elements);
|
||||
return h;
|
||||
}
|
||||
|
||||
HTML elt(std::string tag, HTML e, elements_t elts)
|
||||
HTML elt(const std::string& tag, HTML e, elements_t elts)
|
||||
{
|
||||
elements_t elements = {e};
|
||||
elements.insert(elements.end(), elts.begin(), elts.end());
|
||||
@@ -242,7 +242,7 @@ namespace html {
|
||||
return result;
|
||||
}
|
||||
|
||||
elements_t local_font_elements(strings_t fontnames)
|
||||
elements_t local_font_elements(const strings_t& fontnames)
|
||||
{
|
||||
elements_t result {};
|
||||
for (auto name : fontnames) {
|
||||
@@ -254,7 +254,7 @@ namespace html {
|
||||
return result;
|
||||
}
|
||||
|
||||
elements_t javascript(std::string output_dir, strings_t js_filenames)
|
||||
elements_t javascript(const std::string& output_dir, const strings_t& js_filenames)
|
||||
{
|
||||
//elements_t result { jquery_elements() };
|
||||
elements_t result {};
|
||||
@@ -276,10 +276,10 @@ namespace html {
|
||||
return result;
|
||||
}
|
||||
|
||||
HTML head(std::string title,
|
||||
std::string css,
|
||||
strings_t css_filenames,
|
||||
strings_t local_fonts)
|
||||
HTML head(const std::string& title,
|
||||
const std::string& css,
|
||||
const strings_t& css_filenames,
|
||||
const strings_t& local_fonts)
|
||||
{
|
||||
elements_t elts = meta_elements();
|
||||
// msg() << "ELTS sks: " << elts << "\n";
|
||||
@@ -317,8 +317,8 @@ namespace html {
|
||||
}
|
||||
|
||||
|
||||
HTML button(std::string id, std::string name,
|
||||
std::string attrib="", std::string value="")
|
||||
HTML button(const std::string& id, const std::string& name,
|
||||
const std::string& attrib="", const std::string& value="")
|
||||
{
|
||||
std::vector<std::string> hidden = {"Clear", "Back"};
|
||||
HTML result = elt("span", string_replace(name, " ", " ")).id(id).cls("navb");
|
||||
@@ -449,7 +449,7 @@ namespace html {
|
||||
return result;
|
||||
}
|
||||
|
||||
elements_t status(std::string date, std::string version, std::string copyright)
|
||||
elements_t status(const std::string& date, const std::string& version, const std::string& copyright)
|
||||
{
|
||||
elements_t result {};
|
||||
if (!date.empty()) {
|
||||
@@ -465,21 +465,21 @@ namespace html {
|
||||
}
|
||||
|
||||
elements_t page(
|
||||
std::string title,
|
||||
const std::string& title,
|
||||
std::string page_title,
|
||||
std::string output_dir,
|
||||
std::string nav,
|
||||
const std::string& output_dir,
|
||||
const std::string& nav,
|
||||
int max_level,
|
||||
std::string toc,
|
||||
std::string text,
|
||||
std::string date,
|
||||
std::string version,
|
||||
std::string copyright,
|
||||
std::string css,
|
||||
strings_t css_filenames,
|
||||
strings_t js_filenames,
|
||||
strings_t local_fonts,
|
||||
std::string logo)
|
||||
const std::string& toc,
|
||||
const std::string& text,
|
||||
const std::string& date,
|
||||
const std::string& version,
|
||||
const std::string& copyright,
|
||||
const std::string& css,
|
||||
const strings_t& css_filenames,
|
||||
const strings_t& js_filenames,
|
||||
const strings_t& local_fonts,
|
||||
const std::string& logo)
|
||||
{
|
||||
if (page_title.empty())
|
||||
page_title = title;
|
||||
@@ -540,7 +540,7 @@ namespace html {
|
||||
}
|
||||
|
||||
|
||||
void add_title(elements_t& body, std::string title, std::string logo)
|
||||
void add_title(elements_t& body, const std::string& title, const std::string& logo)
|
||||
{
|
||||
// No title bar at all when there is nothing to put in it (an
|
||||
// untitled document); a logo alone still gets the bar.
|
||||
@@ -561,7 +561,7 @@ namespace html {
|
||||
body.push_back(navigation(max_level));
|
||||
}
|
||||
|
||||
void add_text(elements_t& body, std::string text, std::string toc, bool text_only)
|
||||
void add_text(elements_t& body, const std::string& text, const std::string& toc, bool text_only)
|
||||
{
|
||||
if (text_only) {
|
||||
elements_t content {};
|
||||
@@ -580,7 +580,7 @@ namespace html {
|
||||
}
|
||||
|
||||
void add_status_bar(
|
||||
elements_t& body, std::string date, std::string version, std::string copyright)
|
||||
elements_t& body, const std::string& date, const std::string& version, const std::string& copyright)
|
||||
{
|
||||
elements_t status_elements = status(date, version, copyright);
|
||||
if (!empty(status_elements)) {
|
||||
@@ -593,7 +593,7 @@ namespace html {
|
||||
body.push_back(elt("div", "").attr("id", "pagecache"));
|
||||
}
|
||||
|
||||
void add_js_links(elements_t& body, strings_t js_filenames, std::string output_dir)
|
||||
void add_js_links(elements_t& body, const strings_t& js_filenames, const std::string& output_dir)
|
||||
{
|
||||
if (!js_filenames.empty()) {
|
||||
auto js_elements { javascript(output_dir, js_filenames) };
|
||||
@@ -603,8 +603,8 @@ namespace html {
|
||||
|
||||
elements_t make_page(
|
||||
elements_t body,
|
||||
std::string page_title, std::string css,
|
||||
strings_t css_filenames, strings_t local_fonts)
|
||||
std::string page_title, const std::string& css,
|
||||
const strings_t& css_filenames, const strings_t& local_fonts)
|
||||
{
|
||||
elements_t page { preamble() };
|
||||
page.push_back(
|
||||
@@ -615,7 +615,7 @@ namespace html {
|
||||
return page;
|
||||
}
|
||||
|
||||
bool tag_is_block_element(std::string tag)
|
||||
bool tag_is_block_element(const std::string& tag)
|
||||
{
|
||||
auto location = std::find(block_elements.begin(), block_elements.end(), tag);
|
||||
return location != block_elements.end();
|
||||
@@ -635,7 +635,7 @@ namespace html {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string make_paragraphs(std::string html_text)
|
||||
std::string make_paragraphs(const std::string& html_text)
|
||||
{
|
||||
(void)K::log(3);
|
||||
std::string result {};
|
||||
@@ -654,7 +654,7 @@ namespace html {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string minimize_css(std::string src)
|
||||
std::string minimize_css(const std::string& src)
|
||||
{
|
||||
(void)K::log(3);
|
||||
std::string result = src;
|
||||
@@ -668,7 +668,7 @@ namespace html {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string minimize_js(std::string src)
|
||||
std::string minimize_js(const std::string& src)
|
||||
{
|
||||
(void)K::log(3);
|
||||
return src;
|
||||
|
||||
@@ -32,24 +32,24 @@ public:
|
||||
operator std::string() {
|
||||
std::stringstream ss {}; ss << *this; return ss.str(); };
|
||||
|
||||
HTML(std::string tag) :
|
||||
HTML(const std::string& tag) :
|
||||
m_tag(tag) {};
|
||||
|
||||
HTML(std::string tag, std::string text) :
|
||||
HTML(const std::string& tag, const std::string& text) :
|
||||
m_tag(tag), m_text({text}) {};
|
||||
|
||||
HTML(std::string tag, elements_t elements) :
|
||||
HTML(const std::string& tag, elements_t elements) :
|
||||
m_tag(tag), m_elements(elements) {};
|
||||
|
||||
HTML& attr(std::string name, attr_t value);
|
||||
HTML& attrs(std::string s);
|
||||
HTML& attr(const std::string& name, attr_t value);
|
||||
HTML& attrs(const std::string& s);
|
||||
|
||||
HTML& cls(std::string name) { return attr("class", name); };
|
||||
HTML& sty(std::string css) { return attr("style", css); };
|
||||
HTML& id(std::string id) { return attr("id", id); };
|
||||
HTML& cls(const std::string& name) { return attr("class", name); };
|
||||
HTML& sty(const std::string& css) { return attr("style", css); };
|
||||
HTML& id(const std::string& id) { return attr("id", id); };
|
||||
|
||||
bool void_element(std::string tag) const;
|
||||
bool empty_element(std::string tag) const;
|
||||
bool void_element(const std::string& tag) const;
|
||||
bool empty_element(const std::string& tag) const;
|
||||
friend std::ostream& operator<<(std::ostream& os, const HTML& h);
|
||||
friend std::ostream& operator<<(std::ostream& os, const std::vector<HTML>& hv);
|
||||
|
||||
@@ -68,48 +68,48 @@ private:
|
||||
};
|
||||
|
||||
namespace html {
|
||||
HTML elt(std::string tag);
|
||||
HTML elt(std::string tag, std::string text);
|
||||
HTML elt(std::string tag, elements_t elements);
|
||||
HTML elt(std::string tag, HTML e, elements_t elts);
|
||||
HTML elt(const std::string& tag);
|
||||
HTML elt(const std::string& tag, const std::string& text);
|
||||
HTML elt(const std::string& tag, elements_t elements);
|
||||
HTML elt(const std::string& tag, HTML e, elements_t elts);
|
||||
|
||||
//HTML preamble();
|
||||
//HTML head(strings_t css_filenames, strings_t js_filenames);
|
||||
|
||||
elements_t page(
|
||||
std::string title,
|
||||
const std::string& title,
|
||||
std::string page_title,
|
||||
std::string output_dir,
|
||||
std::string nav,
|
||||
const std::string& output_dir,
|
||||
const std::string& nav,
|
||||
int max_level,
|
||||
std::string toc,
|
||||
std::string text,
|
||||
std::string date,
|
||||
std::string version,
|
||||
std::string copyright,
|
||||
std::string css,
|
||||
const std::string& toc,
|
||||
const std::string& text,
|
||||
const std::string& date,
|
||||
const std::string& version,
|
||||
const std::string& copyright,
|
||||
const std::string& css,
|
||||
strings_t css_filenames = {},
|
||||
strings_t js_filenames = {},
|
||||
strings_t local_fonts = {},
|
||||
std::string logo = {});
|
||||
|
||||
void add_title(elements_t& body, std::string title, std::string logo="");
|
||||
void add_title(elements_t& body, std::string title, std::string logo);
|
||||
void add_title(elements_t& body, const std::string& title, const std::string& logo="");
|
||||
void add_title(elements_t& body, const std::string& title, const std::string& logo);
|
||||
void add_nav(elements_t& body, int max_level);
|
||||
void add_text(elements_t& body, std::string text, std::string toc_text, bool text_only);
|
||||
void add_text(elements_t& body, const std::string& text, const std::string& toc_text, bool text_only);
|
||||
void add_bottom_spacer(elements_t& body);
|
||||
void add_status_bar(elements_t& body, std::string date, std::string version, std::string copyright);
|
||||
void add_status_bar(elements_t& body, const std::string& date, const std::string& version, const std::string& copyright);
|
||||
void add_page_cache(elements_t& body);
|
||||
void add_js_links(elements_t& body, std::vector<std::string> js_filenames, std::string output_dir);
|
||||
void add_js_links(elements_t& body, const std::vector<std::string>& js_filenames, const std::string& output_dir);
|
||||
elements_t make_page(
|
||||
elements_t body,
|
||||
std::string page_title, std::string css,
|
||||
std::vector<std::string> css_filenames,
|
||||
std::vector<std::string> local_fonts);
|
||||
std::string page_title, const std::string& css,
|
||||
const std::vector<std::string>& css_filenames,
|
||||
const std::vector<std::string>& local_fonts);
|
||||
|
||||
bool tag_is_block_element(std::string tag);
|
||||
std::string make_paragraphs(std::string html_text);
|
||||
std::string minimize_css(std::string src);
|
||||
std::string minimize_js(std::string src);
|
||||
bool tag_is_block_element(const std::string& tag);
|
||||
std::string make_paragraphs(const std::string& html_text);
|
||||
std::string minimize_css(const std::string& src);
|
||||
std::string minimize_js(const std::string& src);
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace latex {
|
||||
|
||||
|
||||
std::string title_line(
|
||||
std::string text, std::string font="1.3", std::string vskip="4pt",
|
||||
const std::string& text, const std::string& font="1.3", const std::string& vskip="4pt",
|
||||
bool vskip_if_missing=false)
|
||||
{
|
||||
std::stringstream ss {};
|
||||
@@ -48,8 +48,8 @@ namespace latex {
|
||||
}
|
||||
|
||||
std::string default_cover(
|
||||
std::string title, std::string subtitle,
|
||||
std::string author, std::string date, std::string version)
|
||||
const std::string& title, const std::string& subtitle,
|
||||
const std::string& author, const std::string& date, const std::string& version)
|
||||
{
|
||||
std::string test = trim(title + subtitle + author + date + version);
|
||||
std::stringstream ss {};
|
||||
@@ -65,8 +65,8 @@ namespace latex {
|
||||
}
|
||||
|
||||
std::string nonbook_title(
|
||||
std::string title, std::string subtitle,
|
||||
std::string author, std::string date, std::string version)
|
||||
const std::string& title, const std::string& subtitle,
|
||||
const std::string& author, const std::string& date, const std::string& version)
|
||||
{
|
||||
std::string test = trim(title + subtitle + author + date + version);
|
||||
std::stringstream ss {};
|
||||
@@ -86,7 +86,7 @@ namespace latex {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string pagenumber(int n, std::string style="arabic")
|
||||
std::string pagenumber(int n, const std::string& style="arabic")
|
||||
{
|
||||
(void)K::log(3);
|
||||
std::stringstream ss {};
|
||||
@@ -94,7 +94,7 @@ namespace latex {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string book_verso_page(std::string copyright)
|
||||
std::string book_verso_page(const std::string& copyright)
|
||||
{
|
||||
(void)K::log(3);
|
||||
std::stringstream ss {};
|
||||
@@ -111,7 +111,7 @@ namespace latex {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string font_command(std::string command, const Resolved_font& font, float scale)
|
||||
std::string font_command(const std::string& command, const Resolved_font& font, float scale)
|
||||
{
|
||||
std::stringstream ss {};
|
||||
if (font.family_name.empty())
|
||||
@@ -150,23 +150,23 @@ namespace latex {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string page(std::string structure,
|
||||
std::string title,
|
||||
std::string subtitle,
|
||||
std::string authors,
|
||||
std::string date,
|
||||
std::string version,
|
||||
std::string copyright,
|
||||
std::string bottom,
|
||||
std::string prolog,
|
||||
std::string paper_size,
|
||||
std::string page(const std::string& structure,
|
||||
const std::string& title,
|
||||
const std::string& subtitle,
|
||||
const std::string& authors,
|
||||
const std::string& date,
|
||||
const std::string& version,
|
||||
const std::string& copyright,
|
||||
const std::string& bottom,
|
||||
const std::string& prolog,
|
||||
const std::string& paper_size,
|
||||
bool two_column,
|
||||
float leading,
|
||||
int pointsize,
|
||||
bool ragged_right,
|
||||
std::string cover,
|
||||
const std::string& cover,
|
||||
bool landscape,
|
||||
std::string body,
|
||||
const std::string& body,
|
||||
Resolved_font serif_font,
|
||||
Resolved_font sans_font,
|
||||
Resolved_font mono_font,
|
||||
|
||||
@@ -6,23 +6,23 @@
|
||||
|
||||
namespace latex {
|
||||
|
||||
std::string page(std::string structure,
|
||||
std::string title,
|
||||
std::string subtitle,
|
||||
std::string authors,
|
||||
std::string date,
|
||||
std::string version,
|
||||
std::string copyright,
|
||||
std::string bottom,
|
||||
std::string prolog,
|
||||
std::string paper_size,
|
||||
std::string page(const std::string& structure,
|
||||
const std::string& title,
|
||||
const std::string& subtitle,
|
||||
const std::string& authors,
|
||||
const std::string& date,
|
||||
const std::string& version,
|
||||
const std::string& copyright,
|
||||
const std::string& bottom,
|
||||
const std::string& prolog,
|
||||
const std::string& paper_size,
|
||||
bool two_column,
|
||||
float leading,
|
||||
int pointsize,
|
||||
bool ragged_right,
|
||||
std::string cover,
|
||||
const std::string& cover,
|
||||
bool landscape,
|
||||
std::string body,
|
||||
const std::string& body,
|
||||
Resolved_font serif_font = {},
|
||||
Resolved_font sans_font = {},
|
||||
Resolved_font mono_font = {},
|
||||
|
||||
@@ -3,7 +3,7 @@ The targets in the SKS use the LaTeX convention for converting ASCII
|
||||
characters into standard typographical characters. This is done
|
||||
by LaTeX by default; other targets must use the transforms parameter
|
||||
of Parameter_set, as defined for the m_parameters variable of the
|
||||
Target_set class. (See file target_set.cpp.)
|
||||
Target_registry class. (See file target_registry.cpp.)
|
||||
|
||||
The LaTeX transformations supported by the SKS are:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user