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