aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sdp/meta
diff options
context:
space:
mode:
Diffstat (limited to 'src/sdp/meta')
-rw-r--r--src/sdp/meta/metadoc.d1
-rw-r--r--src/sdp/meta/metadoc_from_src.d60
-rw-r--r--src/sdp/meta/object_setter.d89
-rw-r--r--src/sdp/meta/rgx.d2
4 files changed, 101 insertions, 51 deletions
diff --git a/src/sdp/meta/metadoc.d b/src/sdp/meta/metadoc.d
index 37545f0..4aaafce 100644
--- a/src/sdp/meta/metadoc.d
+++ b/src/sdp/meta/metadoc.d
@@ -77,6 +77,7 @@ template SiSUabstraction() {
_header_body_insertfilelist_imagelist[headBody.body_content],
_make_and_meta_struct,
_opt_action,
+ _manifest,
);
static assert(!isTypeTuple!(da));
static assert(da.length==5);
diff --git a/src/sdp/meta/metadoc_from_src.d b/src/sdp/meta/metadoc_from_src.d
index b5fd5ab..8fb22be 100644
--- a/src/sdp/meta/metadoc_from_src.d
+++ b/src/sdp/meta/metadoc_from_src.d
@@ -234,12 +234,13 @@ template SiSUdocAbstraction() {
/+ node +/
ObjGenericComposite comp_obj_heading, comp_obj_location, comp_obj_block, comp_obj_code, comp_obj_poem_ocn, comp_obj_comment;
auto node_construct = NodeStructureMetadata();
- enum sObj { content, anchor_tags, notes_reg, notes_star, links }
+ enum sObj { content, anchor_tags, notes_reg, notes_star, links, image_no_dimensions }
/+ ↓ abstract marked up document +/
- auto SiSUdocAbstraction(Src,CMM,Opt)(
+ auto SiSUdocAbstraction(Src,CMM,Opt,Mfst)(
Src markup_sourcefile_content,
CMM conf_make_meta,
Opt opt_action,
+ Mfst manifest_matter,
) {
static auto rgx = Rgx();
debug(asserts) {
@@ -383,7 +384,7 @@ template SiSUdocAbstraction() {
writeln("substitution to make: ", conf_make_meta.make.italics[Substitute.markup]);
}
}
- /+ ↓ loop markup document/text line by line +/
+ /+ ↓ ↻ loop markup document/text line by line +/
srcDocLoop:
foreach (line; markup_sourcefile_content) {
// "line" variable can be empty but should never be null
@@ -970,6 +971,7 @@ template SiSUdocAbstraction() {
comp_obj_para.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg];
comp_obj_para.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star];
comp_obj_para.inline_links = substantive_obj_misc_tuple[sObj.links];
+ comp_obj_para.contains_image_without_dimensions = substantive_obj_misc_tuple[sObj.image_no_dimensions];
the_document_body_section ~= comp_obj_para;
_common_reset_(line_occur, an_object, obj_type_status);
indent=[
@@ -1421,6 +1423,40 @@ template SiSUdocAbstraction() {
return images_;
}
string[] segnames_0_4;
+ auto _image_dimensions(M,O)(M manifest_matter, O obj) {
+ if (obj.contains_image_without_dimensions) {
+ import std.math;
+ import imageformats;
+ int w, h, chans;
+ real _w, _h;
+ int max_width = 640;
+ foreach (m; obj.text.matchAll(rgx.inline_image_without_dimensions)) {
+ debug(images) {
+ writeln(manifest_matter.src.image_dir_path ~ "/" ~ m.captures["img"]);
+ }
+ read_image_info(manifest_matter.src.image_dir_path ~ "/" ~ m.captures["img"], w, h, chans);
+ // calculate, decide max width and proportionally reduce to keep w & h within it
+ debug(images) {
+ writeln("width: ", w, ", height: ", h);
+ }
+ if (w > max_width) {
+ _w = max_width;
+ _h = round((max_width / w.to!real) * h.to!real);
+ } else {
+ _w = w;
+ _h = h;
+ }
+ obj.text = obj.text.replaceFirst(
+ rgx.inline_image_without_dimensions,
+ ("$1☼$3,w" ~ _w.to!string ~ "h" ~ _h.to!string ~ " $6")
+ );
+ }
+ debug(images) {
+ writeln("image without dimensions: ", obj.text);
+ }
+ }
+ return obj;
+ }
foreach (ref obj; the_document_head_section) {
if (obj.is_a == "heading") {
debug(dom) {
@@ -1540,6 +1576,7 @@ template SiSUdocAbstraction() {
obj = obj_heading_ancestors(obj, lv_ancestors_txt);
} else if (obj.is_a == "para") {
_images ~= extract_images(obj.text);
+ obj = _image_dimensions(manifest_matter, obj);
}
}
}
@@ -1874,6 +1911,7 @@ template SiSUdocAbstraction() {
document_section_keys_sequenced["seg"] ~= "tail";
document_section_keys_sequenced["scroll"] ~= "tail";
}
+ auto sequenced_document_keys = docSectKeysSeq!()(document_section_keys_sequenced);
auto segnames = html_segnames.dup;
destroy(the_document_head_section);
destroy(the_table_of_contents_section);
@@ -1898,7 +1936,7 @@ template SiSUdocAbstraction() {
dom_collapsed_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,];
auto t = tuple(
document_the,
- docSectKeysSeq!()(document_section_keys_sequenced),
+ sequenced_document_keys,
segnames,
segnames_0_4,
images,
@@ -3980,6 +4018,7 @@ template SiSUdocAbstraction() {
body {
obj_txt_out = "";
bool urls = false;
+ bool images_without_dimensions = false;
tail = "";
/+ special endnotes +/
obj_txt_in = obj_txt_in.replaceAll(
@@ -3994,6 +4033,9 @@ template SiSUdocAbstraction() {
/+ image matched +/
if (obj_txt_in.match(rgx.smid_image_generic)) {
obj_txt_in = images(obj_txt_in);
+ if (obj_txt_in.match(rgx.smid_mod_image_without_dimensions)) {
+ images_without_dimensions = true;
+ }
}
/+ url matched +/
if (obj_txt_in.match(rgx.smid_inline_url)) {
@@ -4019,6 +4061,7 @@ template SiSUdocAbstraction() {
ftn[2],
ftn[3],
urls,
+ images_without_dimensions,
);
return t;
}
@@ -4179,9 +4222,10 @@ template SiSUdocAbstraction() {
static __gshared string[] anchor_tags_ = [];
auto x = munge.init;
bool[string] obj_notes_and_links;
- obj_notes_and_links["notes_reg"] = false;
- obj_notes_and_links["notes_star"] = false;
- obj_notes_and_links["links"] = false;
+ obj_notes_and_links["notes_reg"] = false;
+ obj_notes_and_links["notes_star"] = false;
+ obj_notes_and_links["links"] = false;
+ obj_notes_and_links["image_no_dimensions"] = false;
switch (obj_["is"]) {
case "heading":
static __gshared string anchor_tag = "";
@@ -4230,6 +4274,7 @@ template SiSUdocAbstraction() {
obj_notes_and_links["notes_star"] = x[2];
obj_notes_and_links["notes_plus"] = x[3];
obj_notes_and_links["links"] = x[4];
+ obj_notes_and_links["image_no_dimensions"] = x[5];
break;
}
auto t = tuple(
@@ -4238,6 +4283,7 @@ template SiSUdocAbstraction() {
obj_notes_and_links["notes_reg"],
obj_notes_and_links["notes_star"],
obj_notes_and_links["links"],
+ obj_notes_and_links["image_no_dimensions"],
);
anchor_tags_=[];
return t;
diff --git a/src/sdp/meta/object_setter.d b/src/sdp/meta/object_setter.d
index e4bb05f..380bab7 100644
--- a/src/sdp/meta/object_setter.d
+++ b/src/sdp/meta/object_setter.d
@@ -17,50 +17,51 @@ template ObjectSetter() {
}
struct ObjGenericComposite {
// size_t id;
- string of_part = "";
- string of_section = "";
- string is_of = "";
- string is_a = "";
- string text = "";
- string obj_cite_number = "";
- string obj_cite_number_off = "";
- string obj_cite_number_bkidx = "";
- int obj_cite_number_type = 0;
- string[] anchor_tags = [];
- int indent_base = 0;
- int indent_hang = 0;
- bool bullet = false;
- bool inline_links = false;
- bool inline_notes_reg = false;
- bool inline_notes_star = false;
- string language = ""; // not implemented, consider
- string code_block_syntax = "";
- int table_number_of_columns = 0;
- double[] table_column_widths = [];
- string[] table_column_aligns = [];
- bool table_heading = false;
- bool table_walls = false; // not implemented
- int ocn = 0;
- string segment_anchor_tag = "";
- string segname_prev = "";
- string segname_next = "";
- int parent_lev_markup = 0;
- int parent_ocn = 0;
- int[] ancestors = [];
- string marked_up_level = "9";
- int heading_lev_markup = 9;
- int heading_lev_collapsed = 9;
- int[] dom_markedup = [ 0, 0, 0, 0, 0, 0, 0, 0,];
- int[] dom_collapsed = [ 0, 0, 0, 0, 0, 0, 0, 0,];
- int[] heading_ancestors = [ 0, 0, 0, 0, 0, 0, 0, 0,];
- string[] heading_ancestors_text = [ "", "", "", "", "", "", "", "", ];
- string[] lev4_subtoc = [];
- int heading_array_ptr = 0;
- int ptr_doc_object = 0;
- int ptr_html_segnames = 0;
- int ptr_heading = 0;
- int array_ptr = 0;
- int heading_array_ptr_segments = 0;
+ string of_part = "";
+ string of_section = "";
+ string is_of = "";
+ string is_a = "";
+ string text = "";
+ string obj_cite_number = "";
+ string obj_cite_number_off = "";
+ string obj_cite_number_bkidx = "";
+ int obj_cite_number_type = 0;
+ string[] anchor_tags = [];
+ int indent_base = 0;
+ int indent_hang = 0;
+ bool bullet = false;
+ bool inline_links = false;
+ bool inline_notes_reg = false;
+ bool inline_notes_star = false;
+ bool contains_image_without_dimensions = false;
+ string language = ""; // not implemented, consider
+ string code_block_syntax = "";
+ int table_number_of_columns = 0;
+ double[] table_column_widths = [];
+ string[] table_column_aligns = [];
+ bool table_heading = false;
+ bool table_walls = false; // not implemented
+ int ocn = 0;
+ string segment_anchor_tag = "";
+ string segname_prev = "";
+ string segname_next = "";
+ int parent_lev_markup = 0;
+ int parent_ocn = 0;
+ int[] ancestors = [];
+ string marked_up_level = "9";
+ int heading_lev_markup = 9;
+ int heading_lev_collapsed = 9;
+ int[] dom_markedup = [ 0, 0, 0, 0, 0, 0, 0, 0,];
+ int[] dom_collapsed = [ 0, 0, 0, 0, 0, 0, 0, 0,];
+ int[] heading_ancestors = [ 0, 0, 0, 0, 0, 0, 0, 0,];
+ string[] heading_ancestors_text = [ "", "", "", "", "", "", "", "", ];
+ string[] lev4_subtoc = [];
+ int heading_array_ptr = 0;
+ int ptr_doc_object = 0;
+ int ptr_html_segnames = 0;
+ int ptr_heading = 0;
+ int array_ptr = 0;
+ int heading_array_ptr_segments = 0;
string[string][string] node;
}
struct TheObjects {
diff --git a/src/sdp/meta/rgx.d b/src/sdp/meta/rgx.d
index 8b6f4d2..869728f 100644
--- a/src/sdp/meta/rgx.d
+++ b/src/sdp/meta/rgx.d
@@ -153,6 +153,7 @@ static template SiSUrgxInit() {
static smid_image_generic = ctRegex!(`(?:^|[ ]|[^\S]?)\{(?:~\^\s+|\s*)\S+\.(?:png|gif|jpg).+?\}(?:image|(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)[;:!,?.]?(?:[ )\]]|$)`, "mg");
static smid_image_with_dimensions = ctRegex!(`(?P<pre>(?:^|[ ]|[^\S]?)\{(?:~\^\s+|\s*))(?P<image>\S+\.(?:png|gif|jpg))\s+(?P<width>\d+)x(?P<height>\d+)\s*(?P<post>(?:.+?)\s*\}(?:image|(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?:[;:!,?.]?(?:[ )\]]|$)))`, "mg");
static smid_image = ctRegex!(`(?P<pre>(?:^|[ ]|[^\S]?)\{(?:~\^\s+|\s*))(?P<image>\S+\.(?:png|gif|jpg))\s*(?P<post>(?:.+?)\s*\}(?:image|(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?:[;:!,?.]?(?:[ )\]]|$)))`, "mg");
+ static smid_mod_image_without_dimensions = ctRegex!(`\{(?:~\^\s+|\s*)☼\S+\.(?:png|gif|jpg),w0h0\s+(?:.+?)\s*\}(?:image|(?:https?|git):\/\/\S+?)(?:[;:!,?.]?(?:[ )\]]|$))`, "mg");
/+ inline markup book index +/
static book_index = ctRegex!(`^=\{\s*(.+?)\}$`, "m");
static book_index_open = ctRegex!(`^=\{\s*([^}]+?)$`);
@@ -248,6 +249,7 @@ static template SiSUrgxInit() {
static inline_text_and_note_al_ = ctRegex!(`(.+?(?:【[*+]*\s+.+?】|$))`, "mg");
/+ inline markup footnotes endnotes +/
static inline_image = ctRegex!(`(?P<pre>┥)☼(?P<imginf>(?P<img>\S+?\.(?:jpg|gif|png)),w(?P<width>\d+)h(?P<height>\d+))\s*(?P<post>.*?┝┤.+?├)`, "mg");
+ static inline_image_without_dimensions = ctRegex!(`(?P<pre>┥)☼(?P<imginf>(?P<img>\S+?\.(?:jpg|gif|png)),w(?P<width>0)h(?P<height>0))\s*(?P<post>.*?┝┤.+?├)`, "mg");
static inline_link = ctRegex!(`┥(?P<text>.+?)┝┤(?P<link>.+?)├`, "mg");
static inline_link_clean = ctRegex!(`┤(?:.+?)├|[┥┝]`, "mg");
static inline_a_url = ctRegex!(`(┤)(\S+?)(├)`, "mg");