Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find CRLF line endings (Windows) with regexes #625

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading