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

Added a single Docstring to the Resource interface #1374

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
"singleQuote": true,
"trailingComma": "es5"
},
"dependencies": {}
"dependencies": {},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
14 changes: 14 additions & 0 deletions packages/foam-vscode/src/core/model/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions packages/foam-vscode/src/features/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,6 +21,7 @@ export default async function activate(
markdownItFoamTags,
markdownItWikilinkNavigation,
markdownItRemoveLinkReferences,
foamQuery,
].reduce(
(acc, extension) =>
extension(acc, foam.workspace, foam.services.parser),
Expand Down
14 changes: 14 additions & 0 deletions packages/foam-vscode/src/features/preview/query-embed.spec.ts
Original file line number Diff line number Diff line change
@@ -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(
`<p><span class='foam-tag'>\`\`\`query Hello World!\`\`\`</span></p>`
);
});
});
35 changes: 35 additions & 0 deletions packages/foam-vscode/src/features/preview/query-embed.ts
Original file line number Diff line number Diff line change
@@ -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) =>
`<pre><code><span class="foam-query">${content}</span></code></pre>`;

export default foamQuery;
5 changes: 5 additions & 0 deletions packages/foam-vscode/static/preview/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@
padding: 0.25em;
text-align: center;
}

.foam-query {
font-family: 'Sansation';
color: #f00;
}