slweb

Једноставни генератор статичких веб страна
git clone https://git.sr.ht/~strahinja/slweb
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување e583adf3ce7c4dba70fea7bb2a95bf15abca2a68
родитељ e96e4c18ba5ebec60ca19e3d99e3ca03f2ed9d15
Аутор: Страхиња Радић <sr@strahinja.org>
Датум:   Mon, 22 Jul 2024 21:01:40 +0200

Add ~!; bugfix: footnote value copied at token_len instead of value_len

Diffstat:
Mslweb.1.in | 18++++++++++++++++--
Mslweb.c | 57++++++++++++++++++++++++++++++++++++++++++++++-----------
измењених датотека: 2, додавања: 62(+), брисања: 13(-)

diff --git a/slweb.1.in b/slweb.1.in @@ -28,7 +28,9 @@ tag, skipping and .Ql <head> . .It Fl d Ar directory , Fl \-basedir Ar directory -Set the base directory for includes +Set the base directory for image file paths to pass to +.Xr identify 1 , +includes .Pf "(" Ql {include} and .Ql {incdir} ) @@ -588,6 +590,14 @@ separating header from body is ignored by the parser and is included in this example only for aesthetic purposes. See .Sx TSV/CSV templating . +.It +.Tg Zero_width_space +.Sy Zero width space . +Tilde followed by an exclamation mark +.Pf "(" Ql "~!" ) +will produce +.Ql &#8203;\& +in the output. .El . .Ss Math mode @@ -1139,7 +1149,11 @@ added as necessary, when determining the actual file path to pass to the command. Otherwise, .Cm src -is appended to +is appended to the base directory, specified by the parameter +.Fl d +(or +.Fl \-basedir Ns ), +and defaulting to .Dq .\& . .It .Va incdir-footer-permalink-text . diff --git a/slweb.c b/slweb.c @@ -321,6 +321,7 @@ end_body_and_html(FILE* output) static int end_footnotes(FILE* output, int add_footnote_div) { + KeyValue* pfootnote; size_t footnote = 0; CLEAR(state, ST_PARA_OPEN); @@ -344,7 +345,7 @@ end_footnotes(FILE* output, int add_footnote_div) output_firstcol = 1; } - KeyValue* pfootnote = footnotes; + pfootnote = footnotes; footnote = 0; while (pfootnote && footnote < footnote_count) { @@ -797,15 +798,18 @@ print_image_dimensions(FILE* output, const u8* image_file_prefix, const u8* path char image_path[BUFSIZE - strlen(CMD_IDENTIFY)]; char* eol = NULL; - assert((output != NULL) && (path != NULL)); + assert((output != NULL) && (path != NULL) && (basedir != NULL)); if (!*path) return 1; snprintf(image_path, BUFSIZE - strlen(CMD_IDENTIFY) - 1, "%s%s%s", - image_file_prefix ? (char*)image_file_prefix : ".", + image_file_prefix ? (char*)image_file_prefix : basedir, *path == '/' ? "" : "/", path); errno = 0; if (stat(image_path, &sb) < 0) + { + perror(PROGRAMNAME ": stat"); return 1; + } snprintf(command, BUFSIZE - 1, CMD_IDENTIFY, image_path); cmd_output = popen(command, "r"); if (!cmd_output) @@ -1176,18 +1180,19 @@ process_footnote(FILE* output, const u8* token, const int footnote_definition, current_footnote++; if (footnote_definition) { - footnote_count++; if (footnote_count == 1 && inline_footnote_count > 0) warning(1, (u8*)"Both inline and regular footnotes " "present"); else if (!footnotes) { + footnote_count = 1; CALLOC(footnotes, KeyValue, footnote_count); pfootnotes = footnotes; } else { + footnote_count++; REALLOCARRAY(footnotes, KeyValue, footnote_count); pfootnotes = footnotes + footnote_count - 1; } @@ -1774,7 +1779,6 @@ process_inline_footnote(const u8* token, const int read_yaml_macros_and_links, if (read_yaml_macros_and_links) { token_len = strlen((char*)token); - inline_footnote_count++; if (inline_footnote_count == 1 && footnote_count > 0) warning(1, (u8*)"Both inline and regular footnotes " @@ -1785,8 +1789,11 @@ process_inline_footnote(const u8* token, const int read_yaml_macros_and_links, CALLOC(inline_footnotes, u8*, inline_footnote_count); } else + { + inline_footnote_count++; REALLOC(inline_footnotes, u8*, sizeof(u8*) * inline_footnote_count); + } CALLOC(inline_footnotes[inline_footnote_count - 1], u8, token_len + 1); MEMCCPY(inline_footnotes[inline_footnote_count - 1], @@ -3286,6 +3293,36 @@ do_line: pline += 2; colno += 2; } + else if (strlen((char*)pline) > 1 && *(pline + 1) == '!') + { + u8* entity = (u8*)"&#8203;"; + entity_len = strlen((char*)entity); + /* Handle ~! within footnotes, headings and link + * text specially */ + if (ANY(state, + ST_INLINE_FOOTNOTE | ST_HEADING + | ST_FOOTNOTE_TEXT | ST_LINK)) + APPEND_TOKEN(entity, entity_len); + else + { + /* Output existing text up to ~! */ + process_text_token(output, line, link_prefix, + first_line_in_doc, previous_line_blank, + &previous_line_block, + processed_start_of_line, + read_yaml_macros_and_links, list_para, + &token, &ptoken, &token_size, 1, 1); + processed_start_of_line = 1; + + if (!read_yaml_macros_and_links + && !(ANY(state, + ST_PRE | ST_CODE | ST_HEADING))) + print_output(output, (char*)entity); + } + + pline += 2; + colno += 2; + } else if (strlen((char*)pline) > 1 && *(pline + 1) == '-') { u8* entity = (u8*)"&#8209;"; @@ -3298,7 +3335,7 @@ do_line: APPEND_TOKEN(entity, entity_len); else { - /* Output existing text up to ~~ */ + /* Output existing text up to ~- */ process_text_token(output, line, link_prefix, first_line_in_doc, previous_line_blank, &previous_line_block, @@ -4908,7 +4945,6 @@ done_line: { size_t value_len = strlen( (char*)pfootnotes->value); - if (pfootnotes->value_size < value_len + token_len + 1) { @@ -5047,7 +5083,6 @@ done_line: { size_t value_len = strlen( (char*)pfootnotes->value); - if (pfootnotes->value_size < value_len + token_len + 1) { @@ -5057,10 +5092,10 @@ done_line: REALLOC(pfootnotes->value, u8, pfootnotes->value_size); } - MEMCCPY((pfootnotes->value + token_len), + MEMCCPY((pfootnotes->value + value_len), token, pfootnotes->value_size - - token_len, + - value_len, temp); } else @@ -5142,7 +5177,7 @@ done_line: done_buffer: if (!read_yaml_macros_and_links) { - if (footnote_count > 0 || inline_footnote_count > 0) + if ((footnote_count > 0) || (inline_footnote_count > 0)) end_footnotes(output, add_footnote_div); if (madeby_present)