чување e8066ca2307cc8e24f95138fb18ddc5f3f751f51
родитељ 339edd4f4c5ad03d924c6a2bd7ac0c8a28dfb7bf
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Mon, 14 Dec 2020 11:35:38 +0100
Added TODO; merging into master
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 9, додавања: 119(+), брисања: 42(-)
diff --git a/Makefile b/Makefile
@@ -1,11 +1,12 @@
SLWVERSION = v0.3.0
-SLWDATE = 10 Dec 2020
+SLWDATE = 14 Dec 2020
BINDIR = /usr/local/bin
MANDIR = /usr/local/share/man/man1
CFLAGS=-g
LIBS=-lunistring
BROWSER = surf
-EXAMPLE_PAGES = $(addsuffix /index.slw,examples/basic examples/includes examples/tags)
+EXAMPLE_PAGES = $(addsuffix /index.slw,examples/basic examples/includes \
+ examples/links examples/tags)
#EXAMPLE_PAGES += $(addprefix examples/includes,
EXAMPLE_PAGES_HTML = $(EXAMPLE_PAGES:.slw=.html)
diff --git a/README b/README
@@ -19,6 +19,10 @@ $ make && sudo make install
See the examples/ directory in this repository.
+NOTE: Since the migration to C, not all of the features of bash/sed-based slweb
+are yet ported, so not all of the examples work as intended. This is still a
+WIP, see the file TODO for more details.
+
License
-------
diff --git a/TODO b/TODO
@@ -0,0 +1,18 @@
+ TODO
+ ====
+
+Migration to C checklist
+------------------------
+
+ [ ] Add {=macro} parsing
+ [ ] Add [=command Link](link) form of links
+ [ ] Add [(Link)](link) form of links
+ [ ] Add {include} processing
+ [ ] Add {.class} processing
+ [ ] Add {#id} processing
+ [ ] Convert strncat token processing to individual token-based
+ [ ] Add {lsdir}
+ [ ] Add title: processing
+ [ ] Update manpage
+ [ ] Add backslash-escaping of blank lines for normal tags
+
diff --git a/examples/links/index.html b/examples/links/index.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<title>Links test</title>
+<meta charset="utf8" />
+<meta name="viewport" content="width=device-width, initial-scale=1" />
+<meta name="generator" content="slweb" />
+</head>
+<body>
+<p>Links <a href="https://strahinja.org">Test</a>.</p>
+<p>Another <a href="https://suckless.org">link, inline</a>.</p>
+
+</body>
+</html>
diff --git a/index.css b/index.css
@@ -14,7 +14,7 @@ code
code
{
- padding: .5em 1em;
+ padding: .5em 0;
}
pre
diff --git a/index.html b/index.html
@@ -68,6 +68,14 @@ $ slweb index.slw > index.html
</html>
</pre>
+<h2>TODO (checklist)</h2>
+<p>See the file <a href="https://github.com/Strahinja/slweb/tree/master/TODO"><code>TODO</code></a> for more information.</p>
+
+<h2>Bugs and limitations</h2>
+<p>Bugs can be reported using the <a href="https://github.com/Strahinja/slweb/issues">Github issue tracker</a>. See the manpage (<code>man
+
+slweb</code>) after installing <strong>slweb</strong> for more information.</p>
+
<h2>License</h2>
<p>slweb - Simple static website generator.<br />
@@ -86,7 +94,7 @@ PARTICULAR PURPOSE. See the GNU General Public License for more details. </p>
this program. If not, see <https://www.gnu.org/licenses/>. </p>
<div id="git-log">
Previous commit:
-index.slw a8aa201 2020-12-13 21:35:09 +0100 (Страхиња Радић) (HEAD -> switch-to-c)
+index.slw 339edd4 2020-12-13 21:35:33 +0100 (Страхиња Радић) (HEAD -> switch-to-c, origin/switch-to-c)
</div><!--git-log-->
<div id="made-by">
@@ -95,5 +103,8 @@ Generated by <a href="https://github.com/Strahinja/slweb">slweb</a>
</div><!--made-by-->
</main>
+
+
+
</body>
</html>
diff --git a/index.slw b/index.slw
@@ -19,7 +19,7 @@ $ make && sudo make install
## Examples
-See the [`examples/`](https://github.com/Strahinja/slweb/tree/master/examples) directory in this repository.
+See the [`examples/`][1] directory in this repository.
Given the file `index.slw` in the current directory:
@@ -66,6 +66,17 @@ file `index.html` contains:
</html>
```
+## TODO (checklist)
+
+See the file [`TODO`][2] for more information.
+
+
+## Bugs and limitations
+
+Bugs can be reported using the [Github issue tracker][3]. See the manpage (`man
+slweb`) after installing **slweb** for more information.
+
+
## License
slweb - Simple static website generator.
@@ -88,3 +99,7 @@ this program. If not, see <https://www.gnu.org/licenses/>.
{made-by}
{/main}
+[1]: https://github.com/Strahinja/slweb/tree/master/examples
+[2]: https://github.com/Strahinja/slweb/tree/master/TODO
+[3]: https://github.com/Strahinja/slweb/issues
+
diff --git a/slweb.1.in b/slweb.1.in
@@ -18,9 +18,8 @@ slweb Copyright \(co 2020 Strahinya Radich.
.
.SH DESCRIPTION
.B Slweb
-is a static website generator which aims at being simplistic. It uses
-.BR sed (1)
-to transform a custom Markdown-like syntax into
+is a static website generator which aims at being simplistic. It transforms
+custom Markdown-like syntax into
.SM HTML.
.
.SH OPTIONS
@@ -78,15 +77,15 @@ A line starting with \fC#\fR followed by space will be put inside
hashtags.
.
.IP \[bu]
-.BR "Bold/italic (limited)" .
+.BR Bold/italic .
Text inside \fC*asterisks*\fR or \fC_underlines_\fR will be put inside
-\fC<em></em>\fR. Text inside \fC**double asterisks**\fR will be put inside
-\fC<strong></strong>\fR.
+\fC<em></em>\fR. Text inside \fC**double asterisks**\fR or \fC__double
+underlines__\fR will be put inside \fC<strong></strong>\fR.
.
.IP \[bu]
.BR Backticks .
-Text inside \fC`backticks`\fR will be put inside \fC<code></code>\fR (one per
-line, both backticks need to be on the same line).
+Text inside \fC`backticks`\fR will be put inside \fC<code></code>\fR (both
+backticks need to be on the same line).
.
.IP \[bu]
.BR "Blockquotes" .
@@ -94,7 +93,7 @@ Starting the line with \fC>\fR will surround it with a \fC<blockquote>\fR tag.
Multiple lines are supported.
.
.IP \[bu]
-.BR "Links (limited)" .
+.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.
@@ -317,6 +316,18 @@ file \fCindex.html\fR contains:
.SH "KNOWN LIMITATIONS"
.
.IP \[bu] 4
+As of v0.3.0,
+.B slweb
+is undergoing a migration from Bash script using
+.BR sed (1)
+to a C program. Not all old features will be working or working as intended
+until this migration is complete. See the file
+.SM TODO
+in the Github repository and the
+.SM BUGS
+section below.
+.
+.IP \[bu] 4
Currently there is no way to determine where the paragraph inside a tag should
begin and end without adding blank lines or using the \fC{p}{/p}\fR notation.
For example, the code
diff --git a/slweb.c b/slweb.c
@@ -116,24 +116,13 @@ set_basedir(char* arg, char** basedir)
return 0;
}
-uint8_t*
-init_string(uint8_t** str)
-{
- if (!str || !*str)
- return NULL;
-
- *str[0] = '\0';
-
- return *str;
-}
-
int
finish_and_print_token(uint8_t** token, uint8_t** ptoken, FILE* output)
{
if (!token || !*token || !ptoken || !*ptoken)
return 1;
- *ptoken[0] = '\0';
+ **ptoken = '\0';
fprintf(output, "%s", *token);
return 0;
@@ -395,7 +384,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
*pline = '\0';
pline = line;
line_len = u8_strlen(line);
- ptoken = init_string(&token);
+ *token = '\0';
+ ptoken = token;
lineno++;
colno = 1;
@@ -449,7 +439,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
pvars->value = NULL;
state |= ST_YAML_VAL;
- ptoken = init_string(&token);
+ *token = '\0';
+ ptoken = token;
pline++;
colno++;
@@ -673,7 +664,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
}
state |= ST_TAG;
- ptoken = init_string(&token);
+ *token = '\0';
+ ptoken = token;
pline++;
colno++;
@@ -717,7 +709,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
process_tag(token, output, end_tag);
first_line_in_doc = FALSE;
print_newline = TRUE;
- ptoken = init_string(&token);
+ *token = '\0';
+ ptoken = token;
end_tag = FALSE;
pline++;
@@ -736,7 +729,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
*ptoken = '\0';
if (!read_yaml_macros_and_links)
fprintf(output, "%s", token);
- ptoken = init_string(&token);
+ *token = '\0';
+ ptoken = token;
if (u8_strlen(pline) > 1 && *(pline+1) == '[')
{
@@ -774,7 +768,9 @@ slweb_parse(uint8_t* buffer, FILE* output,
}
state |= ST_LINK;
- ptoken = init_string(&token);
+
+ *token = '\0';
+ ptoken = token;
pline++;
colno++;
@@ -796,7 +792,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
else
process_inline_image(link_text, token, output);
}
- ptoken = init_string(&token);
+ *token = '\0';
+ ptoken = token;
state &= ~(ST_LINK | ST_LINK_SECOND_ARG
| ST_IMAGE | ST_IMAGE_SECOND_ARG);
pline++;
@@ -817,7 +814,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
if (!read_yaml_macros_and_links)
process_link(link_text, token, *links, *links_count,
output);
- ptoken = init_string(&token);
+ *token = '\0';
+ ptoken = token;
state &= ~(ST_LINK | ST_LINK_SECOND_ARG);
pline++;
colno++;
@@ -827,7 +825,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
if (!read_yaml_macros_and_links)
process_image(link_text, token, *links, *links_count,
output);
- ptoken = init_string(&token);
+ *token = '\0';
+ ptoken = token;
state &= ~(ST_IMAGE | ST_IMAGE_SECOND_ARG);
pline++;
colno++;
@@ -856,7 +855,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
pline++;
colno++;
}
- ptoken = init_string(&token);
+ *token = '\0';
+ ptoken = token;
state |= ST_LINK_SECOND_ARG;
break;
@@ -874,7 +874,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
u8_strcpy(link_text, token);
pline += 2;
colno += 2;
- ptoken = init_string(&token);
+ *token = '\0';
+ ptoken = token;
if (state & ST_LINK)
state |= ST_LINK_SECOND_ARG;
else
@@ -897,7 +898,7 @@ slweb_parse(uint8_t* buffer, FILE* output,
if (!(state & ST_YAML))
{
- if (token[0])
+ if (*token)
{
if (!processed_starting_newline
&& !read_yaml_macros_and_links
@@ -918,7 +919,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
if (!read_yaml_macros_and_links)
process_heading(token, output, heading_level);
first_line_in_doc = FALSE;
- ptoken = init_string(&token);
+ *token = '\0';
+ ptoken = token;
heading_level = 0;
print_newline = TRUE;
}
@@ -959,7 +961,7 @@ slweb_parse(uint8_t* buffer, FILE* output,
}
}
- else if (token[0] && read_yaml_macros_and_links
+ else if (*token && read_yaml_macros_and_links
&& state & ST_YAML_VAL)
{
*ptoken = '\0';
@@ -968,7 +970,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
u8_strcpy(pvars->value, token);
}
- ptoken = init_string(&token);
+ *token = '\0';
+ ptoken = token;
if (line_len == 0)
previous_line_blank = TRUE;
@@ -1000,7 +1003,7 @@ main(int argc, char** argv)
basedir = (char*) calloc(2, sizeof(char));
if (!basedir)
return error(ENOMEM, (uint8_t*)"Memory allocation failed (out of memory?)\n");
- basedir[0] = '.';
+ *basedir = '.';
while ((arg = *++argv))
{