diff --git a/manifest.json b/manifest.json index 70121090..5591ca39 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-linter", "name": "Linter", - "version": "1.3.2", + "version": "1.3.3", "minAppVersion": "0.9.7", "description": "Enforces consistent markdown styling.", "author": "Victor Tao", diff --git a/src/utils.ts b/src/utils.ts index 98f97041..ec81abb0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,9 +13,13 @@ export const backtickBlockRegexTemplate = fencedRegexTemplate.replaceAll('X', '` export const tildeBlockRegexTemplate = fencedRegexTemplate.replaceAll('X', '~'); export const indentedBlockRegex = '^((\t|( {4})).*\n)+'; export const codeBlockRegex = new RegExp(`${backtickBlockRegexTemplate}|${tildeBlockRegexTemplate}|${indentedBlockRegex}`, 'gm'); -export const linkRegex = /((!?)\[[^[\n]*\]\([^[\n]*\))|(\[{2}[^[\n]*\]{2})/g; +export const linkRegex = /((!?)\[[^[\n\]]*\]\([^[\n\]]*\))|(\[{2}[^[\n\]]*\]{2})/g; export const tagRegex = /#[^\s#]{1,}/g; +// Reused placeholders + +const yamlPlaceholder = '---\n---'; + // Helper functions /** @@ -100,8 +104,18 @@ export function makeEmphasisOrBoldConsistent(text: string, style: string, type: * @return {string} The text with two spaces at the end of lines of paragraphs, list items, and blockquotes where there were consecutive lines of content. */ export function addTwoSpacesAtEndOfLinesFollowedByAnotherLineOfTextContent(text: string): string { + // added the placeholder for YAML in order to prevent the accidental misconstruing of the YAML as a paragraph when an array is in multiline form (i.e. it has a list for the array elements) + const yamlMatches = text.match(yamlRegex); + if (yamlMatches) { + text = text.replace(yamlMatches[0], escapeDollarSigns(yamlPlaceholder)); + } + const positions: Position[] = getPositions('paragraph', text); if (positions.length === 0) { + if (yamlMatches) { + text = text.replace(yamlPlaceholder, escapeDollarSigns(yamlMatches[0])); + } + return text; } @@ -126,6 +140,10 @@ export function addTwoSpacesAtEndOfLinesFollowedByAnotherLineOfTextContent(text: text = text.substring(0, position.start.offset) + paragraphLines.join('\n') + text.substring(position.end.offset); } + if (yamlMatches) { + text = text.replace(yamlPlaceholder, escapeDollarSigns(yamlMatches[0])); + } + return text; } @@ -180,7 +198,6 @@ export function ignoreCodeBlocksYAMLTagsAndLinks(text: string, func: (text: stri text = ret.text; const replacedCodeBlocks = ret.replacedCodeBlocks; - const yamlPlaceholder = '---\n---'; const yamlMatches = text.match(yamlRegex); if (yamlMatches) { text = text.replace(yamlMatches[0], escapeDollarSigns(yamlPlaceholder)); diff --git a/versions.json b/versions.json index fbf8149f..0109124a 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "1.3.2": "0.9.7" + "1.3.3": "0.9.7" }