чување 1002f8449b07ca482a762db732f401c8dcdf856c
родитељ 27db5f3b3baf3931ba3b519ced0b1907e68ef5fb
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Fri, 11 Dec 2020 21:52:55 +0100
Added git-log, bold, italic
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 6, додавања: 163(+), брисања: 9(-)
diff --git a/defs.h b/defs.h
@@ -63,9 +63,11 @@ const USHORT ST_YAML_VAL = 1 << 2;
const USHORT ST_PARA_OPEN = 1 << 3;
const USHORT ST_TAG = 1 << 4;
const USHORT ST_HEADING = 1 << 5;
-const USHORT ST_PRE = 1 << 6;
-const USHORT ST_CODE = 1 << 7;
-const USHORT ST_BLOCKQUOTE = 1 << 8;
+const USHORT ST_BOLD = 1 << 6;
+const USHORT ST_ITALIC = 1 << 7;
+const USHORT ST_PRE = 1 << 8;
+const USHORT ST_CODE = 1 << 9;
+const USHORT ST_BLOCKQUOTE = 1 << 10;
#pragma GCC diagnostic pop
#endif /* __DEFS_H */
diff --git a/examples/basic/index.slw b/examples/basic/index.slw
@@ -1,3 +1,4 @@
+---
site-name: Test website
site-desc: My first website in slweb
---
diff --git a/examples/includes/index.slw b/examples/includes/index.slw
@@ -1,3 +1,4 @@
+---
site-name: Includes
site-description: Demonstration of the includes
stylesheet: index.css
diff --git a/examples/tags/index.slw b/examples/tags/index.slw
@@ -1,3 +1,4 @@
+---
site-name: Tag test
---
{test}Tag test{/test}
diff --git a/index.html b/index.html
@@ -2,8 +2,8 @@
<h1>slweb</h1>
-<p>**Slweb** is a static website generator which aims at being simplistic. It uses
-**sed**(1) to transform a custom Markdown-like syntax into HTML.</p>
+<p><strong>Slweb</strong> is a static website generator which aims at being simplistic. It uses
+<strong>sed</strong>(1) to transform a custom Markdown-like syntax into HTML.</p>
<h2>Install</h2>
<pre>
@@ -74,7 +74,10 @@ PARTICULAR PURPOSE. See the GNU General Public License for more details. </p>
<p>You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>. </p>
-<git-log>
+<div id="git-log">
+Previous commit:index.slw 27db5f3 2020-12-11 19:39:00 +0100 (Страхиња Радић) (HEAD -> switch-to-c, origin/switch-to-c)
+</div><!--git-log-->
+
<div id="made-by">
Generated by <a href="https://github.com/Strahinja/slweb">slweb</a>
© 2020 Strahinya Radich.
diff --git a/slweb.c b/slweb.c
@@ -25,6 +25,7 @@
static size_t lineno = 0;
static size_t colno = 1;
+static char* filename = NULL;
int
version()
@@ -150,7 +151,50 @@ process_tag(uint8_t* token, FILE* output, BOOL end_tag)
if (!token || u8_strlen(token) < 1)
return warning(1, (uint8_t*)"No tag\n");
- if (!strcmp((char*)token, "made-by"))
+ char* basename = (char*) calloc(strlen(filename), sizeof(char));
+ char* slash = strrchr(filename, '/');
+ if (slash)
+ strcpy(basename, slash);
+ else
+ strcpy(basename, filename);
+
+ if (!strcmp((char*)token, "git-log"))
+ {
+ fprintf(output, "<div id=\"git-log\">\n"
+ "Previous commit:");
+ char* command = (char*) calloc(BUFSIZE, sizeof(char));
+ sprintf(command,
+ "git log -1 --pretty=format:\"%s %%h %%ci (%%cn) %%d\""
+ " || echo \"(Not in a Git repository)\"",
+ basename);
+ /*fprintf(stderr, "$(%s)\n", command);*/
+ FILE* cmd_output = popen(command, "r");
+ if (!cmd_output)
+ {
+ perror(PROGRAMNAME);
+ return error(1, (uint8_t*)"Cannot popen\n");
+ }
+ char* cmd_output_line = (char*) calloc(BUFSIZE, sizeof(char));
+ while (!feof(cmd_output))
+ {
+ if (!fgets(cmd_output_line, BUFSIZE, cmd_output))
+ continue;
+
+ char* eol = strchr(cmd_output_line, '\n');
+ if (eol)
+ *eol = '\0';
+
+ fprintf(output, "%s\n", cmd_output_line);
+
+ }
+ pclose(cmd_output);
+ fprintf(output, "</div><!--git-log-->\n");
+
+ free(command);
+ free(cmd_output_line);
+
+ }
+ else if (!strcmp((char*)token, "made-by"))
{
fprintf(output, "<div id=\"made-by\">\n"
"Generated by <a href=\"https://github.com/Strahinja/slweb\">"
@@ -163,6 +207,8 @@ process_tag(uint8_t* token, FILE* output, BOOL end_tag)
end_tag ? (const char*)"/" : (const char*)"",
token);
+ free(basename);
+
return 0;
}
@@ -171,7 +217,6 @@ main(int argc, char** argv)
{
char* arg;
Command cmd = CMD_NONE;
- char* filename = NULL;
BOOL body_only = FALSE;
char* basedir = NULL;
@@ -404,13 +449,114 @@ main(int argc, char** argv)
colno++;
}
break;
+ case '_':
+ if (state & (ST_TAG | ST_YAML | ST_PRE | ST_CODE))
+ {
+ *ptoken++ = *pline++;
+ colno++;
+ break;
+ }
+
+ if (u8_strlen(pline) > 1
+ && *(pline+1) == '_')
+ {
+ *ptoken = '\0';
+ if (state & ST_BOLD)
+ {
+ u8_strncat(ptoken, (uint8_t*)"</strong>",
+ strlen("</strong>"));
+ ptoken += strlen("</strong>");
+ state &= ~ST_BOLD;
+ }
+ else
+ {
+ u8_strncat(ptoken, (uint8_t*)"<strong>",
+ strlen("<strong>"));
+ ptoken += strlen("<strong>");
+ state |= ST_BOLD;
+ }
+ pline += 2;
+ colno += 2;
+ }
+ else
+ {
+ *ptoken = '\0';
+ if (state & ST_ITALIC)
+ {
+ u8_strncat(ptoken, (uint8_t*)"</em>",
+ strlen("</em>"));
+ ptoken += strlen("</em>");
+ state &= ~ST_ITALIC;
+ }
+ else
+ {
+ u8_strncat(ptoken, (uint8_t*)"<em>",
+ strlen("<em>"));
+ ptoken += strlen("<em>");
+ state |= ST_ITALIC;
+ }
+ pline += 2;
+ colno += 2;
+ }
+ break;
+ case '*':
+ if (state & (ST_TAG | ST_YAML | ST_PRE | ST_CODE))
+ {
+ *ptoken++ = *pline++;
+ colno++;
+ break;
+ }
+
+ if (u8_strlen(pline) > 1
+ && *(pline+1) == '*')
+ {
+ *ptoken = '\0';
+ if (state & ST_BOLD)
+ {
+ u8_strncat(ptoken, (uint8_t*)"</strong>",
+ strlen("</strong>"));
+ ptoken += strlen("</strong>");
+ state &= ~ST_BOLD;
+ }
+ else
+ {
+ u8_strncat(ptoken, (uint8_t*)"<strong>",
+ strlen("<strong>"));
+ ptoken += strlen("<strong>");
+ state |= ST_BOLD;
+ }
+ pline += 2;
+ colno += 2;
+ }
+ else
+ {
+ *ptoken = '\0';
+ if (state & ST_ITALIC)
+ {
+ u8_strncat(ptoken, (uint8_t*)"</em>",
+ strlen("</em>"));
+ ptoken += strlen("</em>");
+ state &= ~ST_ITALIC;
+ }
+ else
+ {
+ u8_strncat(ptoken, (uint8_t*)"<em>",
+ strlen("<em>"));
+ ptoken += strlen("<em>");
+ state |= ST_ITALIC;
+ }
+ pline += 2;
+ colno += 2;
+ }
+ break;
case ' ':
if (u8_strlen(pline) == 2)
{
if (*(pline+1) == ' ')
{
*ptoken = '\0';
- u8_strncat(ptoken, (uint8_t*)"<br />", strlen("<br />"));
+ u8_strncat(ptoken, (uint8_t*)"<br />",
+ strlen("<br />"));
ptoken += strlen("<br />");
pline++;
colno++;