aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2017-02-15 23:27:00 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2017-02-15 23:27:00 +0100
commit1d790b8c78a2925a788e7167ed8d9d52d8e23906 (patch)
tree23d71719ef39dcf0257cdaa2be51898a31749217
parentbc23293bb178b6abcafa0f67d432cbff6ac3c861 (diff)
downloadblogc-1d790b8c78a2925a788e7167ed8d9d52d8e23906.tar.gz
blogc-1d790b8c78a2925a788e7167ed8d9d52d8e23906.tar.bz2
blogc-1d790b8c78a2925a788e7167ed8d9d52d8e23906.zip
content-parser: source-parser: rename TITLE to FIRST_HEADER
-rw-r--r--man/blogc-source.7.ronn10
-rw-r--r--src/blogc/content-parser.c6
-rw-r--r--src/blogc/content-parser.h4
-rw-r--r--src/blogc/source-parser.c16
-rw-r--r--tests/blogc/check_content_parser.c8
-rw-r--r--tests/blogc/check_source_parser.c18
6 files changed, 31 insertions, 31 deletions
diff --git a/man/blogc-source.7.ronn b/man/blogc-source.7.ronn
index 115ff94..f369461 100644
--- a/man/blogc-source.7.ronn
+++ b/man/blogc-source.7.ronn
@@ -52,11 +52,11 @@ that stores the name of the source file, without its extension. This is useful
for building permalinks in templates. This variable can't be overriden by an
explicit definition in source file.
-The variable `TITLE` is created by the source parser by default, containing the
-unparsed value of the first header found in the source file. The content is not
-parsed but HTML entities are encoded. Headers inside blockquotes are ignored.
-This variable can be overriden by an explicit definition in source file, that
-must have the HTML entities escaped manually.
+The variable `FIRST_HEADER` is created by the source parser by default,
+containing the unparsed value of the first header found in the source file.
+The content is not parsed but HTML entities are encoded. Headers inside
+blockquotes are ignored. This variable can be overriden by an explicit
+definition in source file, that must have the HTML entities escaped manually.
Another variable, `DESCRIPTION`, will be automatically created by the source
parser. It contains the unparsed content of the first paragraph found in the
diff --git a/src/blogc/content-parser.c b/src/blogc/content-parser.c
index 86aa74b..8e26943 100644
--- a/src/blogc/content-parser.c
+++ b/src/blogc/content-parser.c
@@ -674,7 +674,7 @@ blogc_is_ordered_list_item(const char *str, size_t prefix_len)
char*
-blogc_content_parse(const char *src, size_t *end_excerpt, char **title,
+blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
char **description)
{
// src is always nul-terminated.
@@ -835,8 +835,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **title,
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
tmp = bc_strndup(src + start, end - start);
- if (title != NULL && *title == NULL)
- *title = blogc_htmlentities(tmp);
+ if (first_header != NULL && *first_header == NULL)
+ *first_header = blogc_htmlentities(tmp);
parsed = blogc_content_parse_inline(tmp);
slug = blogc_slugify(tmp);
if (slug == NULL)
diff --git a/src/blogc/content-parser.h b/src/blogc/content-parser.h
index 39230c6..3b5b85c 100644
--- a/src/blogc/content-parser.h
+++ b/src/blogc/content-parser.h
@@ -17,7 +17,7 @@ char* blogc_htmlentities(const char *str);
char* blogc_fix_description(const char *paragraph);
char* blogc_content_parse_inline(const char *src);
bool blogc_is_ordered_list_item(const char *str, size_t prefix_len);
-char* blogc_content_parse(const char *src, size_t *end_excerpt, char **title,
- char **description);
+char* blogc_content_parse(const char *src, size_t *end_excerpt,
+ char **first_header, char **description);
#endif /* _CONTENT_PARSER_H */
diff --git a/src/blogc/source-parser.c b/src/blogc/source-parser.c
index f6f3471..eb0a975 100644
--- a/src/blogc/source-parser.c
+++ b/src/blogc/source-parser.c
@@ -150,19 +150,19 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err)
if (current == (src_len - 1)) {
tmp = bc_strndup(src + start, src_len - start);
bc_trie_insert(rv, "RAW_CONTENT", tmp);
- char *title = NULL;
+ char *first_header = NULL;
char *description = NULL;
- content = blogc_content_parse(tmp, &end_excerpt, &title,
- &description);
- if (title != NULL) {
- // do not override source-provided title.
- if (NULL == bc_trie_lookup(rv, "TITLE")) {
+ content = blogc_content_parse(tmp, &end_excerpt,
+ &first_header, &description);
+ if (first_header != NULL) {
+ // do not override source-provided first_header.
+ if (NULL == bc_trie_lookup(rv, "FIRST_HEADER")) {
// no need to free, because we are transfering memory
// ownership to the trie.
- bc_trie_insert(rv, "TITLE", title);
+ bc_trie_insert(rv, "FIRST_HEADER", first_header);
}
else {
- free(title);
+ free(first_header);
}
}
if (description != NULL) {
diff --git a/tests/blogc/check_content_parser.c b/tests/blogc/check_content_parser.c
index 33e0c38..8797dc5 100644
--- a/tests/blogc/check_content_parser.c
+++ b/tests/blogc/check_content_parser.c
@@ -1162,7 +1162,7 @@ test_content_parse_ordered_list_crlf(void **state)
static void
-test_content_parse_title(void **state)
+test_content_parse_first_header(void **state)
{
char *t = NULL;
char *html = blogc_content_parse("# foo", NULL, &t, NULL);
@@ -1240,7 +1240,7 @@ test_content_parse_title(void **state)
static void
-test_content_parse_title_crlf(void **state)
+test_content_parse_first_header_crlf(void **state)
{
char *t = NULL;
char *html = blogc_content_parse("# foo\r\n", NULL, &t, NULL);
@@ -2355,8 +2355,8 @@ main(void)
unit_test(test_content_parse_unordered_list_crlf),
unit_test(test_content_parse_ordered_list),
unit_test(test_content_parse_ordered_list_crlf),
- unit_test(test_content_parse_title),
- unit_test(test_content_parse_title_crlf),
+ unit_test(test_content_parse_first_header),
+ unit_test(test_content_parse_first_header_crlf),
unit_test(test_content_parse_description),
unit_test(test_content_parse_description_crlf),
unit_test(test_content_parse_invalid_excerpt),
diff --git a/tests/blogc/check_source_parser.c b/tests/blogc/check_source_parser.c
index e6ff955..c992c45 100644
--- a/tests/blogc/check_source_parser.c
+++ b/tests/blogc/check_source_parser.c
@@ -43,7 +43,7 @@ test_source_parse(void **state)
"# This is a test\n"
"\n"
"bola\n");
- assert_string_equal(bc_trie_lookup(source, "TITLE"), "This is a test");
+ assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
bc_trie_free(source);
}
@@ -76,7 +76,7 @@ test_source_parse_crlf(void **state)
"# This is a test\r\n"
"\r\n"
"bola\r\n");
- assert_string_equal(bc_trie_lookup(source, "TITLE"), "This is a test");
+ assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
bc_trie_free(source);
}
@@ -111,7 +111,7 @@ test_source_parse_with_spaces(void **state)
"# This is a test\n"
"\n"
"bola\n");
- assert_string_equal(bc_trie_lookup(source, "TITLE"), "This is a test");
+ assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
bc_trie_free(source);
}
@@ -156,19 +156,19 @@ test_source_parse_with_excerpt(void **state)
"\n"
"guda\n"
"yay");
- assert_string_equal(bc_trie_lookup(source, "TITLE"), "This is a test");
+ assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
bc_trie_free(source);
}
static void
-test_source_parse_with_title(void **state)
+test_source_parse_with_first_header(void **state)
{
const char *a =
"VAR1: asd asd\n"
"VAR2: 123chunda\n"
- "TITLE: THIS IS CHUNDA!\n"
+ "FIRST_HEADER: THIS IS CHUNDA!\n"
"----------\n"
"# This is a test\n"
"\n"
@@ -190,7 +190,7 @@ test_source_parse_with_title(void **state)
"# This is a test\n"
"\n"
"bola\n");
- assert_string_equal(bc_trie_lookup(source, "TITLE"), "THIS IS CHUNDA!");
+ assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "THIS IS CHUNDA!");
assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
bc_trie_free(source);
}
@@ -224,7 +224,7 @@ test_source_parse_with_description(void **state)
"# This is a test\n"
"\n"
"bola\n");
- assert_string_equal(bc_trie_lookup(source, "TITLE"), "This is a test");
+ assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "huehuehuebrbr");
bc_trie_free(source);
}
@@ -556,7 +556,7 @@ main(void)
unit_test(test_source_parse_crlf),
unit_test(test_source_parse_with_spaces),
unit_test(test_source_parse_with_excerpt),
- unit_test(test_source_parse_with_title),
+ unit_test(test_source_parse_with_first_header),
unit_test(test_source_parse_with_description),
unit_test(test_source_parse_config_empty),
unit_test(test_source_parse_config_invalid_key),