mirror of
https://github.com/mayurankv/Obsidian-Code-Styler.git
synced 2026-07-22 08:10:29 +00:00
Fix REGEX
This commit is contained in:
parent
303c52503c
commit
f5c281fd99
3 changed files with 12 additions and 4 deletions
1
.todo
1
.todo
|
|
@ -55,6 +55,7 @@ Features:
|
|||
|
||||
Inline Code:
|
||||
☐ Add copy button via settings and parameter #88
|
||||
☐ Add optional pandoc style marking
|
||||
|
||||
General:
|
||||
Improvements:
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ export interface InlineCodeParameters {
|
|||
}
|
||||
|
||||
export function parseInlineCode(codeText: string): {parameters: InlineCodeParameters | null, text: string} {
|
||||
const match = /^{( *(?:\w+(?: +(?:(?:[^\s"']+|"[^"]*"|'[^']*')+))*)? *)} *?([^ ].*?)$/.exec(codeText);
|
||||
const match = /^{((?:[^"'{}\\]|\\.|"([^"\\]|\\.)*"|'([^'\\]|\\.)*')*)} *?([^ ].*?)$/.exec(codeText);
|
||||
|
||||
if (typeof match?.[1] !== "undefined" && typeof match?.[2] !== "undefined") {
|
||||
if (match[1] === "")
|
||||
return {parameters: null, text: match[2]};
|
||||
else
|
||||
return {parameters: parseInlineCodeParameters(match[1]), text: match[2]};
|
||||
} else
|
||||
} else
|
||||
return {parameters: null, text: codeText};
|
||||
}
|
||||
function parseInlineCodeParameters(parameterLine: string): InlineCodeParameters {
|
||||
|
|
@ -36,8 +36,7 @@ function parseInlineCodeParameterString(parameterString: string, inlineCodeParam
|
|||
if (parameterString.startsWith("title:")) {
|
||||
const titleMatch = /(["']?)([^\1]+)\1/.exec(parameterString.slice("title:".length));
|
||||
if (titleMatch)
|
||||
inlineCodeParameters.title = titleMatch[2].trim();
|
||||
inlineCodeParameters.title = titleMatch[2].trim().replace(/\\{/g, "{");
|
||||
} else if (parameterString === "icon" || (parameterString.startsWith("icon:") && parameterString.toLowerCase() === "icon:true"))
|
||||
inlineCodeParameters.icon = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
8
tests/InlineRegex.regex
Normal file
8
tests/InlineRegex.regex
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{python} 'result if true'.method() if 1 else result_if_false.property
|
||||
{}{text here not styled}
|
||||
{python icon} 'result if true'.method() if 1 else result_if_false.property
|
||||
{python title:'Inline If'} 'result if true'.method() if 1 else result_if_false.property
|
||||
{python title:'Inline If' icon} 'result if true'.method() if 1 else result_if_false.property
|
||||
{js icon title:foo} javascript:(function(){alert('你好')})()
|
||||
{python} import pypy; print("code" + 'g' + aaa[23]); def bfs(): return None; False #test
|
||||
{ import pypy; print("code" + 'g' + aaa[23]); def bfs(): return None; False #test
|
||||
Loading…
Reference in a new issue