-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from dvcrn/93-heading-inside-block
- Loading branch information
Showing
9 changed files
with
2,367 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
export interface PluginManifest { | ||
id: string; | ||
name: string; | ||
version: string; | ||
minAppVersion: string; | ||
author: string; | ||
description: string; | ||
} | ||
|
||
export class App { | ||
vault: any; | ||
workspace: any; | ||
constructor() { | ||
this.vault = {}; | ||
this.workspace = {}; | ||
} | ||
} | ||
|
||
export class Plugin { | ||
app: App; | ||
manifest: any; | ||
|
||
constructor(app: App, manifest: any) { | ||
this.app = app; | ||
this.manifest = manifest; | ||
} | ||
|
||
loadData(): Promise<any> { | ||
return Promise.resolve({}); | ||
} | ||
|
||
saveData(data: any): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
} | ||
|
||
export class PluginSettingTab {} | ||
export class Setting {} | ||
export class TAbstractFile {} | ||
export class TFile extends TAbstractFile { | ||
basename: string; | ||
extension: string; | ||
path: string; | ||
parent: any; | ||
|
||
constructor() { | ||
super(); | ||
this.basename = ''; | ||
this.extension = ''; | ||
this.path = ''; | ||
this.parent = { path: '' }; | ||
} | ||
} | ||
export class Editor {} | ||
export class MarkdownView {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
moduleNameMapper: { | ||
'^obsidian': '<rootDir>/node_modules/obsidian/dist/obsidian.js', | ||
}, | ||
transform: { | ||
'^.+\\.tsx?': [ | ||
'ts-jest', | ||
{ | ||
tsconfig: 'tsconfig.json', | ||
}, | ||
], | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import FilenameHeadingSyncPlugin from './main'; | ||
import { App, PluginManifest } from 'obsidian'; | ||
|
||
describe('FilenameHeadingSyncPlugin', () => { | ||
let plugin: FilenameHeadingSyncPlugin; | ||
let app: App; | ||
|
||
beforeEach(() => { | ||
// Create a proper mock of the App class | ||
app = { | ||
vault: { | ||
on: jest.fn(), | ||
getFiles: jest.fn().mockReturnValue([]), | ||
}, | ||
workspace: { | ||
on: jest.fn(), | ||
activeLeaf: null, | ||
}, | ||
fileManager: {}, | ||
// Add other required App properties | ||
} as unknown as App; | ||
|
||
const manifest: PluginManifest = { | ||
id: 'test', | ||
name: 'Test Plugin', | ||
version: '1.0.0', | ||
minAppVersion: '0.15.0', | ||
author: 'Test Author', | ||
description: 'Test Description', | ||
}; | ||
|
||
plugin = new FilenameHeadingSyncPlugin(app, manifest); | ||
}); | ||
|
||
describe('findHeading', () => { | ||
it('should find heading after frontmatter', () => { | ||
const fileLines = [ | ||
'---', | ||
'title: Test', | ||
'date: 2023-01-01', | ||
'---', | ||
'# First Heading', | ||
'Some content', | ||
]; | ||
|
||
const result = plugin.findHeading( | ||
fileLines, | ||
plugin.findNoteStart(fileLines), | ||
); | ||
|
||
expect(result).not.toBeNull(); | ||
expect(result?.text).toBe('First Heading'); | ||
expect(result?.style).toBe('Prefix'); | ||
expect(result?.lineNumber).toBe(4); | ||
}); | ||
|
||
it('should skip heading in fenced code block', () => { | ||
const fileLines = [ | ||
'', | ||
'```', | ||
'# Heading Inside Code', | ||
'```', | ||
'# Actual Heading', | ||
'Some content', | ||
]; | ||
|
||
const result = plugin.findHeading(fileLines, 0); | ||
|
||
expect(result).not.toBeNull(); | ||
expect(result?.text).toBe('Actual Heading'); | ||
expect(result?.style).toBe('Prefix'); | ||
expect(result?.lineNumber).toBe(4); | ||
}); | ||
|
||
it('should find underline style heading', () => { | ||
const fileLines = ['First Heading', '============', 'Some content']; | ||
|
||
const result = plugin.findHeading(fileLines, 0); | ||
|
||
expect(result).not.toBeNull(); | ||
expect(result?.text).toBe('First Heading'); | ||
expect(result?.style).toBe('Underline'); | ||
expect(result?.lineNumber).toBe(0); | ||
}); | ||
|
||
it('should ignore escaped hash prefix', () => { | ||
const fileLines = [ | ||
'\\# Not a heading', | ||
'# Actual Heading', | ||
'Some content', | ||
]; | ||
|
||
const result = plugin.findHeading(fileLines, 0); | ||
|
||
expect(result).not.toBeNull(); | ||
expect(result?.text).toBe('Actual Heading'); | ||
expect(result?.style).toBe('Prefix'); | ||
expect(result?.lineNumber).toBe(1); | ||
}); | ||
|
||
it('should ignore hash inside inline code', () => { | ||
const fileLines = [ | ||
'`# Not a heading`', | ||
'# Actual Heading', | ||
'Some content', | ||
]; | ||
|
||
const result = plugin.findHeading(fileLines, 0); | ||
|
||
expect(result).not.toBeNull(); | ||
expect(result?.text).toBe('Actual Heading'); | ||
expect(result?.style).toBe('Prefix'); | ||
expect(result?.lineNumber).toBe(1); | ||
}); | ||
|
||
it('should ignore heading inside frontmatter', () => { | ||
const fileLines = [ | ||
'---', | ||
'# Not a heading', | ||
'title: Test', | ||
'---', | ||
'# Actual Heading', | ||
'Some content', | ||
]; | ||
|
||
const result = plugin.findHeading( | ||
fileLines, | ||
plugin.findNoteStart(fileLines), | ||
); | ||
|
||
expect(result).not.toBeNull(); | ||
expect(result?.text).toBe('Actual Heading'); | ||
expect(result?.style).toBe('Prefix'); | ||
expect(result?.lineNumber).toBe(4); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.