[Scummvm-git-logs] scummvm master -> 6683a75954740a315f13ae002456b3d6b0f5f69a

sev- noreply at scummvm.org
Tue Oct 31 01:03:42 UTC 2023


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
5a30cb60aa COMMON: FORMATS: Extend Markdown images with {} attributes
6683a75954 COMMON: FORMATS: Pass image extensions to the user callbacks in Markdown


Commit: 5a30cb60aaf2310f929ec7ecf2baa63a7deb7b7f
    https://github.com/scummvm/scummvm/commit/5a30cb60aaf2310f929ec7ecf2baa63a7deb7b7f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-10-31T01:57:57+01:00

Commit Message:
COMMON: FORMATS: Extend Markdown images with {} attributes

Changed paths:
    common/formats/markdown.cpp


diff --git a/common/formats/markdown.cpp b/common/formats/markdown.cpp
index 569f2873af8..4fe2cb88bea 100644
--- a/common/formats/markdown.cpp
+++ b/common/formats/markdown.cpp
@@ -824,11 +824,12 @@ static size_t char_autolink_url(SDDataBuffer *ob, SDMarkdown *rndr, byte *data,
 /* char_link • '[': parsing a link or an image */
 static size_t char_link(SDDataBuffer *ob, SDMarkdown *rndr, byte *data, size_t offset, size_t size) {
 	int is_img = (offset && data[-1] == '!'), level;
-	size_t i = 1, txt_e, link_b = 0, link_e = 0, title_b = 0, title_e = 0;
+	size_t i = 1, txt_e, link_b = 0, link_e = 0, title_b = 0, title_e = 0, ext_b = 0, ext_e = 0;
 	SDDataBuffer *content = 0;
 	SDDataBuffer *link = 0;
 	SDDataBuffer *title = 0;
 	SDDataBuffer *u_link = 0;
+	SDDataBuffer *ext = 0;
 	size_t org_work_size = rndr->_work_bufs[BUFFER_SPAN].size;
 	int text_has_nl = 0, ret = 0;
 	int in_title = 0, qtype = 0;
@@ -925,7 +926,30 @@ static size_t char_link(SDDataBuffer *ob, SDMarkdown *rndr, byte *data, size_t o
 		if (data[link_b] == '<') link_b++;
 		if (data[link_e - 1] == '>') link_e--;
 
-		/* building escaped link and title */
+		/* optional image extension */
+		if (is_img && i + 1 < size && data[i + 1] == '{') {
+			/* skipping initial whitespace and opening bracket */
+			i += 2;
+
+			while (i < size && _isspace(data[i]))
+				i++;
+
+			ext_b = i;
+
+			/* looking for extension end: '}" ) */
+			while (i < size && data[i] != '}')
+				i++;
+
+			if (i >= size) goto cleanup;
+
+			/* skipping whitespaces after extension */
+			ext_e = i - 1;
+			while (ext_e > ext_b && _isspace(data[ext_e]))
+				ext_e--;
+			ext_e++;
+		}
+
+		/* building escaped link, title and extension*/
 		if (link_e > link_b) {
 			link = rndr_newbuf(rndr, BUFFER_SPAN);
 			sd_bufput(link, data + link_b, link_e - link_b);
@@ -936,6 +960,11 @@ static size_t char_link(SDDataBuffer *ob, SDMarkdown *rndr, byte *data, size_t o
 			sd_bufput(title, data + title_b, title_e - title_b);
 		}
 
+		if (ext_e > ext_b) {
+			ext = rndr_newbuf(rndr, BUFFER_SPAN);
+			sd_bufput(ext, data + ext_b, ext_e - ext_b);
+		}
+
 		i++;
 	}
 


Commit: 6683a75954740a315f13ae002456b3d6b0f5f69a
    https://github.com/scummvm/scummvm/commit/6683a75954740a315f13ae002456b3d6b0f5f69a
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-10-31T01:58:55+01:00

Commit Message:
COMMON: FORMATS: Pass image extensions to the user callbacks in Markdown

Changed paths:
    common/formats/markdown.cpp
    common/formats/markdown.h
    graphics/macgui/mactext-md.cpp


diff --git a/common/formats/markdown.cpp b/common/formats/markdown.cpp
index 4fe2cb88bea..d53f5e543ac 100644
--- a/common/formats/markdown.cpp
+++ b/common/formats/markdown.cpp
@@ -1075,7 +1075,7 @@ static size_t char_link(SDDataBuffer *ob, SDMarkdown *rndr, byte *data, size_t o
 		if (ob->size && ob->data[ob->size - 1] == '!')
 			ob->size -= 1;
 
-		ret = rndr->_cb.image(ob, u_link, title, content, rndr->_opaque);
+		ret = rndr->_cb.image(ob, u_link, title, content, ext, rndr->_opaque);
 	} else {
 		ret = rndr->_cb.link(ob, u_link, title, content, rndr->_opaque);
 	}
diff --git a/common/formats/markdown.h b/common/formats/markdown.h
index 357fa882067..45292c20424 100644
--- a/common/formats/markdown.h
+++ b/common/formats/markdown.h
@@ -89,7 +89,7 @@ struct SDCallbacks {
 	int (*codespan)(SDDataBuffer *ob, const SDDataBuffer *text, void *opaque);
 	int (*double_emphasis)(SDDataBuffer *ob, const SDDataBuffer *text, void *opaque);
 	int (*emphasis)(SDDataBuffer *ob, const SDDataBuffer *text, void *opaque);
-	int (*image)(SDDataBuffer *ob, const SDDataBuffer *link, const SDDataBuffer *title, const SDDataBuffer *alt, void *opaque);
+	int (*image)(SDDataBuffer *ob, const SDDataBuffer *link, const SDDataBuffer *title, const SDDataBuffer *alt, const SDDataBuffer *ext, void *opaque);
 	int (*linebreak)(SDDataBuffer *ob, void *opaque);
 	int (*link)(SDDataBuffer *ob, const SDDataBuffer *link, const SDDataBuffer *title, const SDDataBuffer *content, void *opaque);
 	int (*raw_html_tag)(SDDataBuffer *ob, const SDDataBuffer *tag, void *opaque);
diff --git a/graphics/macgui/mactext-md.cpp b/graphics/macgui/mactext-md.cpp
index f009baf62e6..a33967e2c29 100644
--- a/graphics/macgui/mactext-md.cpp
+++ b/graphics/macgui/mactext-md.cpp
@@ -226,7 +226,7 @@ int render_emphasis(Common::SDDataBuffer *ob, const Common::SDDataBuffer *text,
 	return 1;
 }
 
-int render_image(Common::SDDataBuffer *ob, const Common::SDDataBuffer *link, const Common::SDDataBuffer *title, const Common::SDDataBuffer *alt, void *opaque) {
+int render_image(Common::SDDataBuffer *ob, const Common::SDDataBuffer *link, const Common::SDDataBuffer *title, const Common::SDDataBuffer *alt, const Common::SDDataBuffer *ext, void *opaque) {
 	if (!link)
 		return 0;
 
@@ -245,7 +245,7 @@ int render_image(Common::SDDataBuffer *ob, const Common::SDDataBuffer *link, con
 
 	sd_bufput(ob, res.c_str(), res.size());
 
-	debug(1, "render_image(%s, %s, %s)", PR(link), PR(title), PR(alt));
+	debug(1, "render_image(%s, %s, %s, %s)", PR(link), PR(title), PR(alt), PR(ext));
 	return 1;
 }
 




More information about the Scummvm-git-logs mailing list