diff --git a/package.json b/package.json index 5e72cf6fd..04924af4a 100644 --- a/package.json +++ b/package.json @@ -39,5 +39,6 @@ "singleQuote": true, "trailingComma": "es5" }, - "dependencies": {} + "dependencies": {}, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/packages/foam-vscode/src/core/model/note.ts b/packages/foam-vscode/src/core/model/note.ts index f85714647..bf8658af8 100644 --- a/packages/foam-vscode/src/core/model/note.ts +++ b/packages/foam-vscode/src/core/model/note.ts @@ -43,6 +43,20 @@ export interface Section { range: Range; } +/** + * + * @jakefrommars64 + * If a note has the following frontmatter: + * ```markdown + * --- + * type: project + * --- + * ``` + * then the following is true: + * - `Resource.type == 'note'` + * - `Resource.properties.type == 'project'` + * + */ export interface Resource { uri: URI; type: string; diff --git a/packages/foam-vscode/src/features/preview/index.ts b/packages/foam-vscode/src/features/preview/index.ts index 598979d47..6f6b44426 100644 --- a/packages/foam-vscode/src/features/preview/index.ts +++ b/packages/foam-vscode/src/features/preview/index.ts @@ -6,6 +6,7 @@ import { default as markdownItFoamTags } from './tag-highlight'; import { default as markdownItWikilinkNavigation } from './wikilink-navigation'; import { default as markdownItRemoveLinkReferences } from './remove-wikilink-references'; import { default as markdownItWikilinkEmbed } from './wikilink-embed'; +import foamQuery from './query-embed'; export default async function activate( context: vscode.ExtensionContext, @@ -20,6 +21,7 @@ export default async function activate( markdownItFoamTags, markdownItWikilinkNavigation, markdownItRemoveLinkReferences, + foamQuery, ].reduce( (acc, extension) => extension(acc, foam.workspace, foam.services.parser), diff --git a/packages/foam-vscode/src/features/preview/query-embed.spec.ts b/packages/foam-vscode/src/features/preview/query-embed.spec.ts new file mode 100644 index 000000000..74903ec10 --- /dev/null +++ b/packages/foam-vscode/src/features/preview/query-embed.spec.ts @@ -0,0 +1,14 @@ +import MarkdownIt from 'markdown-it'; +import { FoamWorkspace } from '../../core/model/workspace'; +import { default as markdownItFoamTags } from './tag-highlight'; +import foamQuery from './query-embed'; + +describe('Just find the stupid codeblock lol', () => { + const md = foamQuery(MarkdownIt(), new FoamWorkspace()); + + it('transforms a string containing a query codeblock to a stylable html element', () => { + expect(md.render(`\`\`\`query Hello World!\`\`\``)).toMatch( + `

\`\`\`query Hello World!\`\`\`

` + ); + }); +}); diff --git a/packages/foam-vscode/src/features/preview/query-embed.ts b/packages/foam-vscode/src/features/preview/query-embed.ts new file mode 100644 index 000000000..d3a84b483 --- /dev/null +++ b/packages/foam-vscode/src/features/preview/query-embed.ts @@ -0,0 +1,35 @@ +/*global markdownit:readonly*/ + +import markdownItRegex from 'markdown-it-regex'; +import { FoamWorkspace } from '../../core/model/workspace'; +import { Logger } from '../../core/utils/log'; +import { isNone } from '../../core/utils'; + +export const foamQuery = (md: markdownit, workspace: FoamWorkspace) => { + return md.use(markdownItRegex, { + name: 'foam-query', + regex: /(\?\?\?query\s[\s\S]*\s\?\?\?)/, // /(\?\?\?[0-9]*[\p{L}/_-][\p{L}\p{N}/_-]*\s*)/u, + replace: (query: string) => { + try { + Logger.error(`Query: ${query}`); + const resource = workspace.find(query); + if (isNone(resource)) { + let content = getFoamQuery(query); + let html = md.render(content); + return html; + } + } catch (e) { + Logger.error( + `Error while creating link for ${query} in Preview panel`, + e + ); + return getFoamQuery(query); + } + }, + }); +}; + +const getFoamQuery = (content: string) => + `
${content}
`; + +export default foamQuery; diff --git a/packages/foam-vscode/static/preview/style.css b/packages/foam-vscode/static/preview/style.css index 4560895f2..a145dc037 100644 --- a/packages/foam-vscode/static/preview/style.css +++ b/packages/foam-vscode/static/preview/style.css @@ -35,3 +35,8 @@ padding: 0.25em; text-align: center; } + +.foam-query { + font-family: 'Sansation'; + color: #f00; +} \ No newline at end of file