чување 22a149d7835297f193d0442c0d9890e61e25f9e2
родитељ 383adb0e3d58423c7e24aa0733920f9088f04417
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Wed, 24 Mar 2021 22:33:13 +0100
Fixing spacing in output
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | slw2gmi.c | | | 92 | +++++++++++++++++++++++-------------------------------------------------------- |
измењених датотека: 1, додавања: 26(+), брисања: 66(-)
diff --git a/slw2gmi.c b/slw2gmi.c
@@ -410,10 +410,13 @@ int
read_csv(FILE* output, const char* filename, csv_callback_t callback);
int
-process_heading_start(FILE* output, UBYTE heading_level)
+process_heading_start(FILE* output, UBYTE heading_level,
+ BOOL first_line_in_doc, BOOL previous_line_blank)
{
if (!output_firstcol)
print_output(output, "\n");
+ if (!previous_line_blank && !first_line_in_doc)
+ print_output(output, "\n");
for (size_t i = 0; i < heading_level; i++)
print_output(output, "#");
print_output(output, " ");
@@ -427,7 +430,7 @@ process_heading(const uint8_t* token, FILE* output)
if (!token || u8_strlen(token) < 1)
warning(1, (uint8_t*)"Empty heading");
- print_output(output, "%s\n", token ? (char*)token : "");
+ print_output(output, "%s\n\n", token ? (char*)token : "");
output_firstcol = TRUE;
return 0;
@@ -1019,10 +1022,6 @@ int
process_incdir_subdir(const char* subdirname, const uint8_t* link_prefix,
FILE* output, BOOL details_open, uint8_t* macro_body)
{
- /*
- *print_output(output, "%s\n", subdirname);
- */
-
struct dirent** namelist;
struct dirent** pnamelist;
long names_total = 0;
@@ -1049,7 +1048,6 @@ process_incdir_subdir(const char* subdirname, const uint8_t* link_prefix,
char* link = NULL;
CALLOC(link, char, BUFSIZE)
- //print_output(output, "\n=> %s/%s.gmi\t", subdirname, basename);
snprintf(link, BUFSIZE, "%s/%s", subdirname, basename);
fflush(output);
@@ -1063,10 +1061,6 @@ process_incdir_subdir(const char* subdirname, const uint8_t* link_prefix,
snprintf(input_filename, BUFSIZE, "%s/%s", abs_subdirname,
(*pnamelist)->d_name);
- /*
- *print_output(output, "\n=> %s/%s.gmi\t%s", subdirname,
- * basename, subdirname);
- */
FILE* input = NULL;
FILE* output = stdout;
uint8_t* buffer = NULL;
@@ -1596,11 +1590,6 @@ int
process_inline_link(uint8_t* link_text, uint8_t* link_macro_body,
uint8_t* link_url, FILE* output)
{
- /*
- *print_output(output, "\n\n=> %s\t%s\n\n", link_url ? (char*)link_url : "",
- * link_text);
- */
-
print_output(output, "%s", link_text);
if (*link_text)
output_firstcol = FALSE;
@@ -1620,11 +1609,6 @@ int
process_inline_image(uint8_t* image_text, uint8_t* image_url, FILE* output,
BOOL add_link, BOOL add_figcaption)
{
- /*
- *print_output(output, "\n\n=> %s\t%s\n\n",
- * image_url ? (char*)image_url : "",
- * image_text);
- */
print_output(output, "%s ", image_text);
if (*image_text)
output_firstcol = FALSE;
@@ -1644,12 +1628,14 @@ int
process_paralinks(const uint8_t* link_prefix, FILE* output)
{
KeyValue* pparalink = paralinks;
+ if (!output_firstcol && (paralinks_count > 0))
+ print_output(output, "\n");
+ print_output(output, "\n");
while (pparalink < paralinks + paralinks_count)
{
if (pparalink->key)
{
- print_output(output, "%s=> %s%s\t%s\n",
- output_firstcol ? "" : "\n",
+ print_output(output, "=> %s%s\t%s\n",
url_is_local((const char*)pparalink->key) && link_prefix
? (const char*)link_prefix : "",
pparalink->key, pparalink->value);
@@ -1658,10 +1644,7 @@ process_paralinks(const uint8_t* link_prefix, FILE* output)
pparalink++;
}
if (paralinks_count > 0)
- {
print_output(output, "\n");
- output_firstcol = TRUE;
- }
free_keyvalue(¶links, paralinks_count);
free(paralinks);
@@ -1721,7 +1704,7 @@ process_line_start(uint8_t* line, const uint8_t* link_prefix,
{
if (!read_yaml_macros_and_links)
print_output(output, "%s",
- output_firstcol && !previous_line_blank ? "" : "\n");
+ output_firstcol && previous_line_blank ? "" : "\n");
output_firstcol = TRUE;
state |= ST_PARA_OPEN;
}
@@ -1842,11 +1825,13 @@ int
begin_article(FILE* output, const BOOL add_article_header,
const uint8_t* author, const uint8_t* title,
const uint8_t* header_text, const char* title_heading_level,
- uint8_t* date, const BOOL ext_in_permalink, const char* permalink_url)
+ uint8_t* date, const BOOL ext_in_permalink, BOOL first_line_in_doc,
+ BOOL* previous_line_blank, const char* permalink_url)
{
if (title)
{
- process_heading_start(output, 1);
+ process_heading_start(output, 1, first_line_in_doc,
+ *previous_line_blank);
process_heading(title, output);
}
@@ -1859,40 +1844,18 @@ begin_article(FILE* output, const BOOL add_article_header,
if (date && input_filename)
{
char* link = strip_ext(input_filename);
- /*
- *uint8_t* samedir_permalink = get_value(vars, vars_count,
- * (uint8_t*)"samedir-permalink", NULL);
- */
char* real_link = NULL;
- /*
- *uint8_t* permalink_macro = get_value(macros, macros_count,
- * (uint8_t*)"permalink", NULL);
- */
CALLOC(real_link, char, BUFSIZE)
if (ext_in_permalink)
strncat(link, timestamp_output_ext, BUFSIZE-strlen(link)-1);
- /*
- *if (permalink_url)
- * process_timestamp(output, permalink_url, permalink_macro, date,
- * NULL);
- *else //if (samedir_permalink && !u8_strcmp(samedir_permalink, (uint8_t*)"1"))
- *{
- * get_realpath(&real_link, input_dirname, link);
- * process_timestamp(output, real_link, permalink_macro, date, NULL);
- *}
- */
- /*
- *else
- * process_timestamp(output, link, permalink_macro, date);
- */
-
free(real_link);
free(link);
}
output_firstcol = author || date || header_text || title;
+ *previous_line_blank = author || header_text || title ;
return 0;
}
@@ -2019,7 +1982,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
var_add_article_header && *var_add_article_header == '1',
author, title, header_text, (char*)title_heading_level, date,
ext_in_permalink && *ext_in_permalink != '0',
- (char*)permalink_url);
+ first_line_in_doc, &previous_line_blank, (char*)permalink_url);
RESET_TOKEN(token, ptoken, token_size)
@@ -2186,7 +2149,8 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
if (!read_yaml_macros_and_links)
{
- print_output(output, "```%s", (state & ST_PRE) ? "" : "\n");
+ print_output(output, "```%s", (state & ST_PRE) ? "" : "\n\n");
+ output_firstcol = TRUE;
output_firstcol = !(state & ST_PRE);
}
@@ -2530,7 +2494,8 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
if ((state & ST_HEADING) && !(state & ST_HEADING_TEXT))
{
if (!read_yaml_macros_and_links)
- process_heading_start(output, heading_level);
+ process_heading_start(output, heading_level,
+ first_line_in_doc, previous_line_blank);
state |= ST_HEADING_TEXT;
pline++;
colno++;
@@ -3167,7 +3132,6 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
pparalinks->value_size = u8_strlen(link_text)+1;
pparalinks->value = u8_strdup(link_text);
- line_len = u8_strlen(line);
if (output_firstcol
&& ((*(line+line_len-1) == ']')
|| *(line+line_len-1) == ')'))
@@ -3267,7 +3231,6 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
pparalinks->value_size = u8_strlen(link_text)+1;
pparalinks->value = u8_strdup(link_text);
- line_len = u8_strlen(line);
if (output_firstcol
&& ((*(line+line_len-1) == ']')
|| *(line+line_len-1) == ')'))
@@ -3304,7 +3267,6 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
pparalinks->value_size = u8_strlen(link_text)+1;
pparalinks->value = u8_strdup(link_text);
- line_len = u8_strlen(line);
if (output_firstcol
&& ((*(line+line_len-1) == ']')
|| *(line+line_len-1) == ')'))
@@ -3740,7 +3702,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
{
if (!read_yaml_macros_and_links)
{
- print_output(output, "%s\n",
+ print_output(output, "%s",
((line_len == 0) || previous_line_blank)
&& output_firstcol
? "" : "\n");
@@ -3828,13 +3790,9 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
process_table_end(output);
state &= ~ST_TABLE;
}
-
- previous_line_blank = FALSE;
}
if (!skip_eol && !keep_token && !read_yaml_macros_and_links
- /*&& line_len > 0*/
- /*&& !output_firstcol*/
&& !ANY(state, ST_YAML | ST_YAML_VAL | ST_LINK_SECOND_ARG
| ST_LINK_SECOND_ARG_END))
{
@@ -3851,12 +3809,14 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
first_line_in_doc = FALSE;
skip_change_first_line_in_doc = FALSE;
- if (line_len == 0)
+ if (!previous_line_blank && (line_len == 0))
{
- process_paralinks(link_prefix, output);
- output_firstcol = TRUE;
previous_line_blank = TRUE;
+ if (!read_yaml_macros_and_links)
+ print_output(output, "\n");
}
+ else
+ previous_line_blank = TRUE;
/* Lasts until the end of line */
state &= ~(ST_YAML_VAL | ST_IMAGE_SECOND_ARG | ST_LINK_SECOND_ARG