Skip to content

Commit

Permalink
Merge pull request #239 from pjkaufman/master
Browse files Browse the repository at this point in the history
Release Prep and Ignoring YAML for 2 Spaces Between Content Continued on the Next Line
  • Loading branch information
pjkaufman authored Jun 25, 2022
2 parents 4451013 + eee5d55 commit e2fc6c8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
21 changes: 19 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"1.3.2": "0.9.7"
"1.3.3": "0.9.7"
}

0 comments on commit e2fc6c8

Please sign in to comment.