Skip to content

Commit

Permalink
Consider CRLF in regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkopp committed Jul 28, 2024
1 parent d3c3b3f commit e6d64ac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/compiler/replaceBlockIDs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function replaceBlockIDs(markdown: string) {
const block_pattern = / \^([\w\d-]+)/g;
const complex_block_pattern = /\n\^([\w\d-]+)\n/g;
const complex_block_pattern = /[\r\n]\^([\w\d-]+)[\r\n]/g;

// To ensure code blocks are not modified...
const codeBlockPattern = /```[\s\S]*?```/g;
Expand Down
6 changes: 3 additions & 3 deletions src/publishFile/ObsidianFrontMatterEngine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MetadataCache, TFile, Vault } from "obsidian";
import { FRONTMATTER_REGEX } from "../utils/regexes";

export interface IFrontMatterEngine {
set(key: string, value: string | boolean | number): IFrontMatterEngine;
Expand Down Expand Up @@ -43,12 +44,11 @@ export default class ObsidianFrontMatterEngine implements IFrontMatterEngine {
const newFrontMatter = this.getFrontMatterSnapshot();

const content = await this.vault.cachedRead(this.file);
const frontmatterRegex = /^\s*?---\n([\s\S]*?)\n---/g;
const yaml = this.frontMatterToYaml(newFrontMatter);
let newContent = "";

if (content.match(frontmatterRegex)) {
newContent = content.replace(frontmatterRegex, (_match) => {
if (content.match(FRONTMATTER_REGEX)) {
newContent = content.replace(FRONTMATTER_REGEX, (_match) => {
return yaml;
});
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/regexes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const FRONTMATTER_REGEX = /^\s*?---\n([\s\S]*?)\n---/g;
export const BLOCKREF_REGEX = /(\^\w+(\n|$))/g;
export const FRONTMATTER_REGEX = /^\s*?---[\r\n]([\s\S]*?)[\r\n]---/g;
export const BLOCKREF_REGEX = /(\^\w+([\r\n]|$))/g;

export const CODE_FENCE_REGEX = /`(.*?)`/g;

export const CODEBLOCK_REGEX = /```.*?\n[\s\S]+?```/g;
export const CODEBLOCK_REGEX = /```.*?[\r\n][\s\S]+?```/g;

export const EXCALIDRAW_REGEX = /:\[\[(\d*?,\d*?)\],.*?\]\]/g;

Expand Down

0 comments on commit e6d64ac

Please sign in to comment.