Repository: platers/obsidian-linter (ts)

Issue:
Bug: css color definitions are confused as tags when transferring tags to front matter
## Describe the Bug

I am using linter and setting it up to move tags to the frontmatter.

highlightr plugin uses the syntax 

`<mark style="background: #FFB8EBA6;">some text</mark>`
linter confuses the color definition as tags and extracts the color declaration along with all the trailing characters 
resulting in

`---
tags:
  - FFB8EBA6;">text</mark>
aliases:
---`

## How to Reproduce
Install linter+highlightr
set up linter to move tags to frontmatter
run linter 




Pull request description:
Bug: Ignore Style Property Contents for Moving Tags
Fixes #489 

Changes Made:
- Ignored HTML tags for moving tags to the YAML frontmatter
- Added a UT to hopefully ensure that we do not hit this issue again in the future

Patch:
diff --git a/src/rules/move-tags-to-yaml.ts b/src/rules/move-tags-to-yaml.ts
index 1a0f0e9..c99e12d 100644
--- a/src/rules/move-tags-to-yaml.ts
+++ b/src/rules/move-tags-to-yaml.ts
@@ -42,7 +42,7 @@ export default class MoveTagsToYaml extends RuleBuilder<MoveTagsToYamlOptions> {
     return RuleType.YAML;
   }
   apply(text: string, options: MoveTagsToYamlOptions): string {
-    return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.inlineCode, IgnoreTypes.math], text, (text) => {
+    return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.inlineCode, IgnoreTypes.math, IgnoreTypes.html], text, (text) => {
       const tags = text.match(tagRegex);
       if (!tags) {
         return text;
diff --git a/src/utils/ignore-types.ts b/src/utils/ignore-types.ts
index 324a905..0f43190 100644
--- a/src/utils/ignore-types.ts
+++ b/src/utils/ignore-types.ts
@@ -18,14 +18,15 @@ export const IgnoreTypes: Record<string, IgnoreType> = {
   bold: {replaceAction: MDAstTypes.Bold, placeholder: '{STRONG_PLACEHOLDER}'},
   list: {replaceAction: MDAstTypes.List, placeholder: '{LIST_PLACEHOLDER}'},
   blockquote: {replaceAction: MDAstTypes.Blockquote, placeholder: '{BLOCKQUOTE_PLACEHOLDER}'},
-  table: {replaceAction: tableRegex, placeholder: '{TABLE_PLACEHOLDER}'},
   math: {replaceAction: MDAstTypes.Math, placeholder: '{MATH_PLACEHOLDER}'},
   inlineMath: {replaceAction: MDAstTypes.InlineMath, placeholder: '{INLINE_MATH_PLACEHOLDER}'},
+  html: {replaceAction: MDAstTypes.Html, placeholder: '{HTML_PLACEHOLDER}'},
   // RegExp
   yaml: {replaceAction: yamlRegex, placeholder: escapeDollarSigns('---\n---')},
   wikiLink: {replaceAction: wikiLinkRegex, placeholder: '{WIKI_LINK_PLACEHOLDER}'},
   tag: {replaceAction: tagRegex, placeholder: '#tag-placeholder'},
   obsidianMultiLineComments: {replaceAction: obsidianMultilineCommentRegex, placeholder: '{OBSIDIAN_COMMENT_PLACEHOLDER}'},
+  table: {replaceAction: tableRegex, placeholder: '{TABLE_PLACEHOLDER}'},
   // custom functions
   link: {replaceAction: replaceMarkdownLinks, placeholder: '{REGULAR_LINK_PLACEHOLDER}'},
 } as const;
diff --git a/src/utils/mdast.ts b/src/utils/mdast.ts
index d76a0b4..5b842d2 100644
--- a/src/utils/mdast.ts
+++ b/src/utils/mdast.ts
@@ -25,6 +25,7 @@ export enum MDAstTypes {
   List = 'list',
   Blockquote = 'blockquote',
   HorizontalRule = 'thematicBreak',
+  Html = 'html',
   // math types
   Math = 'math',
   InlineMath = 'inlineMath',
diff --git a/src/utils/regex.ts b/src/utils/regex.ts
index 138f4a9..171d1f4 100644
--- a/src/utils/regex.ts
+++ b/src/utils/regex.ts
@@ -11,7 +11,7 @@ export const indentedBlockRegex = '^((\t|( {4})).*\n)+';
 export const codeBlockRegex = new RegExp(`${backtickBlockRegexTemplate}|${tildeBlockRegexTemplate}|${indentedBlockRegex}`, 'gm');
 export const wikiLinkRegex = /(!?)(\[{2}[^[\n\]]*\]{2})/g;
 export const genericLinkRegex = /^!?\[.*\](.*)$/;
-export const tagRegex = /(?:\s|^)#[^\s#]{1,}/g;
+export const tagRegex = /(?:\s|^)#[^\s#;.,><?!=+]+/g;
 export const obsidianMultilineCommentRegex = /^%%\n[^%]*\n%%/gm;
 export const wordSplitterRegex = /[,\s]+/;
 export const ellipsisRegex = /(\. ?){2}\./g;


Test patch:
diff --git a/__tests__/move-tags-to-yaml.test.ts b/__tests__/move-tags-to-yaml.test.ts
index 3bfb770..44ea611 100644
--- a/__tests__/move-tags-to-yaml.test.ts
+++ b/__tests__/move-tags-to-yaml.test.ts
@@ -147,5 +147,22 @@ ruleTest({
         #test
       `,
     },
+    { // accounts for https://github.com/platers/obsidian-linter/issues/489
+      testName: 'CSS styles are not included in tags',
+      before: dedent`
+        ---
+        tag: ${''}
+        ---
+        <mark style="background: #FFB8EBA6;">some text</mark>
+      `,
+      after: dedent`
+        ---
+        tag: ${''}
+        ---
+        <mark style="background: #FFB8EBA6;">some text</mark>
+      `,
+    },
+
+
   ],
 });