slweb

Једноставни генератор статичких веб страна
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 40c661409fc910f463cfe2a9f42083ae3351b0e5
родитељ c9c948c73930edd78098fb4b441978b119c7e582
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Mon, 11 Jan 2021 15:40:39 +0100

WIP csv directive (database-like support)

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
MTODO | 10++++++++++
Mdefs.h | 1+
Mindex.html | 2+-
Mslweb.1.in | 31++++++++++++-------------------
Mslweb.c | 37+++++++++++++++++++++++++++++++++++++
измењених датотека: 5, додавања: 61(+), брисања: 20(-)

diff --git a/TODO b/TODO @@ -3,3 +3,13 @@ [ ] Add csv templating directive + [ ] Move fprintf(output...) to a separate function + + [ ] Record that function's output rom {csv}..{/csv} into + "capture blocks" - no need to do that for all of them, + only the last one + + [ ] Open CSV, for each row in CSV skipping the first one + output the current capture block substituting the variable + escapes $1..$9 (keeping it simple with 1-digit) with row fields + diff --git a/defs.h b/defs.h @@ -94,6 +94,7 @@ const ULONG ST_LINK_MACRO = 1 << 13; const ULONG ST_IMAGE = 1 << 14; const ULONG ST_IMAGE_SECOND_ARG = 1 << 15; const ULONG ST_MACRO_BODY = 1 << 16; +const ULONG ST_CSV_BODY = 1 << 17; #pragma GCC diagnostic pop #endif /* __DEFS_H */ diff --git a/index.html b/index.html @@ -128,7 +128,7 @@ this program. If not, see &lt;<a href="https://www.gnu.org/licenses">https://www <div id="git-log"> Previous commit: -index.slw 5db4380 2021-01-06 22:59:54 +0100 (Страхиња Радић) (HEAD -> master) +index.slw c9c948c 2021-01-10 22:49:16 +0100 (Страхиња Радић) (HEAD -> master, origin/master, origin/HEAD) </div><!--git-log--> diff --git a/slweb.1.in b/slweb.1.in @@ -88,9 +88,10 @@ Print program version and exit. .LP Files processed by .B slweb -are using a minimal subset of Markdown with added directives. Supported -.B "Markdown features" -are: +are using a minimal subset of Markdown with added directives. +. +.SS Supported Markdown features +. .IP \[bu] 4 .BR Paragraphs . Text surrounded by newlines will be put inside \fC<p></p>\fR tags. @@ -122,7 +123,7 @@ Multiple lines are supported. .BR Links . The construct \fC[A link](https://example.com)\fR will be converted into \fC<a href="https://example.com">A link</a>\fR. - +.IP Special case is the form \fC[=somemacro Link title](https://anything)\fR which prepends the body of a macro .I somemacro @@ -132,21 +133,24 @@ into the \fC<a></a>\fR tag (here broken into multiple lines for clarity): <!-- contents of somemacro --> Link title</a> .CDE +.IP This can, for example, be used to add .SM SVG icons to links. See .BR Macros . - +.IP Also, the form \fC[(Link title)](http://asite.com)\fR will surround the link title (text between \fC<a></a>\fR tags) with \fC<span></span>\fR, like so: .CDS 4 <a href="http://asite.com"><span>Link title</span></a> .CDE +.IP This allows for separate styling of link text. It can be combined with the macro-form: .CDS 4 [=somemacro (Link title)](http://asite.com) .CDE +.IP It will prepend the body of a macro .I somemacro outside of the \fC<span></span>\fR: @@ -160,8 +164,7 @@ outside of the \fC<span></span>\fR: .BR "Line breaks" . Two spaces followed by a newline will become \fC<br />\fR. . -.PP -.BR "Directives " include: +.SS Directives . .IP \[bu] 4 .BR "General tags" . @@ -275,13 +278,7 @@ containing the \[lq]watermark\[rq] text and a link to the .B slweb home page. . -.PP -.B Special -.SM \fBYAML -.B variables -recognized by -.B slweb -are: +.SS Special YAML variables . .IP \[bu] 4 .BR date . @@ -372,11 +369,7 @@ to 2. (\fCtitle: Some title\fR becomes \fC<h2>Some title</h2>\fR). See .BR title . . -.PP -.B Special macros -recognized by -.B slweb -are: +.SS Special macros . .IP \[bu] 4 .BR permalink . diff --git a/slweb.c b/slweb.c @@ -278,6 +278,39 @@ process_git_log(FILE* output) } int +process_csv(uint8_t* token, FILE* output, ULONG* state, + BOOL read_yaml_macros_and_links, BOOL end_tag) +{ + if (read_yaml_macros_and_links) + return 0; + + if (end_tag) + { + *state &= ~ST_CSV_BODY; + /* + *fprintf(stderr, "%ld:%ld:csv: /end\n", lineno, colno); + */ + } + else + { + *state |= ST_CSV_BODY; + uint8_t* saveptr = NULL; + uint8_t* args = u8_strtok(token, (uint8_t*)" ", &saveptr); + args = u8_strtok(NULL, (uint8_t*)" ", &saveptr); + /* + *if (args) + *{ + * fprintf(stderr, "%ld:%ld:csv: args=[%s]\n", + * lineno, colno, + * args); + *} + */ + } + + return 0; +} + +int process_include(uint8_t* token, FILE* output, ULONG* state, KeyValue** vars, size_t* vars_count, KeyValue** macros, size_t* macros_count, @@ -680,6 +713,10 @@ process_tag(uint8_t* token, FILE* output, KeyValue** macros, "</div><!--made-by-->\n", COPYRIGHTYEAR); } + else if (startswith((char*)token, "csv")) /* {csv} */ + { + process_csv(token, output, state, read_yaml_macros_and_links, end_tag); + } else if (startswith((char*)token, "include")) /* {include} */ { process_include(token, output, state, vars, vars_count,