Skip to content

Commit 38e3d0b

Browse files
author
Ozan Tellioglu
committed
Headers with Special Characters
1 parent 70c95a6 commit 38e3d0b

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/check-line.ts renamed to src/checkLine.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import 'prismjs/components/prism-bash.min';
2121
import 'prismjs/components/prism-visual-basic.min';
2222

2323
// Check Single Line
24-
export const check_line: any = async (
24+
export const checkLine: any = async (
2525
cm: CodeMirror.Editor,
2626
line_number: number,
2727
targetFile: TFile,
@@ -96,7 +96,11 @@ export const check_line: any = async (
9696
// --> Render # Header Block
9797
if (TransclusionHandler.lineIsWithHeading(line.text)) {
9898
const header = TransclusionHandler.getHeader(line.text);
99-
const blockHeading = cache.headings?.find((h) => h.heading === header);
99+
const blockHeading = cache.headings?.find(
100+
(h) =>
101+
ObsidianHelpers.clearSpecialCharacters(h.heading) ===
102+
ObsidianHelpers.clearSpecialCharacters(header)
103+
);
100104
if (blockHeading) {
101105
// --> Start Num
102106
let startNum = blockHeading.position.start.offset;
@@ -291,7 +295,7 @@ export const check_line: any = async (
291295
};
292296

293297
// Check All Lines Function
294-
export const check_lines: any = (
298+
export const checkLines: any = (
295299
cm: CodeMirror.Editor,
296300
from: number,
297301
to: number,
@@ -301,6 +305,6 @@ export const check_lines: any = (
301305
// Last Used Line Number in Code Mirror
302306
var file = ObsidianHelpers.getFileCmBelongsTo(cm, plugin.app.workspace);
303307
for (let i = from; i <= to; i++) {
304-
check_line(cm, i, file, plugin, changedFilePath);
308+
checkLine(cm, i, file, plugin, changedFilePath);
305309
}
306310
};

src/main.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Plugin, TAbstractFile, TFile } from 'obsidian';
22
import { ObsidianHelpers, WidgetHandler, ImageHandler, WikiMarkdownHandler } from './utils';
3-
import { check_line, check_lines } from './check-line';
3+
import { checkLine, checkLines } from './checkLine';
44
import { OzanImagePluginSettingsTab } from './settings';
55
import { WYSIWYG_Style } from './constants';
66
import { OzanImagePluginSettings, DEFAULT_SETTINGS } from './settings';
@@ -167,15 +167,15 @@ export default class OzanImagePlugin extends Plugin {
167167

168168
// Line Edit Changes
169169
codemirrorLineChanges = (cm: any, change: any) => {
170-
check_lines(cm, change.from.line, change.from.line + change.text.length - 1, this);
170+
checkLines(cm, change.from.line, change.from.line + change.text.length - 1, this);
171171
};
172172

173173
// Only Triggered during initial Load
174174
handleInitialLoad = (cm: CodeMirror.Editor) => {
175175
var lastLine = cm.lastLine();
176176
var file = ObsidianHelpers.getFileCmBelongsTo(cm, this.app.workspace);
177177
for (let i = 0; i < lastLine + 1; i++) {
178-
check_line(cm, i, file, this);
178+
checkLine(cm, i, file, this);
179179
}
180180
};
181181

@@ -205,7 +205,7 @@ export default class OzanImagePlugin extends Plugin {
205205
WidgetHandler.clearTransclusionWidgets(line);
206206
}
207207
} else {
208-
check_lines(cm, 0, cm.lastLine(), this);
208+
checkLines(cm, 0, cm.lastLine(), this);
209209
}
210210
});
211211
};
@@ -225,7 +225,7 @@ export default class OzanImagePlugin extends Plugin {
225225
if (!ImageHandler.is_an_image(file.path)) return;
226226
this.app.workspace.iterateCodeMirrors((cm) => {
227227
var lastLine = cm.lastLine();
228-
check_lines(cm, 0, lastLine, this, file.path);
228+
checkLines(cm, 0, lastLine, this, file.path);
229229
});
230230
};
231231

src/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ export class ObsidianHelpers {
281281
static openInternalLink = (event: MouseEvent, link: string, app: App) => {
282282
app.workspace.openLinkText(link, '/', Keymap.isModifier(event, 'Mod') || 1 === event.button);
283283
};
284+
285+
static clearSpecialCharacters = (str: string) => {
286+
return str.replace(/\s|[0-9_]|\W|[#$%^&*()]/g, '');
287+
};
284288
}
285289

286290
// --> Line Id Regex ![[hello#^f76b62]]

0 commit comments

Comments
 (0)