From 67c7aa45c689b716753edf9cdd066aa5cb3ed5b3 Mon Sep 17 00:00:00 2001 From: Van De Velde Date: Thu, 5 Jul 2018 08:09:20 +0200 Subject: [PATCH] Updated tag logic using _ In markdown, an _ is something special ... One cannot just scan for every _ in a text and emphasize every text between _ (underscores). In many program languages, _ are used to represent a space in identifiers and functions etc. Therefore, I've updated the markdown.lua logic to ensure that text between _ is only emphasized when the first _ starts with a space or any other non alpameric character, or the _ starts at the beginning of the text. examples: AI\_CARGO\_DISPATCHER gives AI\_CARGO\_DISPATCHER. AI \_CARGO\_ DISPATCHER gives AI CARGO DISPATCHER. \_AI\_CARGO\_DISPATCHER gives AICARGO\_DISPATCHER --- markdown-tests.lua | 19 +++++++++++++++++++ markdown.lua | 16 +++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/markdown-tests.lua b/markdown-tests.lua index 187fe90..f2090f5 100644 --- a/markdown-tests.lua +++ b/markdown-tests.lua @@ -4392,6 +4392,25 @@ This is [an example] [id] reference-style link.

Wesel - Boxtel [KBS 134]

]==] +tests.sven = [[ +TASK_CARGO_DISPATCHER +~ +

TASK_CARGO_DISPATCHER

+~ +TASK _CARGO_ DISPATCHER +~ +

TASKCARGODISPATCHER

+~ +TASK_CARGO_ DISPATCHER +~ +

TASK_CARGO_ DISPATCHER

+~ +TASK*CARGO*DISPATCHER +~ +

TASKCARGODISPATCHER

+]] + + -- Unhandled test: _M*A*S*H_ local quiet_mode diff --git a/markdown.lua b/markdown.lua index 636e8f9..fd3349a 100644 --- a/markdown.lua +++ b/markdown.lua @@ -895,9 +895,19 @@ local function emphasis(text) text = text:gsub(s .. "([^%s][%*%_]?)" .. s, "%1") text = text:gsub(s .. "([^%s][^<>]-[^%s][%*%_]?)" .. s, "%1") end - for _, s in ipairs {"%*", "%_"} do - text = text:gsub(s .. "([^%s_])" .. s, "%1") - text = text:gsub(s .. "([^%s_])" .. s, "%1") + for _, s in ipairs {"%_"} do + text = text:gsub("([^%w]+)" .. s .. "([^%s_])" .. s, "%1%2 ") + text = text:gsub("([^%w]+)" .. s .. "([^%s_])" ..s, "%1%2") + text = text:gsub("([^%w]+)" .. s .. "([^%s_][^<>_]-[^%s_])" .. s, "%1%2") + text = text:gsub("([^%w]+)" .. s .. "([^<>_]-[^<>_]-[^<>_]-)" .. s, "%1%2") + text = text:gsub("^" .. s .. "([^%s_])" .. s, "%1 ") + text = text:gsub("^" .. s .. "([^%s_])" ..s, "%1") + text = text:gsub("^" .. s .. "([^%s_][^<>_]-[^%s_])" .. s, "%1") + text = text:gsub("^" .. s .. "([^<>_]-[^<>_]-[^<>_]-)" .. s, "%1") + end + for _, s in ipairs {"%*"} do + text = text:gsub(s .. "([^%s_])" .. s, "%1 ") + text = text:gsub(s .. "([^%s_])" ..s, "%1") text = text:gsub(s .. "([^%s_][^<>_]-[^%s_])" .. s, "%1") text = text:gsub(s .. "([^<>_]-[^<>_]-[^<>_]-)" .. s, "%1") end