Skip to content

Commit 16dca96

Browse files
committed
Add support for h2 and h3
1 parent 16ec9b9 commit 16dca96

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

docs/xml/metainfo-component.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@
247247
<para>Unordered list (<literal>ul</literal>), with list items (<literal>li</literal>)</para>
248248
</listitem>
249249
<listitem>
250+
<para>Heading of level 2 (<literal>h2</literal>) and level 3 (<literal>h3</literal>)</para>
251+
</listitem>
252+
<listitem>
250253
<para>
251254
Within paragraphs and list items, emphasis (<literal>em</literal>) and inline code (<literal>code</literal>) text styles are supported.
252255
The emphasis is commonly rendered in italic, while inline code is shown in a monospaced font.

src/as-utils.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,31 @@ as_description_markup_convert (const gchar *markup, AsMarkupKind to_kind, GError
259259
} else {
260260
g_string_append_printf (str, "%s\n", clean_text);
261261
}
262+
} else if ((g_strcmp0 ((gchar*) iter->name, "h2") == 0) || (g_strcmp0 ((gchar*) iter->name, "h3") == 0)) {
263+
g_autofree gchar *clean_text = NULL;
264+
g_autofree gchar *text_content = as_xml_get_node_value_raw (iter);
265+
g_auto(GStrv) spl = NULL;
266+
267+
/* Apparently the element is empty, which is odd. But we better add it instead
268+
* of completely ignoring it. */
269+
if (text_content == NULL)
270+
text_content = g_strdup ("");
271+
272+
/* remove extra whitespaces and linebreaks */
273+
clean_text = as_sanitize_text_spaces (text_content);
274+
275+
if (str->len > 0)
276+
g_string_append (str, "\n");
277+
278+
spl = as_markup_strsplit_words (clean_text, 100);
279+
if (spl != NULL) {
280+
for (guint i = 0; spl[i] != NULL; i++) {
281+
if (g_strcmp0 ((gchar*) iter->name, "h2") == 0)
282+
g_string_append_printf (str, "## %s\n", clean_text);
283+
else if (g_strcmp0 ((gchar*) iter->name, "h3") == 0)
284+
g_string_append_printf (str, "### %s\n", clean_text);
285+
}
286+
}
262287
} else if ((g_strcmp0 ((gchar*) iter->name, "ul") == 0) || (g_strcmp0 ((gchar*) iter->name, "ol") == 0)) {
263288
g_autofree gchar *item_c = NULL;
264289
gboolean is_ordered_list = g_strcmp0 ((gchar*) iter->name, "ol") == 0;

src/as-validator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,7 @@ as_validator_check_release (AsValidator *validator, xmlNode *node, AsFormatStyle
20912091
}
20922092

20932093
/* checks if the description is put outside a description tag */
2094-
if (as_str_equal0 (node_name, "p") || as_str_equal0 (node_name, "ol") || as_str_equal0 (node_name, "ul") || as_str_equal0 (node_name, "li")) {
2094+
if (as_str_equal0 (node_name, "p") || as_str_equal0 (node_name, "ol") || as_str_equal0 (node_name, "ul") || as_str_equal0 (node_name, "li") || as_str_equal0 (node_name, "h2") || as_str_equal0 (node_name, "h3")) {
20952095
as_validator_add_issue (validator, node, "release-description-outside-tag", node_name);
20962096
continue;
20972097
}

0 commit comments

Comments
 (0)