From d73f96220aa99dc681a8e53f41474b65a02ed6fe Mon Sep 17 00:00:00 2001 From: Juju Adams Date: Sun, 29 Jan 2023 16:55:38 +0000 Subject: [PATCH] Fixes text parsing within links --- objects/obj_test_markdown/Create_0.gml | 21 +++++------------- .../scribble_markdown_format.gml | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/objects/obj_test_markdown/Create_0.gml b/objects/obj_test_markdown/Create_0.gml index 9b47e1b62..6ae25095a 100644 --- a/objects/obj_test_markdown/Create_0.gml +++ b/objects/obj_test_markdown/Create_0.gml @@ -7,26 +7,15 @@ text += "## Header 2\n"; text += "### Header 3\n"; text += "- Lorem Ipsum is simply *dummy text* of the printing and **typesetting**_industry.\n"; text += "1. _**Lorem Ipsum**_ has been the industry's \\*standard dummy\\* text ever since ***the 1500s***\n"; -text += "2. [An unknown printer](url) took a galley of type and scrambled it to make a type specimen book.\n"; +text += "2. [![spr_white_coin] An unknown printer](url) took a galley of type and scrambled it to make a type specimen book.\n"; text += "> It has survived not only five centuries, but also the leap into electronic typesetting, remaining [spr_coin] [rainbow]essentially unchanged[/rainbow] ![spr_coin].\n"; -//scribble_markdown_set_styles({ -// body: { -// font: "fnt_style", -// }, -// header1: { -// font: "fnt_style_header1", -// }, -// header2: { -// font: "fnt_style_header2", -// }, -// header3: { -// font: "fnt_style_header3", -// }, -// bullet_sprite: spr_coin, -//}); +scribble_markdown_set_styles({ + bullet_sprite: spr_coin, +}); text = scribble_markdown_format(text); +show_message(text); element = scribble(text) .align(fa_left, fa_middle) diff --git a/scripts/scribble_markdown_format/scribble_markdown_format.gml b/scripts/scribble_markdown_format/scribble_markdown_format.gml index a3943883f..920457e04 100644 --- a/scripts/scribble_markdown_format/scribble_markdown_format.gml +++ b/scripts/scribble_markdown_format/scribble_markdown_format.gml @@ -486,7 +486,7 @@ function scribble_markdown_format(_string) } else { - if (_value == ord("[")) //Links + if (!_in_link && (_value == ord("["))) //Links { #region [text](region) @@ -506,16 +506,26 @@ function scribble_markdown_format(_string) else if (_link_next_value == ord("]")) { ++_link_peek; - if (buffer_peek(_buffer, _link_peek, buffer_u8) == ord("(")) _is_link = true; - break; + + if (buffer_peek(_buffer, _link_peek, buffer_u8) == ord("(")) + { + _is_link = true; + break; + } + + ++_link_size; + } + else + { + ++_link_size; + ++_link_peek; } - - ++_link_size; - ++_link_peek; } if (_is_link) { + _is_link = false; + //Look for the name of the region (which would otherwise be a URL in markdown) var _region_start = _link_peek+1; var _region_end = _region_start;