Branch: refs/heads/master Author: Frank Lanitz frank@frank.uvena.de Committer: Frank Lanitz frank@frank.uvena.de Date: Mon, 20 Oct 2014 18:24:58 UTC Commit: db67897fa1daf89fa728d5db25c6f11de32e829e https://github.com/geany/geany-plugins/commit/db67897fa1daf89fa728d5db25c6f1...
Log Message: ----------- TableConvert: Adding DokuWiki as first non-Geany filetype for TableConvert and clean logic up so it should support also other wiki syntaxes in future
Modified Paths: -------------- tableconvert/src/tableconvert.c tableconvert/src/tableconvert.h
Modified: tableconvert/src/tableconvert.c 196 lines changed, 123 insertions(+), 73 deletions(-) =================================================================== @@ -39,70 +39,94 @@ GeanyFunctions *geany_functions; TableConvertRule tablerules[] = { /* LaTeX */ { - N_("LaTeX"), - "\begin{table}[h]\n\begin{tabular}{}\n", - "", - "", - "", - "", - " & ", - "\t", - "\\", - "", - "\end{tabular}\n\end{table}" + N_("LaTeX"), /* type */ + "\begin{table}[h]\n\begin{tabular}{}\n", /* start */ + "\t", /* header_start */ + "", /* header_stop */ + " & ", /* header_columnsplit */ + "", /* header_linestart */ + "\\ \hline", /* header_lineend */ + "", /* body_start */ + "", /* body_end */ + " & ", /* columnsplit */ + "\t", /* linestart */ + "\\", /* lineend */ + "", /* linesplit */ + "\end{tabular}\n\end{table}" /* end */ }, /* HTML */ { - N_("HTML"), - "<table>\n", - "<thead>\n", - "</thead>\n", - "<tbody>\n", - "\n</tbody>", - "</td>\n\t<td>", - "<tr>\n\t<td>", - "</td>\n</tr>", - "", - "\n</table>" + N_("HTML"), /* type */ + "<table>\n", /* start */ + "<thead>\n", /* header_start */ + "</thead>\n", /* header_stop */ + "</td>\n\t<td>", /* header_columnsplit */ + "<tr>\n\t<td>", /* header_linestart */ + "</td>\n</tr>\n", /* header_lineend */ + "<tbody>\n", /* body_start */ + "\n</tbody>", /* body_end */ + "</td>\n\t<td>", /* columnsplit */ + "<tr>\n\t<td>", /* linestart */ + "</td>\n</tr>", /* lineend */ + "", /* linesplit */ + "\n</table>" /* end */ }, /* SQL */ + /* Header not yet supported, so treated as normal + * "Body"-SQL. This is handled on function logic + * */ { - N_("SQL"), - "", - "", - "", - "", - "", - "','", - "\t('", - "')", - ",", - ";" - } + N_("SQL"), /* type */ + "", /* start */ + "", /* header_start */ + "", /* header_stop */ + "", /* header_columnsplit */ + "", /* header_linestart */ + "", /* header_lineend */ + "", /* body_start */ + "", /* body_end */ + "','", /* columnsplit */ + "\t('", /* linestart */ + "')", /* lineend */ + ",", /* linesplit */ + ";" /* end */ + }, + /* DokuWiki */ + { + N_("DokuWiki"), /* type */ + "", /* start */ + "", /* header_start */ + "", /* header_stop */ + " ^ ", /* header_columnsplit */ + "^ ", /* header_linestart */ + " ^", /* header_lineend */ + "", /* body_start */ + "", /* body_end */ + " | ", /* columnsplit */ + "| ", /* linestart */ + " |", /* lineend */ + "", /* linesplit */ + "", /* end */ + } };
static gchar* convert_to_table_worker(gchar **rows, gboolean header, - const TableConvertRule *rule) + gint file_type) { guint i; guint j; GString *replacement_str = NULL; GeanyDocument *doc = NULL; + TableConvertRule *rule = &tablerules[file_type]; doc = document_get_current();
g_return_val_if_fail(rows != NULL, NULL); + g_return_if_fail(rule != NULL);
/* Adding start of table to replacement */ replacement_str = g_string_new(rule->start);
- /* Adding special header if requested - * e.g. <thead> */ - if (header == TRUE) - { - g_string_append(replacement_str, rule->header_start); - } - /* Iteration onto rows and building up lines of table for * replacement */ for (i = 0; rows[i] != NULL; i++) @@ -110,46 +134,67 @@ static gchar* convert_to_table_worker(gchar **rows, gboolean header, gchar **columns = NULL; columns = g_strsplit_set(rows[i], "\t", -1);
- if (i == 1 && + /* Putting in some header if needed */ + if (i == 0 && header == TRUE) { - g_string_append(replacement_str, rule->header_stop); - /* We are assuming, that if someone inserts a head, - * only in this case we will insert some special body. - * Might needs to be discussed further */ - g_string_append(replacement_str, rule->body_start); - } + /* header_start */ + g_string_append(replacement_str, rule->header_start);
- g_string_append(replacement_str, rule->linestart); + /* header_linestart */ + g_string_append(replacement_str, rule->header_linestart);
- for (j = 0; columns[j] != NULL; j++) - { - if (j > 0) + /* header_columnsplit + columncontent */ + for (j = 0; columns[j] != NULL; j++) { - g_string_append(replacement_str, rule->columnsplit); + if (j > 0) + { + g_string_append(replacement_str, rule->header_columnsplit); + } + g_string_append(replacement_str, columns[j]); } - g_string_append(replacement_str, columns[j]); - }
- if (utils_str_equal(rule->lineend, "")) - { + /* header_lineend */ + g_string_append(replacement_str, rule->header_lineend); + + /* header_stop */ + g_string_append(replacement_str, rule->header_stop); + + /* Adding a new line of header assuming it's something + * relevant for every typ */ g_string_append(replacement_str, editor_get_eol_char(doc->editor)); + + /* body_start */ + /* Only insert explicit body start if there is a header */ + g_string_append(replacement_str, rule->body_start); } - else + if (i > 0 || + header == FALSE) { - g_string_append(replacement_str, rule->lineend); - if (doc->file_type->id == GEANY_FILETYPES_SQL || - doc->file_type->id == GEANY_FILETYPES_LATEX) + /* linestart */ + g_string_append(replacement_str, rule->linestart); + + /* columnsplit + column */ + for (j = 0; columns[j] != NULL; j++) { - g_string_append(replacement_str, editor_get_eol_char(doc->editor)); + if (j > 0) + { + g_string_append(replacement_str, rule->columnsplit); + } + g_string_append(replacement_str, columns[j]); } - }
- if (rows[i+1] != NULL) - { - g_string_append(replacement_str, rule->linesplit); + /* lineend */ + g_string_append(replacement_str, rule->lineend); + + /* linesplit */ + if (rows[i+1] != NULL && utils_str_equal(rule->linesplit, "")) + { + g_string_append(replacement_str, rule->linesplit); + } + g_string_append(replacement_str, editor_get_eol_char(doc->editor)); + g_strfreev(columns); } - g_strfreev(columns); }
if (header == TRUE) @@ -163,6 +208,7 @@ static gchar* convert_to_table_worker(gchar **rows, gboolean header, return g_string_free(replacement_str, FALSE); }
+ void convert_to_table(gboolean header, gint file_type) { GeanyDocument *doc = NULL; @@ -207,22 +253,22 @@ void convert_to_table(gboolean header, gint file_type) { replacement = convert_to_table_worker(rows, header, - &tablerules[TC_HTML]); + TC_HTML); break; } case GEANY_FILETYPES_LATEX: { replacement = convert_to_table_worker(rows, header, - &tablerules[TC_LATEX]); + TC_LATEX); break; } case GEANY_FILETYPES_SQL: { /* TODO: Check for INTEGER and other datatypes on SQL */ replacement = convert_to_table_worker(rows, - header, - &tablerules[TC_SQL]); + FALSE, + TC_SQL); break; } default: @@ -233,9 +279,13 @@ void convert_to_table(gboolean header, gint file_type) } else { + if (file_type == TC_SQL) + { + header = FALSE; + } replacement = convert_to_table_worker(rows, header, - &tablerules[file_type]); + file_type); }
}
Modified: tableconvert/src/tableconvert.h 4 lines changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -45,6 +45,9 @@ typedef struct { const gchar *start; const gchar *header_start; const gchar *header_stop; + const gchar *header_columnsplit; + const gchar *header_linestart; + const gchar *header_lineend; const gchar *body_start; const gchar *body_end; const gchar *columnsplit; @@ -60,6 +63,7 @@ enum { TC_LATEX = 0, TC_HTML, TC_SQL, + TC_DOKUWIKI, TC_END };
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).