чување d831b2858dafa85c539eb99a5ea397ff022e3bae
родитељ ff18a11fe49b31b1b09144e4ed8c18c623b7dead
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Tue, 19 Jan 2021 18:33:25 +0100
Permit macros and tags in headings
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 3, додавања: 41(+), брисања: 26(-)
diff --git a/defs.h b/defs.h
@@ -85,22 +85,23 @@ typedef struct
#define ST_PARA_OPEN (1 << 2)
#define ST_TAG (1 << 3)
#define ST_HEADING (1 << 4)
-#define ST_BOLD (1 << 5)
-#define ST_ITALIC (1 << 6)
-#define ST_PRE (1 << 7)
-#define ST_CODE (1 << 8)
-#define ST_BLOCKQUOTE (1 << 9)
-#define ST_LINK (1 << 10)
-#define ST_LINK_SECOND_ARG (1 << 11)
-#define ST_LINK_SPAN (1 << 12)
-#define ST_LINK_MACRO (1 << 13)
-#define ST_IMAGE (1 << 14)
-#define ST_IMAGE_SECOND_ARG (1 << 15)
-#define ST_MACRO_BODY (1 << 16)
-#define ST_CSV_BODY (1 << 17)
-#define ST_HTML_TAG (1 << 18)
-#define ST_KBD (1 << 19)
-#define ST_LIST (1 << 20)
+#define ST_HEADING_TEXT (1 << 5)
+#define ST_BOLD (1 << 6)
+#define ST_ITALIC (1 << 7)
+#define ST_PRE (1 << 8)
+#define ST_CODE (1 << 9)
+#define ST_BLOCKQUOTE (1 << 10)
+#define ST_LINK (1 << 11)
+#define ST_LINK_SECOND_ARG (1 << 12)
+#define ST_LINK_SPAN (1 << 13)
+#define ST_LINK_MACRO (1 << 14)
+#define ST_IMAGE (1 << 15)
+#define ST_IMAGE_SECOND_ARG (1 << 16)
+#define ST_MACRO_BODY (1 << 17)
+#define ST_CSV_BODY (1 << 18)
+#define ST_HTML_TAG (1 << 19)
+#define ST_KBD (1 << 20)
+#define ST_LIST (1 << 21)
#define ST_CS_NONE 0
#define ST_CS_HEADER 1
diff --git a/index.html b/index.html
@@ -134,7 +134,7 @@ this program. If not, see <<a href="https://www.gnu.org/licenses">https://www
<div id="git-log">
Previous commit:
-index.slw e39fde5 2021-01-18 21:16:44 +0100 (Страхиња Радић) (HEAD -> master)
+index.slw ff18a11 2021-01-18 21:17:54 +0100 (Страхиња Радић) (HEAD -> master, origin/master, origin/HEAD)
</div><!--git-log-->
diff --git a/slweb.c b/slweb.c
@@ -304,13 +304,20 @@ read_file_into_buffer(uint8_t** buffer, size_t* buffer_size, char* input_filenam
}
int
+process_heading_start(FILE* output, UBYTE heading_level)
+{
+ print_output(output, "<h%d>", heading_level);
+ return 0;
+}
+
+int
process_heading(uint8_t* token, FILE* output, UBYTE heading_level)
{
if (!token || u8_strlen(token) < 1)
warning(1, (uint8_t*)"Empty heading");
- print_output(output, "<h%d>%s</h%d>",
- heading_level, token ? (char*)token : "", heading_level);
+ print_output(output, "%s</h%d>",
+ token ? (char*)token : "", heading_level);
return 0;
}
@@ -1898,6 +1905,16 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
}
+ if ((state & ST_HEADING) && !(state & ST_HEADING_TEXT))
+ {
+ if (!read_yaml_macros_and_links)
+ process_heading_start(output, heading_level);
+ state |= ST_HEADING_TEXT;
+ pline++;
+ colno++;
+ break;
+ }
+
if (colno == 1
&& u8_strlen(pline) > 1
&& startswith((char*)pline, " "))
@@ -1945,8 +1962,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
case '{':
- if (state & (ST_CODE | ST_HEADING | ST_PRE | ST_YAML
- | ST_YAML_VAL))
+ if (state & (ST_CODE | ST_PRE | ST_YAML | ST_YAML_VAL))
{
*ptoken++ = *pline++;
colno++;
@@ -2021,8 +2037,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
case '}':
- if (state & (ST_CODE | ST_PRE | ST_HEADING | ST_YAML
- | ST_YAML_VAL))
+ if (state & (ST_CODE | ST_PRE | ST_YAML | ST_YAML_VAL))
{
*ptoken++ = *pline++;
colno++;
@@ -2197,8 +2212,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
case '=':
- if (state & (ST_CODE | ST_HEADING | ST_MACRO_BODY | ST_PRE
- | ST_TAG))
+ if (state & (ST_CODE | ST_MACRO_BODY | ST_PRE | ST_TAG))
{
*ptoken++ = *pline++;
colno++;
@@ -2492,7 +2506,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
}
else if (state & ST_HEADING)
{
- state &= ~ST_HEADING;
+ state &= ~(ST_HEADING | ST_HEADING_TEXT);
if (!read_yaml_macros_and_links)
process_heading(token, output, heading_level);
first_line_in_doc = FALSE;