Skip to content

Commit

Permalink
🚧 biome: obsidian
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Dec 20, 2024
1 parent fcea7ed commit 71f1cb7
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 129 deletions.
19 changes: 11 additions & 8 deletions src/obsidian/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class CommentParser {

return new Comment(type, attributes);
} catch (ex) {
console.error('ERROR: Cannot parse comment: ' + comment);
console.error(`ERROR: Cannot parse comment: ${comment}`);
return null;
}
}
Expand All @@ -102,14 +102,17 @@ export class CommentParser {
}

private readCommentStringFromLine(line: string): string {
return this.readCommentRegex.exec(line)?.[0] ?? '';
return this.readCommentRegex.exec(line)?.[0] ?? "";
}

private parseAttributes(properties: string): Map<string, string> {
let m;
const attributes = new Map<string, string>();

while ((m = this.parsePropertiesRegex.exec(properties)) !== null) {
while (true) {
const m = this.parsePropertiesRegex.exec(properties);
if (m == null) {
break;
}
if (m.index === this.parsePropertiesRegex.lastIndex) {
this.parsePropertiesRegex.lastIndex++;
}
Expand All @@ -118,16 +121,16 @@ export class CommentParser {
let value: string;

m.forEach((match, groupIndex) => {
if (groupIndex == 1 || groupIndex == 3) {
if (groupIndex === 1 || groupIndex === 3) {
key = match;
}
if (groupIndex == 2 || groupIndex == 4) {
if (groupIndex === 2 || groupIndex === 4) {
value = match;
attributes.set(key, value);
}
if (groupIndex == 5) {
if (groupIndex === 5) {
if (match) {
attributes.set(match, 'true');
attributes.set(match, "true");
}
}
});
Expand Down
22 changes: 11 additions & 11 deletions src/obsidian/embeddedSlideProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SlidesExtendedPlugin } from '../slidesExtended-Plugin';
import { EmbeddedSlideParameters } from '../@types';
import { load } from 'js-yaml';
import type { SlidesExtendedPlugin } from "../slidesExtended-Plugin";
import type { EmbeddedSlideParameters } from "../@types";
import { load } from "js-yaml";

export class EmbeddedSlideProcessor {
private plugin: SlidesExtendedPlugin;
Expand All @@ -11,26 +11,26 @@ export class EmbeddedSlideProcessor {
handler = async (source: string, el: HTMLElement) => {
try {
const parameters = this.readParameters(source);
const page = parameters.page ? `${parameters.page}` : '0';
const page = parameters.page ? `${parameters.page}` : "0";

const url = new URL(
`http://localhost:${this.plugin.settings.port}/embed/${parameters.slide}#/${page}`,
);
url.searchParams.append('embed', 'true');
url.searchParams.append("embed", "true");

const viewContent = el.createDiv();

viewContent.empty();
viewContent.addClass('reveal-preview-view');
viewContent.addClass("reveal-preview-view");

viewContent.createEl('iframe', {
viewContent.createEl("iframe", {
attr: {
src: url.toString(),
sandbox: 'allow-scripts allow-same-origin allow-popups',
sandbox: "allow-scripts allow-same-origin allow-popups",
},
});
} catch (e) {
el.createEl('h2', { text: 'Parameters invalid: ' + e.message });
el.createEl("h2", { text: `Parameters invalid: ${e.message}` });
}
};

Expand All @@ -39,10 +39,10 @@ export class EmbeddedSlideProcessor {
const slide = this.plugin.obsidianUtils.findFile(
params.slide.toString(),
);
if (slide && slide.endsWith('.md')) {
if (slide?.endsWith(".md")) {
params.slide = slide;
} else if (slide) {
params.slide = slide + '.md';
params.slide = `${slide}.md`;
}
return params;
}
Expand Down
24 changes: 11 additions & 13 deletions src/obsidian/markdownProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { InternalLinkProcessor } from './processors/internalLinkProcessor';
import { LatexProcessor } from './processors/latexProcessor';
import { MermaidProcessor } from './processors/mermaidProcessor';
import { MultipleFileProcessor } from './processors/multipleFileProcessor';
import { ObsidianUtils } from './obsidianUtils';
import type { ObsidianUtils } from "./obsidianUtils";
import { CommentProcessor } from './processors/commentProcessor';
import { DropProcessor } from './processors/dropProcessor';
import { YamlStore } from '../yaml/yamlStore';
Expand All @@ -23,7 +23,7 @@ import { ChartProcessor } from './processors/chartProcessor';
import { DefaultBackgroundProcessor } from './processors/defaultBackgroundProcessor';
import { ReferenceProcessor } from './processors/referenceProcessor';
import { SkipSlideProcessor } from './processors/skipSlideProcessor';
import { Options } from '../@types';
import type { Options } from "../@types";

export class MarkdownProcessor {
private multipleFileProcessor: MultipleFileProcessor;
Expand Down Expand Up @@ -80,10 +80,10 @@ export class MarkdownProcessor {
YamlStore.getInstance().options = options;

let before = this.trimEnding(markdown, options);
let after;
let after: string;

let circuitCounter = 0;
while (before != after) {
while (before !== after) {
circuitCounter++;
if (after) {
before = after;
Expand All @@ -100,7 +100,7 @@ export class MarkdownProcessor {

if (circuitCounter > 9) {
console.warn(
'WARNING: Circuit in template hierarchy detected!',
"WARNING: Circuit in template hierarchy detected!",
);
break;
}
Expand Down Expand Up @@ -297,21 +297,19 @@ export class MarkdownProcessor {
};

trimEnding(markdown: string, options: Options): string {
const input = markdown + '\n';
const input = `${markdown}\n`;

let m;
if ((m = new RegExp(options.separator, 'gmi').exec(input)) !== null) {
let m = new RegExp(options.separator, "gmi").exec(input);
if (m !== null) {
const [match] = m;

if (input.endsWith(match)) {
return input.substring(0, input.lastIndexOf(match));
}
}

if (
(m = new RegExp(options.verticalSeparator, 'gmi').exec(input)) !==
null
) {
m = new RegExp(options.verticalSeparator, "gmi").exec(input);
if (m !== null) {
const [match] = m;

if (input.endsWith(match)) {
Expand All @@ -323,7 +321,7 @@ export class MarkdownProcessor {
}

log(name: string, before: string, after: string) {
if (before != after) {
if (before !== after) {
console.debug(`${name}: ${after}`);
}
}
Expand Down
Loading

0 comments on commit 71f1cb7

Please sign in to comment.