File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed
Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 11import type { App } from "obsidian" ;
22import { TextInputSuggest } from "./suggest" ;
3- import { normalizeDisplayItem , normalizeQuery } from "./utils" ;
3+ import {
4+ normalizeDisplayItem ,
5+ normalizeQuery ,
6+ stripMdExtensionForDisplay ,
7+ } from "./utils" ;
48
59export class GenericTextSuggester extends TextInputSuggest < string > {
610 constructor (
@@ -35,7 +39,9 @@ export class GenericTextSuggester extends TextInputSuggest<string> {
3539
3640 renderSuggestion ( value : string , el : HTMLElement ) : void {
3741 if ( ! value ) return ;
38- this . renderMatch ( el , value , this . getCurrentQuery ( ) ) ;
42+ const displayValue = stripMdExtensionForDisplay ( value ) ;
43+ const displayQuery = stripMdExtensionForDisplay ( this . getCurrentQuery ( ) ) ;
44+ this . renderMatch ( el , displayValue , displayQuery ) ;
3945 }
4046
4147 protected getCurrentQuery ( ) : string {
Original file line number Diff line number Diff line change 44 replaceRange ,
55 getTextBeforeCursor ,
66 renderExactHighlight ,
7- renderFuzzyHighlight
7+ renderFuzzyHighlight ,
8+ stripMdExtensionForDisplay ,
89} from "./utils" ;
910
1011// Mock HTMLInputElement for testing
@@ -155,4 +156,27 @@ describe("Suggester Utils", () => {
155156 expect ( el . innerHTML ) . toBe ( '<<mark class="qa-highlight">i</mark>mg src=x>' ) ;
156157 } ) ;
157158 } ) ;
159+
160+ describe ( "stripMdExtensionForDisplay" , ( ) => {
161+ it ( "strips only a trailing .md extension (case-insensitive)" , ( ) => {
162+ expect ( stripMdExtensionForDisplay ( "file.md" ) ) . toBe ( "file" ) ;
163+ expect ( stripMdExtensionForDisplay ( "folder/file.md" ) ) . toBe ( "folder/file" ) ;
164+ expect ( stripMdExtensionForDisplay ( "FILE.MD" ) ) . toBe ( "FILE" ) ;
165+ } ) ;
166+
167+ it ( "does not strip other extensions" , ( ) => {
168+ expect ( stripMdExtensionForDisplay ( "file.js" ) ) . toBe ( "file.js" ) ;
169+ expect ( stripMdExtensionForDisplay ( "file.canvas" ) ) . toBe ( "file.canvas" ) ;
170+ } ) ;
171+
172+ it ( "does not strip .md when it is not the final suffix" , ( ) => {
173+ expect ( stripMdExtensionForDisplay ( "file.md.backup" ) ) . toBe (
174+ "file.md.backup" ,
175+ ) ;
176+ expect ( stripMdExtensionForDisplay ( "file.md.md" ) ) . toBe ( "file.md" ) ;
177+ expect ( stripMdExtensionForDisplay ( "{{TEMPLATE:folder/file.md}}" ) ) . toBe (
178+ "{{TEMPLATE:folder/file.md}}" ,
179+ ) ;
180+ } ) ;
181+ } ) ;
158182} ) ;
Original file line number Diff line number Diff line change @@ -16,6 +16,11 @@ export function normalizeForSearch(value: string): string {
1616 return value . normalize ( "NFC" ) . toLowerCase ( ) ;
1717}
1818
19+ // Display-only helper: keep stored path intact, but hide trailing ".md" in UI labels.
20+ export function stripMdExtensionForDisplay ( value : string ) : string {
21+ return value . toLowerCase ( ) . endsWith ( ".md" ) ? value . slice ( 0 , - 3 ) : value ;
22+ }
23+
1924/**
2025 * Insert text at cursor position
2126 */
You can’t perform that action at this time.
0 commit comments