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

Add config argument to specify valid markdown flavors #1424

Merged
merged 3 commits into from
Feb 21, 2025
Merged
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
31,816 changes: 0 additions & 31,816 deletions package-lock.json

This file was deleted.

7 changes: 7 additions & 0 deletions packages/foam-vscode/package.json
Original file line number Diff line number Diff line change
@@ -457,6 +457,13 @@
"configuration": {
"title": "Foam",
"properties": {
"foam.supportedLanguages": {
"type": "array",
"default": [
"markdown"
],
"description": "List of languages to treat as Markdown-like documents."
},
"foam.completion.label": {
"type": "string",
"default": "path",
28 changes: 21 additions & 7 deletions packages/foam-vscode/src/services/editor.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ import { getExcerpt, stripFrontMatter, stripImages } from '../core/utils/md';
import { isSome } from '../core/utils/core';
import { fromVsCodeUri, toVsCodeUri } from '../utils/vsc-utils';
import { asAbsoluteUri, URI } from '../core/model/uri';
import { getFoamVsCodeConfig } from './config';
import {
AlwaysIncludeMatcher,
FileListBasedMatcher,
@@ -52,14 +53,27 @@ export function formatMarkdownTooltip(content: string): MarkdownString {
return md;
}

export const mdDocSelector = [
{ language: 'markdown', scheme: 'file' },
{ language: 'markdown', scheme: 'vscode-vfs' },
{ language: 'markdown', scheme: 'untitled' },
];
// Generate the document selector dynamically
export const mdDocSelector = getFoamVsCodeConfig<string[]>(
'supportedLanguages',
['markdown']
).flatMap(lang => [
{ language: lang, scheme: 'file' }, // Local files
{ language: lang, scheme: 'vscode-vfs' }, // Remote files
{ language: lang, scheme: 'untitled' }, // Untitled files
]);

export function isMdEditor(editor: TextEditor) {
return editor && editor.document && editor.document.languageId === 'markdown';
// Check if the editor's document is a supported language
export function isMdEditor(editor: TextEditor): boolean {
const supportedLanguages = getFoamVsCodeConfig<string[]>(
'supportedLanguages',
['markdown']
);
return (
editor &&
editor.document &&
supportedLanguages.includes(editor.document.languageId)
);
}

export function findSelectionContent(): SelectionInfo | undefined {