Compare commits

...

86 Commits

Author SHA1 Message Date
Riccardo Ferretti
4c9a9cec56 v0.15.2 2021-10-27 12:11:02 +02:00
Riccardo Ferretti
8a91a6ab36 Prepare v0.15.2 2021-10-27 12:05:39 +02:00
Paul de Raaij
667037bc14 Improve generation of link reference definitions (#786)
* Fixes the removal of explicitly defined link references

* Add use case of explicit & implicit
2021-10-27 10:58:10 +02:00
allcontributors[bot]
30cc9fc9f0 docs: add eltociear as a contributor for doc (#801)
* docs: update docs/index.md [skip ci]

* docs: update readme.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2021-10-27 10:52:41 +02:00
Ikko Ashimine
abed7be3ec Fix typo in write-your-notes-in-github-gist.md (#798)
recieve -> receive
2021-10-27 10:51:27 +02:00
Riccardo
d31e094358 Added support for target date variables in daily note template (#781)
* added support for target date variables in daily note template

* added FOAM_DATE_* variables to resolver

* Document `FOAM_DATE_*` template variables

* Add CHANGELOG entry

Co-authored-by: Michael Overmeyer <michael.overmeyer@shopify.com>
2021-10-27 10:50:58 +02:00
Riccardo
f320af05c5 Improve graph performance by batching painting (#795) 2021-10-26 13:01:19 +02:00
Paul de Raaij
ee229dac84 Apply entire tag regex to the preview window (#785) 2021-10-25 19:56:51 +02:00
allcontributors[bot]
877d843f60 docs: add Laptop765 as a contributor for doc (#796)
* docs: update docs/index.md [skip ci]

* docs: update readme.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2021-10-25 19:51:22 +02:00
Paul
af65e4d5f7 Add some basic details about multi-root workspaces (#775)
* Include details about multi-root workspaces

* Reword and clarify
2021-10-25 19:50:47 +02:00
Riccardo Ferretti
dd9fa0af79 Link decorations now enabled by default 2021-10-25 19:22:32 +02:00
Riccardo Ferretti
14f68aea30 minor fixes around VS Code test configurations and suite reporting 2021-10-25 19:22:00 +02:00
Riccardo Ferretti
f68c2ab6db Color graph filter control based on style of node type 2021-10-22 12:33:19 +02:00
Riccardo Ferretti
bae99a6184 fixed dependencies and types 2021-10-21 10:09:45 +02:00
Riccardo Ferretti
861f7dbba7 v0.15.1 2021-10-21 09:01:19 +02:00
Riccardo Ferretti
6a4b90d6d7 Prepare 0.15.1 2021-10-21 08:59:34 +02:00
Riccardo
f73ddb88d4 Fixed test suite
* tweaking error propagation

* updated xvfb-action version

* improved logging

* only adding actually failing tests to failures (no comment)
2021-10-19 12:42:41 +02:00
Riccardo Ferretti
41ca70f23c better handling of output streams in tests and small change around computing which tests to run 2021-10-19 10:53:19 +02:00
Riccardo
7cf7811b85 Include other connected notes into link hovers (#780)
* Include other connected notes into link hovers

* reorganized hover provider tests and added some
2021-10-11 11:59:15 +02:00
Riccardo
eef0aa7f0b Improved filtering controls on graph visualization (#782)
* improved handling of filters in graph view
* code clean up
2021-10-11 11:55:54 +02:00
Riccardo
d222cfbbec Consolidate foam-core within foam-vscode (#774)
* moved `foam-core` inside `foam-vscode`

* updated contribution guide to reflect new modules setup

* improved testing

* consolidate to root yarn.lock files

* tweaking CI workflow && using github secrets to force cache refresh

* improved linting configuration. `core` module cannot depend on other parts of the `foam-vscode` package
2021-10-09 11:09:02 +02:00
Riccardo Ferretti
ee7a891976 v0.15.0 2021-10-04 10:05:46 +02:00
Riccardo Ferretti
680e317dbf Preparation for 0.15.0 2021-10-04 10:05:15 +02:00
Riccardo Ferretti
dbb46369a2 Added Project Manager to recommended extensions list (reported by @readingsnail) 2021-09-14 18:49:04 +02:00
Riccardo Ferretti
562da95f90 Bump fast-array-diff from 1.0.0 to 1.0.1 2021-09-14 18:37:32 +02:00
Riccardo Ferretti
fc03e07eeb removed extra file 2021-09-14 18:24:09 +02:00
Riccardo Ferretti
ccea5666bf fixed CI workflow (caching) 2021-09-14 18:23:39 +02:00
dannysemi
2a7a909ac5 Issue #530: Introduced DAT in dataviz view, and sending properties to it (#737)
* Introduced DAT.ui

* Sending properties and tags to graph for better data handling
2021-09-13 17:33:49 +02:00
Paul de Raaij
efac46174a Proposal and basic feature to include notes into a note (#741)
* Add the functionality to include notes in a note

* Add proposal of embedding

* Add tests for including notes

* Add documentation for inclusion feature
2021-09-13 17:23:40 +02:00
Riccardo Ferretti
4c5d996586 minor change in hash computation for CI 2021-09-13 17:17:28 +02:00
Jonas SPRENGER
6de0024b0b bugfix/705: replacing Indexable Types with Map (#729)
* bugfix/705: replacing Indexable Types with Map

* test for resources/placeholders named like JS proto properties

Co-authored-by: Jonas <jojo@srg.com>
2021-09-13 17:10:46 +02:00
allcontributors[bot]
70b0fae078 docs: add JonasSprenger as a contributor for code (#763)
* docs: update docs/index.md [skip ci]

* docs: update readme.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2021-09-06 23:31:54 +02:00
Jonas SPRENGER
fd9bf8f04f Implement hover feature for wikilinks (#728)
* Implement hover feature for wikilinks

* Make hover configuration reactive
2021-09-06 23:31:04 +02:00
allcontributors[bot]
630a77782d docs: add ksprashu as a contributor for doc (#756)
* docs: update docs/index.md [skip ci]

* docs: update readme.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2021-09-01 21:19:08 +02:00
Prashanth Subrahmanyam
6fdce389e9 Update recommended extensions based on template (#755) 2021-09-01 21:18:08 +02:00
allcontributors[bot]
9ce5a9528f docs: add theowenyoung as a contributor for doc, content (#753)
* docs: update docs/index.md [skip ci]

* docs: update readme.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2021-08-31 19:51:03 +02:00
Owen Young
ca821d3928 Add another gatsby template (#752)
Add foam-template-gatsby-theme-primer-wiki
2021-08-31 19:49:05 +02:00
allcontributors[bot]
9dacadedfc docs: add Pearcekieser as a contributor for doc (#750)
* docs: update docs/index.md [skip ci]

* docs: update readme.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2021-08-27 13:06:34 +02:00
Pearcekieser
0c07e7535e Add Recommended Extension: TODO Tree (#748)
issue: #740
2021-08-27 13:05:55 +02:00
Riccardo Ferretti
dddc379f2b fix 734: improved logging in markdown-provider 2021-07-28 11:51:38 +02:00
Riccardo
e83740d65a Tags improvements (#733)
* No longer parsing tags inside codeblocks

* fixed linting

* Using Tag data structure in Resource
2021-07-28 11:45:19 +02:00
Riccardo Ferretti
eddd9de665 foam-vscode to use latest foam-core 2021-07-25 15:57:31 +02:00
Riccardo Ferretti
7f6004dd6d v0.14.2 2021-07-24 10:20:31 +02:00
Riccardo Ferretti
1258cef04c Preparation for 0.14.2 2021-07-24 10:19:16 +02:00
Paul de Raaij
7adbffcfc2 Introduce autocompletion for tags (#708) 2021-07-24 00:10:42 +02:00
Michael Overmeyer
8395a408f2 Make navigating to a placeholder wikilink use the default template (#712) 2021-07-23 16:50:32 +02:00
Michael Overmeyer
721a6cc935 Standardize on wikilink, MediaWiki, and GitHub (#716)
* Standardize on `wikilink`

Not `wiki-link`, nor `wiki link`

https://en.wikipedia.org/wiki/Help:Link#Wikilinks

* Standardize on `MediaWiki`

Not `media-wiki`, nor `mediawiki`

https://www.mediawiki.org/wiki/MediaWiki

* Standardize on `GitHub`

Not `Github`

Co-authored-by: Riccardo <code@riccardoferretti.com>
2021-07-22 00:19:35 +02:00
Paul de Raaij
1659fe37d9 Respect the ignore globs when searching all files (#730) 2021-07-21 11:22:23 +02:00
Riccardo Ferretti
32f9120864 updated link to log output in bug template 2021-07-18 16:37:32 +02:00
Michael Overmeyer
cec0aecd06 Remove Markdown Notes from recommended extensions (#722) 2021-07-17 21:03:45 +02:00
Riccardo Ferretti
c59584d342 v0.14.1 2021-07-15 01:24:25 +02:00
Riccardo Ferretti
ea930d3d17 preparation for 0.14.1 2021-07-15 01:21:11 +02:00
Paul de Raaij
130b839ee9 Add a null check to prevent preview to break (#718) 2021-07-15 01:11:07 +02:00
Riccardo Ferretti
1b4dc8a8b1 v0.14.0 2021-07-13 13:50:25 +02:00
Riccardo Ferretti
7fcbf1acf1 Preparation for 0.14.0 2021-07-13 13:48:44 +02:00
Michael Overmeyer
011706904b Make daily notes use templates (#700) 2021-07-13 12:24:48 +02:00
Michael Overmeyer
c14e1e6349 Migrate create-from-template to use Foam's URI instead of VSCode's Uri (#709) 2021-07-12 23:24:21 +02:00
Paul de Raaij
97629a2ce6 Removes escape character of an alias when setting target (#697)
* Removes escape character of an alias when setting WikiLink target

* Alter tearDown of document-link-provider test

* Disable link reference defintion generation for all tests
2021-07-12 22:41:33 +02:00
Paul de Raaij
6b3eef43a8 Allows wikilinks to be opened in the editor again (#710) 2021-07-12 20:49:25 +02:00
Paul de Raaij
d4adce6730 Adds FAQ about enabling and disabling Foam (#706)
* Adss FAQ about enabling and disabling Foam

* Update frequently-asked-questions.md
2021-07-12 19:16:57 +02:00
allcontributors[bot]
ae65f53540 docs: add rafo as a contributor for doc (#703)
* docs: update docs/index.md [skip ci]

* docs: update readme.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2021-07-06 12:57:30 +02:00
Rafael Riedel
8998204298 Update recommended-extensions.md (#702)
Changed "Mermaid Support for Preview" to the extensions new name: "Markdown Preview Mermaid Support"
2021-07-06 12:56:46 +02:00
Michael Overmeyer
92f6e001e5 Fix implicit insertion of FOAM_SELECTED_TEXT (#701)
* Only do the insertion when necessary.
* Insert using the correct whitespace.
2021-07-06 00:37:39 +02:00
Paul de Raaij
889f93a7e1 Move selected text into a new note and auto create a backlink (#666)
template and functionality to use selected text in a new note
2021-07-04 20:44:22 +02:00
Paul de Raaij
4db8c55969 Only remove link definition token that contain an alias divider (#698)
* be more conservative in removing link definitions

* Update packages/foam-vscode/src/features/preview-navigation.ts

Co-authored-by: Riccardo <code@riccardoferretti.com>

Co-authored-by: Riccardo <code@riccardoferretti.com>
2021-07-04 20:38:52 +02:00
Riccardo Ferretti
7e740fec0f v0.13.8 2021-07-02 20:02:27 +02:00
Riccardo Ferretti
beae852c21 Prepare for next release 2021-07-02 19:48:52 +02:00
Paul de Raaij
85e857d973 handle different capitalizations of wikilinks and files (#688) 2021-07-02 19:41:24 +02:00
José Duarte
667eee0e10 Add documentation to the dated-notes.ts file (#690)
* Add docs to `createDailyNoteDirectoryIfNotExists`

* Add docs to `createDailyNoteIfNotExists`

* Capitalize doc strings

* Add docs to `getDailyNoteFileName`

* Update the @configuration parameter docs

* Add docs to `getDailyNotePath`

* Add docs to `openDailyNoteFor`

* Update packages/foam-vscode/src/dated-notes.ts

Co-authored-by: Michael Overmeyer <michael.overmeyer@shopify.com>

* Update packages/foam-vscode/src/dated-notes.ts

Co-authored-by: Michael Overmeyer <michael.overmeyer@shopify.com>

* Polish some of the comments

Co-authored-by: José Duarte <jmg.duarte@campus.fct.unl.pt!>
Co-authored-by: Michael Overmeyer <michael.overmeyer@shopify.com>
2021-06-28 14:55:14 +02:00
dependabot[bot]
b6e68b3605 Bump glob-parent from 5.1.1 to 5.1.2 in /packages/foam-core (#678)
Bumps [glob-parent](https://github.com/gulpjs/glob-parent) from 5.1.1 to 5.1.2.
- [Release notes](https://github.com/gulpjs/glob-parent/releases)
- [Changelog](https://github.com/gulpjs/glob-parent/blob/main/CHANGELOG.md)
- [Commits](https://github.com/gulpjs/glob-parent/compare/v5.1.1...v5.1.2)

---
updated-dependencies:
- dependency-name: glob-parent
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-24 23:57:34 +02:00
Paul de Raaij
b9b0f9b515 Allow for dots in wikilinks (#689) 2021-06-24 23:20:03 +02:00
dependabot[bot]
95399977ec Bump hosted-git-info from 2.8.8 to 2.8.9 (#686)
Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.8.8 to 2.8.9.
- [Release notes](https://github.com/npm/hosted-git-info/releases)
- [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md)
- [Commits](https://github.com/npm/hosted-git-info/compare/v2.8.8...v2.8.9)

---
updated-dependencies:
- dependency-name: hosted-git-info
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-21 18:15:13 +02:00
dependabot[bot]
f759e7cd6e Bump ws from 5.2.2 to 5.2.3 in /packages/foam-core (#685)
Bumps [ws](https://github.com/websockets/ws) from 5.2.2 to 5.2.3.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/compare/5.2.2...5.2.3)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-21 18:14:46 +02:00
Riccardo Ferretti
5839455535 fixed bug in date snippet
thanks to @syndenham-chorea for reporting and directing the fix
see https://discord.com/channels/729975036148056075/729975036664086560/855628250414972998
2021-06-21 00:28:45 +02:00
Riccardo Ferretti
7e4ae82fe1 updated foam-core dependency 2021-06-21 00:25:13 +02:00
Scott Bronson
e47155424f doc: describe how to select launch configuration (#674) 2021-06-12 00:19:57 +02:00
allcontributors[bot]
903a191394 docs: add bronson as a contributor for doc (#677)
* docs: update docs/index.md [skip ci]

* docs: update readme.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2021-06-12 00:17:33 +02:00
Scott Bronson
5c6212dc96 remove broken link to adding-a-new-command (#675)
This file was removed by deb77328c0 last Dec.
2021-06-12 00:16:05 +02:00
Paul de Raaij
bca9756e2b Revive support for basic link alias (#656)
* Add support for basic link aliases

* Refactor to future link model

* Refactor preview behavior for aliases

* Refactore use of NoteSource

* Remove references from ref block  before processing links

Co-authored-by: Jani Eväkallio <jani.evakallio@gmail.com>
2021-06-09 23:07:10 +02:00
Riccardo Ferretti
2e435a3828 v0.13.7 2021-06-05 15:53:16 +02:00
Riccardo Ferretti
a0f83e7510 refactored code to avoid circular dependency 2021-06-05 15:50:04 +02:00
Riccardo Ferretti
641024b01b added dependency on replace-ext (fix for #667 we hope..) 2021-06-05 15:49:34 +02:00
Riccardo Ferretti
c5a7d02656 include ES2019 library in tsconfig for vscode package 2021-06-05 15:30:35 +02:00
Riccardo Ferretti
b76196cd23 removed Foam local plugin experimental feature 2021-06-05 15:17:23 +02:00
Riccardo Ferretti
61ae468a70 v0.13.6 2021-06-05 14:58:22 +02:00
Riccardo Ferretti
6119278915 Removed support for Foam local plugins 2021-06-05 14:51:16 +02:00
173 changed files with 4197 additions and 14790 deletions

View File

@@ -697,6 +697,79 @@
"contributions": [
"code"
]
},
{
"login": "bronson",
"name": "Scott Bronson",
"avatar_url": "https://avatars.githubusercontent.com/u/1776?v=4",
"profile": "https://github.com/bronson",
"contributions": [
"doc"
]
},
{
"login": "rafo",
"name": "Rafael Riedel",
"avatar_url": "https://avatars.githubusercontent.com/u/41793?v=4",
"profile": "http://rafaelriedel.de",
"contributions": [
"doc"
]
},
{
"login": "Pearcekieser",
"name": "Pearcekieser",
"avatar_url": "https://avatars.githubusercontent.com/u/5055971?v=4",
"profile": "https://github.com/Pearcekieser",
"contributions": [
"doc"
]
},
{
"login": "theowenyoung",
"name": "Owen Young",
"avatar_url": "https://avatars.githubusercontent.com/u/62473795?v=4",
"profile": "https://github.com/theowenyoung",
"contributions": [
"doc",
"content"
]
},
{
"login": "ksprashu",
"name": "Prashanth Subrahmanyam",
"avatar_url": "https://avatars.githubusercontent.com/u/476729?v=4",
"profile": "http://www.prashu.com",
"contributions": [
"doc"
]
},
{
"login": "JonasSprenger",
"name": "Jonas SPRENGER",
"avatar_url": "https://avatars.githubusercontent.com/u/25108895?v=4",
"profile": "https://github.com/JonasSprenger",
"contributions": [
"code"
]
},
{
"login": "Laptop765",
"name": "Paul",
"avatar_url": "https://avatars.githubusercontent.com/u/1468359?v=4",
"profile": "https://github.com/Laptop765",
"contributions": [
"doc"
]
},
{
"login": "eltociear",
"name": "Ikko Ashimine",
"avatar_url": "https://avatars.githubusercontent.com/u/22633385?v=4",
"profile": "https://bandism.net/",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 7,

View File

@@ -1,20 +1,18 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/class-name-casing": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off",
"require-await": "warn"
}
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "import"],
"rules": {
"@typescript-eslint/class-name-casing": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off",
"require-await": "warn"
}
}

View File

@@ -20,4 +20,4 @@ labels: bug
Feel free to attach any of the following that might help with debugging the issue:
- screenshots
- a zip with a minimal repo to reproduce the issue
- the Foam log in VsCode (see [instructions](https://github.com/foambubble/foam/blob/master/docs/foam-logging-in-vscode.md))
- the Foam log in VsCode (see [instructions](https://github.com/foambubble/foam/blob/master/docs/features/foam-logging-in-vscode.md))

View File

@@ -3,17 +3,15 @@ name: CI
on:
push:
branches:
- '**'
# The following will also make the workflow run on all PRs, internal and external.
# This would create duplicate runs, that we are skipping by adding the "if" to the jobs below.
# See https://github.community/t/duplicate-checks-on-push-and-pull-request-simultaneous-event/18012
- master
pull_request:
branches:
- master
jobs:
lint:
name: Lint
runs-on: ubuntu-18.04
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'foambubble/foam'
steps:
- uses: actions/checkout@v1
- name: Setup Node
@@ -27,7 +25,7 @@ jobs:
node_modules
*/*/node_modules
packages/foam-vscode/.vscode-test
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('packages/foam-vscode/src/test/run-tests.ts') }}
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', 'packages/foam-vscode/src/test/run-tests.ts') }}-${{ secrets.CACHE_VERSION }}
- name: Install Dependencies
run: yarn
- name: Check Lint Rules
@@ -39,7 +37,6 @@ jobs:
matrix:
os: [macos-10.15, ubuntu-18.04, windows-2019]
runs-on: ${{ matrix.os }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'foambubble/foam'
env:
OS: ${{ matrix.os }}
steps:
@@ -55,12 +52,12 @@ jobs:
node_modules
*/*/node_modules
packages/foam-vscode/.vscode-test
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('packages/foam-vscode/src/test/run-tests.ts') }}
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', 'packages/foam-vscode/src/test/run-tests.ts') }}-${{ secrets.CACHE_VERSION }}
- name: Install Dependencies
run: yarn
- name: Build Packages
run: yarn build
- name: Run Tests
uses: GabrielBB/xvfb-action@v1.0
uses: GabrielBB/xvfb-action@v1.4
with:
run: yarn test

100
.vscode/launch.json vendored
View File

@@ -3,83 +3,29 @@
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"inputs": [
"version": "0.2.0",
"configurations": [
{
"id": "packageName",
"type": "pickString",
"description": "Select the package in which this test is located",
"options": ["foam-core", "foam-vscode"],
"default": "foam-core"
"type": "node",
"name": "Debug Jest Tests",
"request": "launch",
"runtimeArgs": ["workspace", "foam-vscode", "run", "test"], // ${yarnWorkspaceName} is what we're missing
"args": ["--runInBand"],
"runtimeExecutable": "yarn",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true
},
{
"name": "Run VSCode Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/packages/foam-vscode"
],
"outFiles": ["${workspaceFolder}/packages/foam-vscode/out/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
}
],
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"runtimeArgs": ["workspace", "${input:packageName}", "run", "test"], // ${yarnWorkspaceName} is what we're missing
"args": [
"--runInBand"
],
"runtimeExecutable": "yarn",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
},
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/tsdx",
"test",
],
"console": "integratedTerminal",
"cwd": "${workspaceFolder}/packages/foam-core",
"internalConsoleOptions": "neverOpen"
},
{
"name": "Run VSCode Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/packages/foam-vscode"
],
"outFiles": [
"${workspaceFolder}/packages/foam-vscode/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
// @NOTE: This task is broken. VSCode e2e tests are currently disabled
// due to incompability of jest and mocha inside a typescript monorepo
// Contributions to fix this are welcome!
{
"name": "Test VSCode Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/packages/foam-vscode",
"--extensionTestsPath=${workspaceFolder}/packages/foam-vscode/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/packages/foam-vscode/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Test Core",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/tsdx/dist/index.js",
"args": ["test"],
"cwd": "${workspaceFolder}/packages/foam-core",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "${defaultBuildTask}"
}
]
]
}

View File

@@ -12,6 +12,7 @@
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"foam.edit.linkReferenceDefinitions": "withExtensions",
"foam.files.ignore": [
"**/.vscode/**/*",
"**/_layouts/**/*",

54
.vscode/tasks.json vendored
View File

@@ -1,31 +1,31 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"label": "watch: foam-vscode",
"type": "npm",
"script": "start:vscode",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "always"
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "test: all packages",
"type": "npm",
"script": "test",
"problemMatcher": [],
"group": {
"kind": "test",
"isDefault": true
},
}
]
"version": "2.0.0",
"tasks": [
{
"label": "watch: foam-vscode",
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "always"
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "test: all packages",
"type": "npm",
"script": "test",
"problemMatcher": [],
"group": {
"kind": "test",
"isDefault": true
}
}
]
}

View File

@@ -14,9 +14,6 @@
// Tons of markdown goodies (lists, tables of content, so much more)
"yzhang.markdown-all-in-one",
// [[wiki-links]], backlinking etc
"kortina.vscode-markdown-notes",
// Graph visualizer
"tchayen.markdown-links",

View File

@@ -19,21 +19,21 @@ window.addEventListener('DOMContentLoaded', (event) => {
document
.querySelectorAll(".markdown-body a[title]:not([href^=http])")
.forEach((a) => {
// filter to only wiki-links
// filter to only wikilinks
var prev = a.previousSibling;
var next = a.nextSibling;
if (
prev instanceof Text && prev.textContent.endsWith('[') &&
prev instanceof Text && prev.textContent.endsWith('[') &&
next instanceof Text && next.textContent.startsWith(']')
) {
// remove surrounding brackets
prev.textContent = prev.textContent.slice(0, -1);
next.textContent = next.textContent.slice(1);
// add CSS list for styling
a.classList.add('wikilink');
// replace page-link with "Page Title"...
a.innerText = a.title;

View File

@@ -18,8 +18,6 @@ Before you start contributing we recommend that you read the following links:
We understand that diving in an unfamiliar codebase may seem scary,
to make it easier for new contributors we provide some resources:
- [[architecture]] - This document describes the architecture of Foam and how the repository is structured.
You can also see [existing issues](https://github.com/foambubble/foam/issues) and help out!
Finally, the easiest way to help, is to use it and provide feedback by [submitting issues](https://github.com/foambubble/foam/issues/new/choose) or participating in the [Foam Community Discord](https://foambubble.github.io/join-discord/g)!
@@ -35,37 +33,59 @@ If you're interested in contributing, this short guide will help you get things
`yarn install`
3. This project uses [Yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/). `foam-vscode` relies on `foam-core`. This means we need to compile it before we do any extension development. From the root, run the command:
3. From the root, run the command:
`yarn build`
You should now be ready to start working!
### Structure of the project
Foam code and documentation live in the monorepo at [foambubble/foam](https://github.com/foambubble/foam/).
- [/docs](https://github.com/foambubble/foam/tree/master/docs): documentation and [[recipes]].
Exceptions to the monorepo are:
- The starter template at [foambubble/foam-template](https://github.com/foambubble/)
- All other [[recommended-extensions]] live in their respective GitHub repos
This project uses [Yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/).
Originally Foam had:
- [/packages/foam-core](https://github.com/foambubble/foam/tree/master/packages/foam-core) - Powers the core functionality in Foam across all platforms.
- [/packages/foam-vscode](https://github.com/foambubble/foam/tree/master/packages/foam-vscode) - The core VS Code plugin.
To improve DX we have moved the `foam-core` module into `packages/foam-vscode/src/core`, but from a development point of view it's useful to think of the `foam-vscode/src/core` "submodule" as something that might be extracted in the future.
For all intents and purposes this means two things:
1. nothing in `foam-vscode/src/core` should depend on files outside of this directory
2. code in `foam-vscode/src/core` should NOT depend on `vscode` library
We have kept the yarn workspace for the time being as we might use it to pull out `foam-core` in the future, or we might need it for other packages that the VS Code plugin could depend upon (e.g. currently the graph visualization is inside the module, but it might be pulled out if its complexity increases).
### Testing
Code needs to come with tests.
We use the following convention in Foam:
- *.test.ts are unit tests
- *.spec.ts are integration tests
- `*.test.ts` are unit tests
- `*.spec.ts` are integration tests
Also, note that tests in `foam-core` live in the `test` directory.
Tests in `foam-vscode` live alongside the code in `src`.
Tests live alongside the code in `src`.
### The VS Code Extension
This guide assumes you read the previous instructions and you're set up to work on Foam.
1. Now we'll use the launch configuration defined at [`.vscode/launch.json`](https://github.com/foambubble/foam/blob/master/.vscode/launch.json) to start a new extension host of VS Code. From the root, or the `foam-vscode` workspace, press f5.
1. Now we'll use the launch configuration defined at [`.vscode/launch.json`](https://github.com/foambubble/foam/blob/master/.vscode/launch.json) to start a new extension host of VS Code. Open the "Run and Debug" Activity (the icon with the bug on the far left) and select "Run VSCode Extension" in the pop-up menu. Now hit F5 or click the green arrow "play" button to fire up a new copy of VS Code with your extension installed.
2. In the new extension host of VS Code that launched, open a Foam workspace (e.g. your personal one, or a test-specific one created from [foam-template](https://github.com/foambubble/foam-template)). This is strictly not necessary, but the extension won't auto-run unless it's in a workspace with a `.vscode/foam.json` file.
3. Test a command to make sure it's working as expected. Open the Command Palette (Ctrl/Cmd + Shift + P) and select "Foam: Update Markdown Reference List". If you see no errors, it's good to go!
For more resources related to the VS Code Extension, check out the links below:
- [[tutorial-adding-a-new-command-to-the-vs-code-extension]]
---
Feel free to modify and submit a PR if this guide is out-of-date or contains errors!
@@ -75,5 +95,6 @@ Feel free to modify and submit a PR if this guide is out-of-date or contains err
[//begin]: # "Autogenerated link references for markdown compatibility"
[principles]: principles.md "Principles"
[code-of-conduct]: code-of-conduct.md "Code of Conduct"
[architecture]: dev/architecture.md "Architecture"
[recipes]: recipes/recipes.md "Recipes"
[recommended-extensions]: recommended-extensions.md "Recommended Extensions"
[//end]: # "Autogenerated link references"

View File

@@ -1,23 +0,0 @@
---
tags: architecture
---
# Architecture
This document aims to provide a quick overview of the Foam architecture!
Foam code and documentation live in the monorepo at [foambubble/foam](https://github.com/foambubble/foam/).
- [/docs](https://github.com/foambubble/foam/tree/master/docs): documentation and [[recipes]].
- [/packages/foam-core](https://github.com/foambubble/foam/tree/master/packages/foam-core) - Powers the core functionality in Foam across all platforms.
- [/packages/foam-vscode](https://github.com/foambubble/foam/tree/master/packages/foam-vscode) - The core VSCode plugin.
Exceptions to the monorepo are:
- The starter template at [foambubble/foam-template](https://github.com/foambubble/)
- All other [[recommended-extensions]] live in their respective GitHub repos.
- [foam-cli](https://github.com/foambubble/foam-cli) - The Foam CLI tool.
[//begin]: # "Autogenerated link references for markdown compatibility"
[recipes]: ../recipes/recipes.md "Recipes"
[recommended-extensions]: ../recommended-extensions.md "Recommended Extensions"
[//end]: # "Autogenerated link references"

View File

@@ -17,7 +17,7 @@
`foam-core`'s primary responsibility is to build an API on top of a workspace of markdown files, which allows us to:
- Treat files as a graph, based on links
- Can be either [[wiki-links]] or relative `[markdown](links.md)` style
- Can be either [[wikilinks]] or relative `[markdown](links.md)` style
- We need to know about the edges (connections) as well as nodes
- What link points to what other file, etc.
- Needs to have the exact link text, e.g. even if `[[some-page]]` or `[[some-page.md]]` or `[[Some Page]]` point to the same document (`./some-page.md`), we need to know which format was used, so [[link-reference-definitions]] can be generated correctly
@@ -61,7 +61,7 @@ Here are some example use cases that the core should support. They don't need to
- Adding and editing page content
- [[materialized-backlinks]]
- [[link-reference-definitions]] for [[wiki-links]]
- [[link-reference-definitions]] for [[wikilinks]]
- [Frontmatter](https://jekyllrb.com/docs/front-matter/)
- Finding all documents with `#tag`
- Finding all documents with instances of `[[link]]`
@@ -99,7 +99,7 @@ Useful for knowing what needs to be supported. See [[feature-comparison]].
[workspace-janitor]: ../features/workspace-janitor.md "Janitor"
[cli]: ../features/cli.md "Command Line Interface"
[build-vs-assemble]: build-vs-assemble.md "Build vs Assemble"
[wiki-links]: ../wiki-links.md "Wiki Links"
[wikilinks]: ../wikilinks.md "Wikilinks"
[link-reference-definitions]: ../features/link-reference-definitions.md "Link Reference Definitions"
[materialized-backlinks]: materialized-backlinks.md "Materialized Backlinks (stub)"
[todo]: todo.md "Todo"

View File

@@ -1,16 +1,16 @@
# Foam File Format
This file is an example of a valid Foam file. Essentially it's just a markdown file with a bit of additional support for mediawiki-style `[[wiki-links]]`.
This file is an example of a valid Foam file. Essentially it's just a markdown file with a bit of additional support for MediaWiki-style `[[wikilinks]]`.
Here are a few specific constraints, mainly because our tooling is a bit fragmented. Most of these should be eventually lifted, and our requirement should just be "Markdown with `[[wiki-links]]`:
Here are a few specific constraints, mainly because our tooling is a bit fragmented. Most of these should be eventually lifted, and our requirement should just be "Markdown with `[[wikilinks]]`:
- **The first top level `# Heading` will be used as title for the note.**
- If not available, we will use the file name
- **File name should have extension `.md`**
- This is a temporary limitation and will be lifted in future versions.
- At least `.mdx` will be supported, but ideally we'll support any file that you can map to `Markdown` language mode in VS Code
- **In addition to normal Markdown Links syntax you can use `[[media-wiki]]` links.** See [[wiki-links]] for more details.
- **In addition to normal Markdown Links syntax you can use `[[MediaWiki]]` links.** See [[wikilinks]] for more details.
[//begin]: # "Autogenerated link references for markdown compatibility"
[wiki-links]: ../wiki-links.md "Wiki Links"
[wikilinks]: ../wikilinks.md "Wikilinks"
[//end]: # "Autogenerated link references"

View File

@@ -4,13 +4,13 @@
### File-by-file Insertion
For the time being, if you want to get [[wiki-links]] into all files within the workspace, you'll need to generate the link reference definitions yourself file-by-file (with the assistance of Foam).
For the time being, if you want to get [[wikilinks]] into all files within the workspace, you'll need to generate the link reference definitions yourself file-by-file (with the assistance of Foam).
### Wikilinks don't work on GitHub
> **TL;DR;** [workaround](#workaround) in the end of the chapter.
If you click any of the wiki-links on GitHub web UI (such as the `README.md` of a project), you'll notice that the links break with a 404 error.
If you click any of the wikilinks on GitHub web UI (such as the `README.md` of a project), you'll notice that the links break with a 404 error.
At the time of writing (June 28 2020) this is a known, but unsolved error. To understand why this is the case, we need to understand what we are trading off.
@@ -59,7 +59,7 @@ Problem space in essence:
- may clutter the search results
- During build-time (when converting markdown to html for publishing purposes)
- link reference definitions are needed, if the files are published via such tools (or to such platforms) that don't understand wikilinks
- link reference definitions might have to be in different formats depending on the publish target (e.g. Github pages vs Github UI)
- link reference definitions might have to be in different formats depending on the publish target (e.g. GitHub pages vs GitHub UI)
The potential solution:
@@ -122,8 +122,8 @@ The potential solution:
```
- With Foam repo, just use edit-time link reference definitions with '.md' extension - this makes the links work in the Github UI
- Have publish target defined for Github pages, that doesn't use '.md' extension, but still has the link reference definitions. Generate the output into gh-pages branch (or separate repo) with automation.
- With Foam repo, just use edit-time link reference definitions with '.md' extension - this makes the links work in the GitHub UI
- Have publish target defined for GitHub pages, that doesn't use '.md' extension, but still has the link reference definitions. Generate the output into gh-pages branch (or separate repo) with automation.
- This naturally requires first removing the existing link reference definitions during the build
- Other
- To clean up the search results, remove link reference definition section guards (assuming that these are not defined by the markdown spec). Use unifiedjs parse trees to identify if there's missing (or surplus) definitions (check if they are identified properly by the library), and just add the needed definitions to the bottom of the file (without guards) AND remove them if they are not needed (anywhere from the file).
@@ -137,7 +137,7 @@ UI-wise, the publish targets could be picked in some similar fashion as the run/
- [tracking issue on GitHub](https://github.com/foambubble/foam/issues/16)
[//begin]: # "Autogenerated link references for markdown compatibility"
[wiki-links]: ../wiki-links.md "Wiki Links"
[wikilinks]: ../wikilinks.md "Wikilinks"
[link-reference-definitions]: ../features/link-reference-definitions.md "Link Reference Definitions"
[backlinking]: ../features/backlinking.md "Backlinking"
[//end]: # "Autogenerated link references"

View File

@@ -25,7 +25,7 @@ If a roadmap item is a stub, **consider** opening a [GitHub issue](https://githu
- [[improve-default-workspace-settings]]
- Discussion: [foam#270](https://github.com/foambubble/foam/issues/270)
- Improve [[git-integration]]
- Fix [[wiki-links]] compatibility issues
- Fix [[wikilinks]] compatibility issues
- Simplify [[foam-file-format]]
### Core features
@@ -87,7 +87,7 @@ The community is working on a number of automated scripts to help you migrate to
[recipes]: ../recipes/recipes.md "Recipes"
[contribution-guide]: ../contribution-guide.md "Contribution Guide"
[git-integration]: ../features/git-integration.md "Git Integration"
[wiki-links]: ../wiki-links.md "Wiki Links"
[wikilinks]: ../wikilinks.md "Wikilinks"
[foam-file-format]: foam-file-format.md "Foam File Format"
[unlinked-references]: unlinked-references.md "Unlinked references (stub)"
[make-backlinks-more-prominent]: ../recipes/make-backlinks-more-prominent.md "Make Backlinks More Prominent"

View File

@@ -1,6 +1,6 @@
# Backlinking
When using [[wiki-links]], you can find all notes that link to a specific note in the [VS Code Markdown Notes](https://marketplace.visualstudio.com/items?itemName=kortina.vscode-markdown-notes) **Backlinks Explorer**
When using [[wikilinks]], you can find all notes that link to a specific note in the [VS Code Markdown Notes](https://marketplace.visualstudio.com/items?itemName=kortina.vscode-markdown-notes) **Backlinks Explorer**
- Run `Cmd` + `Shift` + `P` (`Ctrl` + `Shift` + `P` for Windows), type "backlinks" and run the **Explorer: Focus on Backlinks** view.
- Keep this pane always visible to discover relationships between your thoughts
@@ -8,7 +8,7 @@ When using [[wiki-links]], you can find all notes that link to a specific note i
- Finding backlinks in published Foam workspaces via [[materialized-backlinks]] is on the [[roadmap]] but not yet implemented.
[//begin]: # "Autogenerated link references for markdown compatibility"
[wiki-links]: ../wiki-links.md "Wiki Links"
[wikilinks]: ../wikilinks.md "Wikilinks"
[make-backlinks-more-prominent]: ../recipes/make-backlinks-more-prominent.md "Make Backlinks More Prominent"
[materialized-backlinks]: ../dev/materialized-backlinks.md "Materialized Backlinks (stub)"
[roadmap]: ../dev/roadmap.md "Roadmap"

View File

@@ -1,6 +1,6 @@
# Creating New Notes
- Write out a new `[[wiki-link]]` and `Cmd` + `Click` to create a new file and enter it.
- Write out a new `[[wikilink]]` and `Cmd` + `Click` to create a new file and enter it.
- For keyboard navigation, use the 'Follow Definition' key `F12` (or [remap key binding](https://code.visualstudio.com/docs/getstarted/keybindings) to something more ergonomic)
- `Cmd` + `Shift` + `P` (`Ctrl` + `Shift` + `P` for Windows), execute `Foam: Create New Note` and enter a **Title Case Name** to create `Title Case Name.md`
- Add a keyboard binding to make creating new notes easier.

View File

@@ -13,3 +13,19 @@ For example, to load a stylesheet called `Style.css`, we can update `settings.js
"markdown.styles": ["Style.css"]
}
```
## Foam elements
### Foam note & placeholder links
It is possible to custom style the links to a note or placeholder. The links are an `<a>` tag. For notes use the class `foam-note-link`, for placeholders use `foam-placeholder-link`.
### Cyclic inclusion warnings
Foams offers the functionality to include other notes in your note. This will be displayed in the preview tab. Foam recognises a cyclic inclusion of notes and will display a warning when detected. The following html is used and can be custom styled using the class `foam-cyclic-link-warning`.
```html
<div class="foam-cyclic-link-warning">
Cyclic link detected for wikilink: ${wikilink}
</div>
```

View File

@@ -25,9 +25,9 @@ The above configuration would create a file `journal/note-2020-07-25.mdx`, with
## Daily Note Templates
In the future, Foam may provide a functionality for specifying a template for new Daily Notes and other types of documents.
Daily notes can also make use of [templates](note-templates.md), by defining a special `.foam/templates/daily-note.md` template.
In the meantime, you can use [VS Code Snippets](https://code.visualstudio.com/docs/editor/userdefinedsnippets) for defining your own Daily Note template.
See [Note Templates](note-templates.md) for details of the features available in templates.
## Roam-style Automatic Daily Notes

View File

@@ -1,60 +0,0 @@
# Foam Local Plugins
Foam can use workspace plugins to provide customization for users.
## ATTENTION
This feature is experimental and its API subject to change.
**Local plugins can execute arbitrary code on your machine** - ensure you trust the content of the repo.
## Goal
Here are some of the things that we could enable with local plugins in Foam:
- extend the document syntax to support roam style attributes (e.g. `stage:: seedling`)
- automatically add tags to my notes based on the location in the repo (e.g. notes in `/areas/finance` will automatically get the `#finance` tag)
- add a new CLI command to support some internal use case or automate import/export
- extend the VSCode experience to support one's own workflow, e.g. weekly note, templates, extra panels, foam model derived TOC, ... all without having to write/deploy a VSCode extension
## How to enable local plugins
Plugins can execute arbitrary code on the client's machine.
For this reason this feature is disabled by default, and needs to be explicitly enabled.
To enable the feature:
- create a `~/.foam/config.json` file
- add the following content to the file
```
{
"experimental": {
"localPlugins": {
"enabled": true
}
}
}
```
For security reasons this setting can only be defined in the user settings file.
(otherwise a malicious repo could set it via its `./foam/config.json`)
- [[todo]] an additional security mechanism would involve having an explicit list of whitelisted repo paths where plugins are allowed. This would provide finer grain control over when to enable or disable the feature.
## Technical approach
When Foam is loaded it will check whether the experimental local plugin feature is enabled, and in such case it will:
- check `.foam/plugins` directory.
- each directory in there is considered a plugin
- the layout of each directory is
- `index.js` contains the main info about the plugin, specifically it exports:
- `name: string` the name of the plugin
- `description?: string` the description of the plugin
- `parser?: ParserPlugin` an object that interacts with the markdown parsing phase
Currently for simplicity we keep everything in one file. We might in the future split the plugin by domain (e.g. vscode, cli, core, ...)
[//begin]: # 'Autogenerated link references for markdown compatibility'
[todo]: ../dev/todo.md 'Todo'
[//end]: # 'Autogenerated link references'

View File

@@ -0,0 +1,20 @@
# Including notes in a note
In some situations it might be useful to include the content of another note in your current note. Foam supports this displaying within the vscode environment. Note, this does not work out-of-the-box for your publishing solutions.
## Including a note
Including a note can be done by adding an `!` before a wikilink defintion. For example `![[wikilink]]`.
## Custom styling
Displaying the inclusion of notes allows for some custom styling, see [[custom-markdown-preview-styles]]
## Future possibilities
Work on this feature is evolving and progressing. See the [[inclusion-of-notes]] proposal for the current discussion.
[//begin]: # "Autogenerated link references for markdown compatibility"
[custom-markdown-preview-styles]: custom-markdown-preview-styles.md "Custom Markdown Preview Styles"
[inclusion-of-notes]: ../proposals/inclusion-of-notes.md "Inclusion of notes Proposal "
[//end]: # "Autogenerated link references"

View File

@@ -2,22 +2,22 @@
## Introduction
When you use `[[wiki-links]]`, the [foam-vscode](https://github.com/foambubble/foam/tree/master/packages/foam-vscode) extension will automatically generate [Markdown Link Reference Definitions](https://spec.commonmark.org/0.29/#link-reference-definitions) at the bottom of the file. This is done to make the content of the file compatible with various Markdown tools (e.g. parsers, static site generators, VS code plugins etc), which don't support `[[wiki-links]]`.
When you use `[[wikilinks]]`, the [foam-vscode](https://github.com/foambubble/foam/tree/master/packages/foam-vscode) extension will automatically generate [Markdown Link Reference Definitions](https://spec.commonmark.org/0.29/#link-reference-definitions) at the bottom of the file. This is done to make the content of the file compatible with various Markdown tools (e.g. parsers, static site generators, VS code plugins etc), which don't support `[[wikilinks]]`.
## Example
The following example:
```md
- [[wiki-links]]
- [[wikilinks]]
- [[github-pages]]
```
...generates the following link reference definitions to the bottom of the file:
```md
[wiki-links]: wiki-links "Wiki Links"
[github-pages]: github-pages "Github Pages"
[wikilinks]: wikilinks "Wikilinks"
[github-pages]: github-pages "GitHub Pages"
```
You can open the [raw markdown](https://foambubble.github.io/foam/features/link-reference-definitions.md) to see them at the bottom of this file
@@ -26,7 +26,7 @@ You can open the [raw markdown](https://foambubble.github.io/foam/features/link-
The three components of a link reference definition are `[link-label]: link-target "Link Title"`
- **link label:** The link text to match in the surrounding markdown document. This matches the inner bracket of the double-bracketed `[[wiki-link]]` notation
- **link label:** The link text to match in the surrounding markdown document. This matches the inner bracket of the double-bracketed `[[wikilink]]` notation
- **link destination** The target of the matched link
- By default we generate links without extension. This can be overridden, see [Configuration](#configuration) below
- **"Link Title"** Optional title for link (The Foam template has a snippet of JavaScript to replace this on the website at runtime)

View File

@@ -24,22 +24,59 @@ To create a note from a template:
_Theme: Ayu Light_
## Default template
## Special templates
### Default template
The `.foam/templates/new-note.md` template is special in that it is the template that will be used by the `Foam: Create New Note` command.
Customize this template to contain content that you want included every time you create a note.
### Default daily note template
The `.foam/templates/daily-note.md` template is special in that it is the template that will be used when creating daily notes (e.g. by using `Foam: Open Daily Note`).
Customize this template to contain content that you want included every time you create a daily note.
## Variables
Templates can use all the variables available in [VS Code Snippets](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables).
In addition, you can also use variables provided by Foam:
| Name | Description |
| ------------ | ----------------------------------------------------------------------------------- |
| `FOAM_TITLE` | The title of the note. If used, Foam will prompt you to enter a title for the note. |
| Name | Description |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `FOAM_SELECTED_TEXT` | Foam will fill it with selected text when creating a new note, if any text is selected. Selected text will be replaced with a wikilink to the new note. |
| `FOAM_TITLE` | The title of the note. If used, Foam will prompt you to enter a title for the note. |
| `FOAM_DATE_*` | `FOAM_DATE_YEAR`, `FOAM_DATE_MONTH`, etc. Foam-specific versions of [VS Code's datetime snippet variables](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables). Prefer these versions over VS Code's. |
**Note:** neither the defaulting feature (eg. `${variable:default}`) nor the format feature (eg. `${variable/(.*)/${1:/upcase}/}`) (available to other variables) are available for these Foam-provided variables.
**Note:** neither the defaulting feature (eg. `${variable:default}`) nor the format feature (eg. `${variable/(.*)/${1:/upcase}/}`) (available to other variables) are available for these Foam-provided variables. See [#693](https://github.com/foambubble/foam/issues/693).
### `FOAM_DATE_*` variables
Foam defines its own set of datetime variables that have a similar behaviour as [VS Code's datetime snippet variables](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables).
For example, `FOAM_DATE_YEAR` has the same behaviour as VS Code's `CURRENT_YEAR`, `FOAM_DATE_SECONDS_UNIX` has the same behaviour as `CURRENT_SECONDS_UNIX`, etc.
By default, prefer using the `FOAM_DATE_` versions. The datetime used to compute the values will be the same for both `FOAM_DATE_` and VS Code's variables, with the exception of the creation notes using the daily note template.
#### Relative daily notes
When referring to daily notes, you can use the relative snippets (`/+1d`, `/tomorrow`, etc.). In these cases, the new notes will be created with the daily note template, but the datetime used should be the relative datetime, not the current datetime.
By using the `FOAM_DATE_` versions of the variables, the correct relative date will populate the variables, instead of the current datetime.
For example, given this daily note template (`.foam/templates/daily-note.md`):
```markdown
# $FOAM_DATE_YEAR-$FOAM_DATE_MONTH-$FOAM_DATE_DATE
## Here's what I'm going to do today
* Thing 1
* Thing 2
```
When the `/tomorrow` snippet is used, `FOAM_DATE_` variables will be populated with tomorrow's date, as expected.
If instead you were to use the VS Code versions of these variables, they would be populated with today's date, not tomorrow's, causing unexpected behaviour.
When creating notes in any other scenario, the `FOAM_DATE_` values are computed using the same datetime as the VS Code ones, so the `FOAM_DATE_` versions can be used in all scenarios by default.
## Metadata
@@ -58,6 +95,8 @@ Foam-specific variables (e.g. `$FOAM_TITLE`) can be used within template metadat
The `filepath` metadata attribute allows you to define a relative or absolute filepath to use when creating a note using the template.
If the filepath is a relative filepath, it is relative to the current workspace.
**Note:** While you can make use of the `filepath` attribute in [daily note](daily-notes.md) templates (`.foam/templates/daily-note.md`), there is currently no way to have `filepath` vary based on the date. This will be improved in the future. For now, you can customize the location of daily notes using the [`foam.openDailyNote` settings](daily-notes.md).
#### Example of relative `filepath`
For example, `filepath` can be used to customize `.foam/templates/new-note.md`, overriding the default `Foam: Create New Note` behaviour of opening the file in the same directory as the active file:

View File

@@ -4,15 +4,19 @@
- [Frequently Asked Questions](#frequently-asked-questions)
- [Links/Graphs/BackLinks don't work. How do I enable them?](#linksgraphsbacklinks-dont-work-how-do-i-enable-them)
- [I don't want Foam enabled for all my workspaces](#i-dont-want-foam-enabled-for-all-my-workspaces)
## Links/Graphs/BackLinks don't work. How do I enable them?
- Ensure that you have all the [[recommended-extensions]] installed in Visual Studio Code
- Reload Visual Studio Code by running `Cmd` + `Shift` + `P` (`Ctrl` + `Shift` + `P` for Windows), type "reload" and run the **Developer: Reload Window** command to for the updated extensions take effect
- Check the formatting rules for links on [[foam-file-format]], [[wiki-links]] and [[link-formatting-and-autocompletion]]
- Check the formatting rules for links on [[foam-file-format]], [[wikilinks]] and [[link-formatting-and-autocompletion]]
## I don't want Foam enabled for all my workspaces
Any extension you install in Visual Studio Code is enabled by default. Give the philosophy of Foam it works out of the box without doing any configuration upfront. In case you want to disable Foam for a specific workspace, or disable Foam by default and enable it for specific workspaces, it is advised to follow the best practices as [documented by Visual Studio Code](https://code.visualstudio.com/docs/editor/extension-marketplace#_manage-extensions)
[//begin]: # "Autogenerated link references for markdown compatibility"
[recommended-extensions]: recommended-extensions.md "Recommended Extensions"
[foam-file-format]: dev/foam-file-format.md "Foam File Format"
[wiki-links]: wiki-links.md "Wiki Links"
[wikilinks]: wikilinks.md "Wikilinks"
[//end]: # "Autogenerated link references"

View File

@@ -19,7 +19,7 @@ Uncategorised thoughts, to be added
- <https://code.visualstudio.com/api/extension-guides/notebook>
- Future architecture
- Could we do publish-related settings as a pre-push git hook, e.g. generating footnote labels
- Running them on Github Actions to edit stuff as it comes in
- Running them on GitHub Actions to edit stuff as it comes in
- Ideally, we shouldn't have to touch files, should be just markdown
- Looking at the errors/warnings/output panes makes me think, what kind of automated quality tools could we write.
- Deduplication, finding similarities...

View File

@@ -37,7 +37,7 @@ Whether you want to build a [Second Brain](https://www.buildingasecondbrain.com/
1. Create a single **Foam** workspace for all your knowledge and research following the [Getting started](#getting-started) guide.
2. Write your thoughts in markdown documents (I like to call them **Bubbles**, but that might be more than a little twee). These documents should be atomic: Put things that belong together into a single document, and limit its content to that single topic. ([source](https://zettelkasten.de/posts/overview/#principles))
3. Use Foam's shortcuts and autocompletions to link your thoughts together with `[[wiki-links]]`, and navigate between them to explore your knowledge graph.
3. Use Foam's shortcuts and autocompletions to link your thoughts together with `[[wikilinks]]`, and navigate between them to explore your knowledge graph.
4. Get an overview of your **Foam** workspace using a [[graph-visualisation]] (⚠️ WIP), and discover relationships between your thoughts with the use of [[backlinking]].
Foam is a like a bathtub: _What you get out of it depends on what you put into it._
@@ -72,6 +72,8 @@ These instructions assume you have a GitHub account, and you have Visual Studio
After setting up the repository, open `.vscode/settings.json` and edit, add or remove any settings you'd like for your Foam workspace.
* *If using a [multi-root workspace](https://code.visualstudio.com/docs/editor/multi-root-workspaces) as noted above, make sure that your **Foam** directory is first in the list. There are some settings that will need to be migrated from `.vscode/settings.json` to your `.code-workspace` file.*
To learn more about how to use **Foam**, read the [[recipes]].
Getting stuck in the setup? Read the [[frequently-asked-questions]].
@@ -202,6 +204,16 @@ If that sounds like something you're interested in, I'd love to have you along o
<td align="center"><a href="https://github.com/Barabazs"><img src="https://avatars.githubusercontent.com/u/31799121?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Barabas</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=Barabazs" title="Code">💻</a></td>
<td align="center"><a href="http://enginveske@gmail.com"><img src="https://avatars.githubusercontent.com/u/43685404?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Engincan VESKE</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=EngincanV" title="Documentation">📖</a></td>
<td align="center"><a href="http://www.paulderaaij.nl"><img src="https://avatars.githubusercontent.com/u/495374?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Paul de Raaij</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=pderaaij" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/bronson"><img src="https://avatars.githubusercontent.com/u/1776?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Scott Bronson</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=bronson" title="Documentation">📖</a></td>
<td align="center"><a href="http://rafaelriedel.de"><img src="https://avatars.githubusercontent.com/u/41793?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Rafael Riedel</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=rafo" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/Pearcekieser"><img src="https://avatars.githubusercontent.com/u/5055971?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Pearcekieser</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=Pearcekieser" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/theowenyoung"><img src="https://avatars.githubusercontent.com/u/62473795?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Owen Young</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=theowenyoung" title="Documentation">📖</a> <a href="#content-theowenyoung" title="Content">🖋</a></td>
<td align="center"><a href="http://www.prashu.com"><img src="https://avatars.githubusercontent.com/u/476729?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Prashanth Subrahmanyam</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=ksprashu" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/JonasSprenger"><img src="https://avatars.githubusercontent.com/u/25108895?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Jonas SPRENGER</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=JonasSprenger" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/Laptop765"><img src="https://avatars.githubusercontent.com/u/1468359?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Paul</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=Laptop765" title="Documentation">📖</a></td>
<td align="center"><a href="https://bandism.net/"><img src="https://avatars.githubusercontent.com/u/22633385?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Ikko Ashimine</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=eltociear" title="Documentation">📖</a></td>
</tr>
</table>

View File

@@ -0,0 +1,48 @@
# Inclusion of notes Proposal <!-- omit in TOC -->
Currently it is not possible within Foam to include other notes into a note. Next to including a full note it could be interesting to add functionalities that allow for greater flexibility. This proposal discusses some functionalities around inclusion of notes.
**IMPORTANT: This design is merely a proposal of a design that could be implemented. It DOES NOT represent a commitment by `Foam` developers to implement the features outlined in this document. This document is merely a mechanism to facilitate discussion of a possible future direction for `Foam`.**
- [Introduction](#introduction)
- [New features](#new-features)
- [Including a note](#including-a-note)
- [Include a section of a note](#include-a-section-of-a-note)
- [Include an attribute of a file (note property or frontmatter)](#include-an-attribute-of-a-file-note-property-or-frontmatter)
## Introduction
Initial work and thought on including a note was ignited by issue [#652](https://github.com/foambubble/foam/issues/652). Requested by a user was a likewise functionality as offered in Obsidian. This was simply the ability to include a note.
Whilst researching digital gardening for my own setup, I came across an in-depth overview by [Maggie Appleton](https://maggieappleton.com/roam-garden). Showing examples of her personal Roam Research I see valuable possibilites to connect more information, if we would add additional functionalities to the possibility of including a note. This proposal displays these possible functionalities and markup.
## New features
### Including a note
The minimal functionality is the ability to fully include a note. Markup used in Obsidian for this is `![[wikilink]]`. For Foam I would suggest to follow this syntax. Benefits being:
- Adds minimal amount of knowledge required as syntax is based on the syntax of creating a wikilink.
- Makes the auto-complete work ouf-of-the-box, without any additional code and listeners required.
**Important**. A risk exists that a loop of including the same notes arises. E.g. Note A includes note B which includes note A. This needs to be prevented by the implementation and made visible to the user.
### Include a section of a note
It could be interesting to only include a section of a note instead of the entire note. In order to do so thse user should be able to use the following syntax:
`![[wikilink#section-b]]`
As a result it will include the section title + section content until the next section *or* end of file.
### Include an attribute of a file (note property or frontmatter)
As a user I could be interested in collecting the value of any given proeprty for a note. For example, I might want to include the tags as defined in the frontmatter of note A. This should be possible via the syntax:
`![[wikilink:<property>]]`
The property value should be lookedup by foam defined properties, e.g. title, **or** any property defined in the frontmatter of a note.
So, the example of including the tags of a note should be:
`![[wikilink:tags]]`

View File

@@ -2,11 +2,11 @@
## Using foam-gatsby-template
You can use [foam-gatsby-template](https://github.com/mathieudutour/foam-gatsby-template) to generate a static site to host it online on Github or [Vercel](https://vercel.com).
You can use [foam-gatsby-template](https://github.com/mathieudutour/foam-gatsby-template) to generate a static site to host it online on GitHub or [Vercel](https://vercel.com).
### Publishing your foam to GitHub pages
It comes configured with Github actions to auto deploy to Github pages when changes are pushed to your main branch.
It comes configured with GitHub actions to auto deploy to GitHub pages when changes are pushed to your main branch.
### Publishing your foam to Vercel
@@ -17,7 +17,7 @@ cd _layouts
npm run build
```
Remove `public` from your .gitignore file then commit and push your public folder in `_layouts` to Github.
Remove `public` from your .gitignore file then commit and push your public folder in `_layouts` to GitHub.
Log into your Vercel account. (Create one if you don't have it already.)
@@ -28,3 +28,7 @@ That's it!
## Using foam-template-gatsby-kb
You can use another template [foam-template-gatsby-kb](https://github.com/hikerpig/foam-template-gatsby-kb), and host it on [Vercel](https://vercel.com) or [Netlify](https://www.netlify.com/).
## Using foam-template-gatsby-theme-primer-wiki
You can use another template [foam-template-gatsby-theme-primer-wiki](https://github.com/theowenyoung/foam-template-gatsby-theme-primer-wiki), ([Demo](https://demo-wiki.owenyoung.com/)), and host it on Github Pages, [Vercel](https://vercel.com) or [Netlify](https://www.netlify.com/).

View File

@@ -1,4 +1,4 @@
# Github Pages
# GitHub Pages
- In VSCode workspace settings set `"foam.edit.linkReferenceDefinitions": "withoutExtensions"`
- Execute the “Foam: Run Janitor” command from the command palette.

View File

@@ -82,6 +82,6 @@ Finally, if all is successful, Vercel will show the detected framework: Jekyll.
And now, Vercel will take care of building and rendering our foam workspace each time on push. Vercel will publish our site to `xxx.vercel.app`, we can also define a custom domain name for our Vercel website.
[//begin]: # "Autogenerated link references for markdown compatibility"
[publish-to-github-pages]: publish-to-github-pages.md "Github Pages"
[publish-to-github-pages]: publish-to-github-pages.md "GitHub Pages"
[math-support-with-katex]: math-support-with-katex.md "Katex Math Rendering"
[//end]: # "Autogenerated link references"

View File

@@ -30,7 +30,7 @@ With this #recipe you can create notes on your iOS device, which will automatica
2. the repository name of your Foam repo
3. the GitHub access token from step 7
4. An author name
11. Check your Github repo for a commit
11. Check your GitHub repo for a commit
12. If you are publishing your Foam to the web you may want to edit your publishing configuration to exclude inbox files - as publishing (and method) is a user choice that is beyond the scope of this recipe
## Code for Drafts Action

View File

@@ -27,5 +27,5 @@ You can use [Mermaid](https://marketplace.visualstudio.com/items?itemName=bierne
4. Embed the diagram file as you embedding the image file, for example: `![My Diagram](my-diagram.drawio.svg)`
[//begin]: # "Autogenerated link references for markdown compatibility"
[publish-to-github-pages]: ../publishing/publish-to-github-pages.md "Github Pages"
[publish-to-github-pages]: ../publishing/publish-to-github-pages.md "GitHub Pages"
[//end]: # "Autogenerated link references"

View File

@@ -37,7 +37,7 @@ A #recipe is a guide, tip or strategy for getting the most out of your Foam work
## Write
- Link documents with [[wiki-links]].
- Link documents with [[wikilinks]].
- Use shortcuts for [[creating-new-notes]]
- Instantly create and access your [[daily-notes]]
- Add and explore [[tags]]
@@ -56,6 +56,7 @@ A #recipe is a guide, tip or strategy for getting the most out of your Foam work
- _More..._
- VS Code Advanced Features [[todo]] [[good-first-task]]
- Focus with Zen Mode
- Display content of other notes in the preview tab by [[including-notes]]
## Version control
@@ -112,7 +113,7 @@ _See [[contribution-guide]] and [[how-to-write-recipes]]._
[graph-visualisation]: ../features/graph-visualisation.md "Graph Visualisation"
[backlinking]: ../features/backlinking.md "Backlinking"
[unlinked-references]: ../dev/unlinked-references.md "Unlinked references (stub)"
[wiki-links]: ../wiki-links.md "Wiki Links"
[wikilinks]: ../wikilinks.md "Wikilinks"
[creating-new-notes]: ../features/creating-new-notes.md "Creating New Notes"
[daily-notes]: ../features/daily-notes.md "Daily notes"
[tags]: ../features/tags.md "Tags"
@@ -125,9 +126,10 @@ _See [[contribution-guide]] and [[how-to-write-recipes]]._
[add-images-to-notes]: add-images-to-notes.md "Add images to your notes"
[shows-image-preview-on-hover]: shows-image-preview-on-hover.md "Shows Image Preview on Hover"
[good-first-task]: ../dev/good-first-task.md "Good First Task"
[including-notes]: ../features/including-notes.md "Including notes in a note"
[git-integration]: ../features/git-integration.md "Git Integration"
[write-your-notes-in-github-gist]: write-your-notes-in-github-gist.md "Write your notes in GitHub Gist"
[publish-to-github-pages]: ../publishing/publish-to-github-pages.md "Github Pages"
[publish-to-github-pages]: ../publishing/publish-to-github-pages.md "GitHub Pages"
[publish-to-gitlab-pages]: ../publishing/publish-to-gitlab-pages.md "GitLab Pages"
[publish-to-azure-devops-wiki]: ../publishing/publish-to-azure-devops-wiki.md "Publish to Azure DevOps Wiki"
[publish-to-vercel]: ../publishing/publish-to-vercel.md "Publish to Vercel"

View File

@@ -15,7 +15,7 @@ Pros
- Provides functionality to edit, create, and browser markdown files.
- Support journal mode, todo lists, and free writing
- Syncs to GitHub repo
- Supports Wiki Links
- Supports Wikilinks
- Supports Backlinks
- Developer is happy to prioritize Foam compatibility

View File

@@ -34,7 +34,7 @@ Once you've opened/created the Foam repository, it will appear in the `Repositor
## Editing your workspace
When you create or open a page, you can edit the markdown content as usual, as well as [paste images](https://github.com/vsls-contrib/gistpad#pasting-images-1), and create [`[[links]]` to other pages](https://github.com/vsls-contrib/gistpad#links). When you type `[[`, you'll recieve auto-completion for the existing pages in your workspace, and you can also automatically create new pages by simply creating a link to it.
When you create or open a page, you can edit the markdown content as usual, as well as [paste images](https://github.com/vsls-contrib/gistpad#pasting-images-1), and create [`[[links]]` to other pages](https://github.com/vsls-contrib/gistpad#links). When you type `[[`, you'll receive auto-completion for the existing pages in your workspace, and you can also automatically create new pages by simply creating a link to it.
Since you're using the Visual Studio Code markdown editor, you can benefit from all of the rich language services (e.g. syntax highlighting, header collapsing), as well as the extension ecosystem (e.g. [Emojisense](https://marketplace.visualstudio.com/items?itemName=bierner.emojisense)).

View File

@@ -5,9 +5,9 @@ These extensions defined in `.vscode/extensions.json` are automatically installe
This list is subject to change. Especially the Git ones.
- [Foam for VSCode](https://marketplace.visualstudio.com/items?itemName=foam.foam-vscode) (alpha)
- [Markdown Notes](https://marketplace.visualstudio.com/items?itemName=kortina.vscode-markdown-notes)
- [Markdown Links](https://marketplace.visualstudio.com/items?itemName=tchayen.markdown-links)
- [Markdown All In One](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one)
- [Paste Image](https://marketplace.visualstudio.com/items?itemName=mushan.vscode-paste-image)
- [Spell Right](https://marketplace.visualstudio.com/items?itemName=ban.spellright)
## Extensions For Additional Features
@@ -15,10 +15,11 @@ These extensions are not (yet?) defined in `.vscode/extensions.json`, but have b
- [Emojisense](https://marketplace.visualstudio.com/items?itemName=bierner.emojisense)
- [Markdown Emoji](https://marketplace.visualstudio.com/items?itemName=bierner.markdown-emoji) (adds `:smile:` syntax, works with emojisense to provide autocomplete for this syntax)
- [Mermaid Support for Preview](https://marketplace.visualstudio.com/items?itemName=bierner.markdown-mermaid)
- [Markdown Preview Mermaid Support](https://marketplace.visualstudio.com/items?itemName=bierner.markdown-mermaid)
- [Mermaid Markdown Syntax Highlighting](https://marketplace.visualstudio.com/items?itemName=bpruitt-goddard.mermaid-markdown-syntax-highlighting)
- [VSCode PDF Viewing](https://marketplace.visualstudio.com/items?itemName=tomoki1207.pdf)
- [Git Lens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens)
- [Markdown Extended](https://marketplace.visualstudio.com/items?itemName=jebbs.markdown-extended) (with `kbd` option disabled, `kbd` turns wiki-links into non-clickable buttons)
- [Project Manager](https://marketplace.visualstudio.com/items?itemName=alefragnani.project-manager) (to quickly switch between projects)
- [Markdown Extended](https://marketplace.visualstudio.com/items?itemName=jebbs.markdown-extended) (with `kbd` option disabled, `kbd` turns wikilinks into non-clickable buttons)
- [GitDoc](https://marketplace.visualstudio.com/items?itemName=vsls-contrib.gitdoc) (easy version management via git auto commits)
- [Markdown Footnotes](https://marketplace.visualstudio.com/items?itemName=bierner.markdown-footnotes) (Adds [^footnote] syntax support to VS Code's built-in markdown preview)
- [Todo Tree](https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.todo-tree) (Searches workspace for TODO and related comments and summarizes those lines in vs-code gutter)

View File

@@ -1,27 +1,30 @@
# Wiki Links
# Wikilinks
Foam enables you to Link pages together using `[[file-name]]` annotations (i.e. `[[media-wiki]]` links).
Foam enables you to Link pages together using `[[file-name]]` annotations (i.e. `[[MediaWiki]]` links).
- Type `[[` and start typing a file name for autocompletion.
- Note that your file names should be in `lower-dash-case.md`, and your wiki links should reference file names exactly: `[[lower-dash-case]]`, not `[[Lower Dash Case]]`.
- Note that your file names should be in `lower-dash-case.md`, and your wikilinks should reference file names exactly: `[[lower-dash-case]]`, not `[[Lower Dash Case]]`.
- See [[link-formatting-and-autocompletion]] for more information, and how to setup your link autocompletions to make this easier.
- `Cmd` + `Click` ( `Ctrl` + `Click` on Windows ) on file name to navigate to file (`F12` also works while your cursor is on the file name)
- `Cmd` + `Click` ( `Ctrl` + `Click` on Windows ) on non-existent file to create that file in the workspace.
- The note creation makes use of the special [`new-note.md` note template](features/note-templates)
> If the `F12` shortcut feels unnatural you can rebind it at File > Preferences > Keyboard Shortcuts by searching for `editor.action.revealDefinition`.
## Markdown compatibility
The [Foam for VSCode](https://marketplace.visualstudio.com/items?itemName=foam.foam-vscode) extension automatically generates [[link-reference-definitions]] at the bottom of the file to make wiki-links compatible with Markdown tools and parsers.
The [Foam for VSCode](https://marketplace.visualstudio.com/items?itemName=foam.foam-vscode) extension automatically generates [[link-reference-definitions]] at the bottom of the file to make wikilinks compatible with Markdown tools and parsers.
## Read more
- [[foam-file-format]]
- [[note-templates]]
- [[link-formatting-and-autocompletion]]
- See [[link-reference-definition-improvements]] for further discussion on current problems and potential solutions.
[//begin]: # "Autogenerated link references for markdown compatibility"
[link-reference-definitions]: features/link-reference-definitions.md "Link Reference Definitions"
[foam-file-format]: dev/foam-file-format.md "Foam File Format"
[note-templates]: features/note-templates.md "Note Templates"
[link-reference-definition-improvements]: dev/link-reference-definition-improvements.md "Link Reference Definition Improvements"
[//end]: # "Autogenerated link references"

View File

@@ -4,5 +4,5 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.13.5"
"version": "0.15.2"
}

View File

@@ -9,10 +9,6 @@
"packages/*"
],
"scripts": {
"start:vscode": "yarn workspace foam-vscode vscode:start-debugging",
"build:core": "yarn workspace foam-core build",
"watch:core": "yarn workspace foam-core start",
"test:core": "yarn workspace foam-core test",
"vscode:package-extension": "yarn workspace foam-vscode package-extension",
"vscode:install-extension": "yarn workspace foam-vscode install-extension",
"vscode:publish-extension": "yarn workspace foam-vscode publish-extension",

View File

@@ -1,3 +0,0 @@
module.exports = {
plugins: [['@babel/plugin-transform-runtime', { helpers: false }]],
};

View File

@@ -1,21 +0,0 @@
# Foam Core
This module contains the core functions, model, and API of Foam.
It is used by its clients to integrate Foam in various use cases, from VsCode extension, to CLI, to CI integrations.
## Local Development
Below is a list of commands you will probably find useful.
### `yarn watch`
Runs the project in development/watch mode. Your project will be rebuilt upon changes.
### `yarn build`
Bundles the package to the `dist` folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).
### `yarn test`
Runs the test watcher (Jest) in an interactive mode.
By default, runs tests related to files changed since the last commit.

View File

@@ -1,48 +0,0 @@
{
"name": "foam-core",
"repository": "https://github.com/foambubble/foam",
"version": "0.13.4",
"license": "MIT",
"files": [
"dist"
],
"scripts": {
"clean": "rimraf dist",
"build": "tsdx build --tsconfig ./tsconfig.build.json",
"test": "tsdx test",
"lint": "tsdx lint src test",
"watch": "tsdx watch",
"prepare": "tsdx build --tsconfig ./tsconfig.build.json"
},
"devDependencies": {
"@babel/core": "^7.10.4",
"@babel/plugin-transform-runtime": "^7.10.4",
"@babel/preset-env": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@types/github-slugger": "^1.3.0",
"@types/lodash": "^4.14.157",
"@types/micromatch": "^4.0.1",
"@types/picomatch": "^2.2.1",
"husky": "^4.2.5",
"tsdx": "^0.13.2",
"tslib": "^2.0.0",
"typescript": "^3.9.5"
},
"dependencies": {
"detect-newline": "^3.1.0",
"fast-array-diff": "^1.0.0",
"github-slugger": "^1.3.0",
"glob": "^7.1.6",
"lodash": "^4.17.21",
"micromatch": "^4.0.2",
"remark-frontmatter": "^2.0.0",
"remark-parse": "^8.0.2",
"remark-wiki-link": "^0.0.4",
"title-case": "^3.0.2",
"unified": "^9.0.0",
"unist-util-visit": "^2.0.2",
"yaml": "^1.10.0"
},
"main": "dist/index.js",
"types": "dist/index.d.ts"
}

View File

@@ -1,39 +0,0 @@
import { createMarkdownParser } from './markdown-provider';
import { FoamConfig, Foam, IDataStore, FoamGraph } from './index';
import { FoamWorkspace } from './model/workspace';
import { Matcher } from './services/datastore';
import { ResourceProvider } from 'model/provider';
export const bootstrap = async (
config: FoamConfig,
dataStore: IDataStore,
initialProviders: ResourceProvider[]
) => {
const parser = createMarkdownParser([]);
const matcher = new Matcher(
config.workspaceFolders,
config.includeGlobs,
config.ignoreGlobs
);
const workspace = new FoamWorkspace();
await Promise.all(initialProviders.map(p => workspace.registerProvider(p)));
const graph = FoamGraph.fromWorkspace(workspace, true);
const foam: Foam = {
workspace,
graph,
config,
services: {
dataStore,
parser,
matcher,
},
dispose: () => {
workspace.dispose();
graph.dispose();
},
};
return foam;
};

View File

@@ -1,73 +0,0 @@
import {
Resource,
ResourceLink,
NoteLinkDefinition,
ResourceParser,
} from './model/note';
import { FoamConfig } from './config';
import {
IDataStore,
FileDataStore,
Matcher,
IMatcher,
} from './services/datastore';
import { ILogger } from './utils/log';
import { IDisposable, isDisposable } from './common/lifecycle';
import { FoamWorkspace } from './model/workspace';
import { FoamGraph } from '../src/model/graph';
import { URI } from './model/uri';
export { Position } from './model/position';
export { Range } from './model/range';
export { IDataStore, FileDataStore, Matcher, IMatcher };
export { ILogger };
export { LogLevel, LogLevelThreshold, Logger, BaseLogger } from './utils/log';
export { Event, Emitter } from './common/event';
export { FoamConfig };
export { ResourceProvider } from './model/provider';
export { IDisposable, isDisposable };
export {
createMarkdownReferences,
stringifyMarkdownLinkReferenceDefinition,
createMarkdownParser,
MarkdownResourceProvider,
} from './markdown-provider';
export {
TextEdit,
generateHeading,
generateLinkReferences,
getKebabCaseFileName,
LINK_REFERENCE_DEFINITION_HEADER,
LINK_REFERENCE_DEFINITION_FOOTER,
} from './janitor';
export { applyTextEdit } from './janitor/apply-text-edit';
export { createConfigFromFolders } from './config';
export { bootstrap } from './bootstrap';
export {
Resource,
ResourceLink,
URI,
FoamWorkspace,
FoamGraph,
NoteLinkDefinition,
ResourceParser,
};
export interface Services {
dataStore: IDataStore;
parser: ResourceParser;
matcher: IMatcher;
}
export interface Foam extends IDisposable {
services: Services;
workspace: FoamWorkspace;
graph: FoamGraph;
config: FoamConfig;
}

View File

@@ -1,86 +0,0 @@
import * as fs from 'fs';
import path from 'path';
import { Node } from 'unist';
import { isNotNull } from '../utils';
import { Resource } from '../model/note';
import unified from 'unified';
import { FoamConfig } from '../config';
import { Logger } from '../utils/log';
import { URI } from '../model/uri';
export interface FoamPlugin {
name: string;
description?: string;
parser?: ParserPlugin;
}
export interface ParserPlugin {
name?: string;
visit?: (node: Node, note: Resource) => void;
onDidInitializeParser?: (parser: unified.Processor) => void;
onWillParseMarkdown?: (markdown: string) => string;
onWillVisitTree?: (tree: Node, note: Resource) => void;
onDidVisitTree?: (tree: Node, note: Resource) => void;
onDidFindProperties?: (properties: any, note: Resource) => void;
}
export interface PluginConfig {
enabled?: boolean;
pluginFolders?: string[];
}
export const SETTINGS_PATH = 'experimental.localPlugins';
export async function loadPlugins(config: FoamConfig): Promise<FoamPlugin[]> {
const pluginConfig = config.get<PluginConfig>(SETTINGS_PATH, {});
const isFeatureEnabled = pluginConfig.enabled ?? false;
if (!isFeatureEnabled) {
return [];
}
const pluginDirs: URI[] =
pluginConfig.pluginFolders?.map(URI.file) ??
findPluginDirs(config.workspaceFolders);
const plugins = await Promise.all(
pluginDirs
.filter(dir => fs.statSync(URI.toFsPath(dir)).isDirectory)
.map(async dir => {
try {
const pluginFile = path.join(URI.toFsPath(dir), 'index.js');
fs.accessSync(pluginFile);
Logger.info(`Found plugin at [${pluginFile}]. Loading..`);
const plugin = validate(await import(pluginFile));
return plugin;
} catch (e) {
Logger.error(`Error while loading plugin at [${dir}] - skipping`, e);
return null;
}
})
);
return plugins.filter(isNotNull);
}
function findPluginDirs(workspaceFolders: URI[]) {
return workspaceFolders
.map(root => URI.joinPath(root, '.foam', 'plugins'))
.reduce((acc, pluginDir) => {
try {
const content = fs
.readdirSync(URI.toFsPath(pluginDir))
.map(dir => URI.joinPath(pluginDir, dir));
return [
...acc,
...content.filter(c => fs.statSync(URI.toFsPath(c)).isDirectory()),
];
} catch {
return acc;
}
}, [] as URI[]);
}
function validate(plugin: any): FoamPlugin {
if (!plugin.name) {
throw new Error('Plugin must export `name` string property');
}
return plugin;
}

View File

@@ -1,16 +0,0 @@
import { isSome } from './core';
const HASHTAG_REGEX = /(^|\s)#([0-9]*[\p{L}/_-][\p{L}\p{N}/_-]*)/gmu;
const WORD_REGEX = /(^|\s)([0-9]*[\p{L}/_-][\p{L}\p{N}/_-]*)/gmu;
export const extractHashtags = (text: string): Set<string> => {
return isSome(text)
? new Set(Array.from(text.matchAll(HASHTAG_REGEX), m => m[2].trim()))
: new Set();
};
export const extractTagsFromProp = (prop: string | string[]): Set<string> => {
const text = Array.isArray(prop) ? prop.join(' ') : prop;
return isSome(text)
? new Set(Array.from(text.matchAll(WORD_REGEX)).map(m => m[2].trim()))
: new Set();
};

View File

@@ -1,94 +0,0 @@
import path from 'path';
import { FoamWorkspace } from '../src';
import { NoteLinkDefinition, Resource } from '../src/model/note';
import { IDataStore, Matcher } from '../src/services/datastore';
import { MarkdownResourceProvider } from '../src/markdown-provider';
import { Range } from '../src/model/range';
import { URI } from '../src/model/uri';
import { Logger } from '../src/utils/log';
Logger.setLevel('error');
const position = Range.create(0, 0, 0, 100);
const documentStart = position.start;
const documentEnd = position.end;
const eol = '\n';
/**
* Turns a string into a URI
* The goal of this function is to make sure we are consistent in the
* way we generate URIs (and therefore IDs) across the tests
*/
export const strToUri = URI.file;
export const noOpDataStore = (): IDataStore => ({
read: _ => Promise.resolve(''),
list: _ => Promise.resolve([]),
});
export const createTestWorkspace = () => {
const workspace = new FoamWorkspace();
const matcher = new Matcher([URI.file('/')], ['**/*']);
const provider = new MarkdownResourceProvider(
matcher,
undefined,
undefined,
noOpDataStore()
);
workspace.registerProvider(provider);
return workspace;
};
export const createTestNote = (params: {
uri: string;
title?: string;
definitions?: NoteLinkDefinition[];
links?: Array<{ slug: string } | { to: string }>;
text?: string;
root?: URI;
}): Resource => {
const root = params.root ?? URI.file('/');
return {
uri: URI.resolve(params.uri, root),
type: 'note',
properties: {},
title: params.title ?? path.parse(strToUri(params.uri).path).base,
definitions: params.definitions ?? [],
tags: new Set(),
links: params.links
? params.links.map((link, index) => {
const range = Range.create(
position.start.line + index,
position.start.character,
position.start.line + index,
position.end.character
);
return 'slug' in link
? {
type: 'wikilink',
slug: link.slug,
target: link.slug,
range: range,
text: 'link text',
}
: {
type: 'link',
target: link.to,
label: 'link text',
range: range,
};
})
: [],
source: {
eol: eol,
end: documentEnd,
contentStart: documentStart,
text: params.text ?? '',
},
};
};
describe('Test utils', () => {
it('are happy', () => {});
});

View File

@@ -1,63 +0,0 @@
import path from 'path';
import { loadPlugins } from '../src/plugins';
import { createMarkdownParser } from '../src/markdown-provider';
import { FoamConfig, createConfigFromObject } from '../src/config';
import { URI } from '../src/model/uri';
import { Logger } from '../src/utils/log';
Logger.setLevel('error');
const config: FoamConfig = createConfigFromObject([], [], [], {
experimental: {
localPlugins: {
enabled: true,
pluginFolders: [path.join(__dirname, 'test-plugin')],
},
},
});
describe('Foam plugins', () => {
it('will not load if feature is not explicitly enabled', async () => {
let plugins = await loadPlugins(createConfigFromObject([], [], [], {}));
expect(plugins.length).toEqual(0);
plugins = await loadPlugins(
createConfigFromObject([], [], [], {
experimental: {
localPlugins: {},
},
})
);
expect(plugins.length).toEqual(0);
plugins = await loadPlugins(
createConfigFromObject([], [], [], {
experimental: {
localPlugins: {
enabled: false,
},
},
})
);
expect(plugins.length).toEqual(0);
});
it('can load', async () => {
const plugins = await loadPlugins(config);
expect(plugins.length).toEqual(1);
expect(plugins[0].name).toEqual('Test Plugin');
});
it('supports parser extension', async () => {
const plugins = await loadPlugins(config);
const parserPlugin = plugins[0].parser;
expect(parserPlugin).not.toBeUndefined();
const parser = createMarkdownParser([parserPlugin!]);
const note = parser.parse(
URI.file('/path/to/a'),
`
# This is a note with header
and some content`
);
expect(note.properties.hasHeading).toBeTruthy();
});
});

View File

@@ -1,20 +0,0 @@
const middleware = next => ({
setNote: note => {
note.properties['injectedByMiddleware'] = true;
return next.setNote(note);
},
});
const parser = {
visit: (node, note) => {
if (node.type === 'heading') {
note.properties.hasHeading = true;
}
},
};
module.exports = {
name: 'Test Plugin',
graphMiddleware: middleware,
parser: parser,
};

View File

@@ -1,62 +0,0 @@
import { extractHashtags } from '../src/utils';
import { Logger } from '../src/utils/log';
Logger.setLevel('error');
describe('hashtag extraction', () => {
it('works with simple strings', () => {
expect(extractHashtags('hello #world on #this planet')).toEqual(
new Set(['world', 'this'])
);
});
it('works with tags at beginning or end of text', () => {
expect(extractHashtags('#hello world on this #planet')).toEqual(
new Set(['hello', 'planet'])
);
});
it('supports _ and -', () => {
expect(extractHashtags('#hello-world on #this_planet')).toEqual(
new Set(['hello-world', 'this_planet'])
);
});
it('supports nested tags', () => {
expect(extractHashtags('#parent/child on #planet')).toEqual(
new Set(['parent/child', 'planet'])
);
});
it('ignores tags that only have numbers in text', () => {
expect(
extractHashtags('this #123 tag should be ignore, but not #123four')
).toEqual(new Set(['123four']));
});
it('supports unicode letters like Chinese charaters', () => {
expect(
extractHashtags(`
this #tag_with_unicode_letters_汉字, pure Chinese tag like #纯中文标签 and
other mixed tags like #标签1 #123四 should work
`)
).toEqual(
new Set(['tag_with_unicode_letters_汉字', '纯中文标签', '标签1', '123四'])
);
});
it('ignores hashes in plain text urls and links', () => {
expect(
extractHashtags(`
test text with url https://site.com/#section1 https://site.com/home#section2 and
https://site.com/home/#section3a
[link](https://site.com/#section4) with [link2](https://site.com/home#section5) #control
hello world
`)
).toEqual(new Set(['control']));
});
it('ignores hashes in links to sections', () => {
expect(
extractHashtags(`
this is a wikilink to [[#section1]] in the file and a [[link#section2]] in another
this is a [link](#section3) to a section
`)
).toEqual(new Set());
});
});

View File

@@ -1,6 +0,0 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext"
}
}

View File

@@ -1,29 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "src",
"composite": true,
"esModuleInterop": true,
"importHelpers": true,
"downlevelIteration": true,
// commonjs module format is used so that the incremental
// tsc build-mode ran during development can replace individual
// files (as opposed to generate the .cjs.development.js bundle.
//
// this is overridden in tsconfig.build.json for distribution
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist",
"rootDir": "./src",
"sourceMap": true,
"strict": true,
"lib": [
"ES2019", "es2020.string"
]
},
"include": [
"src",
"types"
]
}

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,97 @@ All notable changes to the "foam-vscode" extension will be documented in this fi
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
## [0.15.2] - 2021-10-27
Features:
- Added `FOAM_DATE_*` template variables (#781)
Fixes and Improvements:
- Dataviz: apply note type color to filter item label
- Dataviz: optimized rendering of graph to reduce load on CPU (#795)
- Preview: improved tag highlight in preview (#785 - thanks @pderaaij)
- Better handling of link reference definition (#786 - thanks @pderaaij)
- Link decorations are now enabled by default (can be turned off in settings)
## [0.15.1] - 2021-10-21
Fixes and Improvements:
- Improved filtering controls for graph (#782)
- Link Hover: Include other connected notes to link target
## [0.15.0] - 2021-10-04
Features:
- Preview on hover for wikilinks (#728 - thanks @JonasSprenger)
- Added tags and controls to graph dataviz (#737 - thanks @dannysemi)
Fixes and Improvements:
- Improved tags parsing (#708 - thanks @pderaaij)
- Fixed support for resources named like JS Object methods (#729 - thanks @JonasSprenger)
## [0.14.2] - 2021-07-24
Features:
- Autocompletion for tags (#708 - thanks @pderaaij)
- Use templates for new note created from wikilink (#712 - thanks @movermeyer)
Fixes and Improvements:
- Improved performance of initial file loading (#730 - thanks @pderaaij)
## [0.14.1] - 2021-07-14
Fixes and Improvements:
- Fixed NPE that would cause markdown preview to render incorrectly (#718 - thanks @pderaaij)
## [0.14.0] - 2021-07-13
Features:
- Create new note from selection (#666 - thanks @pderaaij)
- Use templates for daily notes (#700 - thanks @movermeyer)
Fixes and Improvements:
- Fixed for wikilink aliases in tables (#697 - thanks @pderaaij)
- Fixed link definition generation in presence of aliased wikilinks (#698 - thanks @pderaaij)
- Fixed template insertion of selected text (#701 - thanks @movermeyer)
- Fixed preview navigation (#710 - thanks @pderaaij)
## [0.13.8] - 2021-07-02
Fixes and Improvements:
- Improved handling of capitalization in wikilinks (#688 - thanks @pderaaij)
- This update will make wikilinks with different capitalization, such as `[[wikilink]]` and `[[WikiLink]]` point to the same file. Please note that means that files that only differ in capitalization across the workspace would now be treated as having the same name
- Allow dots in wikilinks (#689 - thanks @pderaaij)
- Fixed a bug in the expansion of date snippets (thanks @syndenham-chorea)
- Added support for wikilink alias syntax, like `[[wikilink|label]]` (#689 - thanks @pderaaij)
## [0.13.7] - 2021-06-05
Fixes and Improvements:
- Fixed #667, incorrect resolution of foam-core library
Internal:
- BREAKING CHANGE: Removed Foam local plugins
If you were previously using the alpha feature of Foam local plugins you will soon be able to migrate the functionality to the V1 API
## [0.13.6] - 2021-06-05
Fixes and Improvements:
- Fixed #667, incorrect resolution of foam-core library
## [0.13.5] - 2021-06-05
Fixes and Improvements:

View File

@@ -28,8 +28,8 @@ You really, _really_, **really** should read [Foam documentation](https://foambu
## Features
- Connect your notes using [`[[wiki-links]]`](https://foambubble.github.io/foam/features/backlinking)
- Create markdown [references](https://foambubble.github.io/foam/features/link-reference-definitions) for `[[wiki-links]]`, to use your notes in a non-foam workspace
- Connect your notes using [`[[wikilinks]]`](https://foambubble.github.io/foam/features/backlinking)
- Create markdown [references](https://foambubble.github.io/foam/features/link-reference-definitions) for `[[wikilinks]]`, to use your notes in a non-foam workspace
- See how your notes are connected via a [graph](https://foambubble.github.io/foam/features/graph-visualisation) with the `Foam: Show Graph` command
- Tag your notes and navigate them with the [Tag Explorer](https://foambubble.github.io/foam/features/tags)
- Make your notes navigable both in GitHub UI as well as GitHub Pages

View File

@@ -8,7 +8,7 @@
"type": "git"
},
"homepage": "https://github.com/foambubble/foam",
"version": "0.13.5",
"version": "0.15.2",
"license": "MIT",
"publisher": "foam",
"engines": {
@@ -240,10 +240,15 @@
"type": "boolean",
"default": true
},
"foam.links.hover.enable": {
"description": "Enable displaying note content on hover links",
"type": "boolean",
"default": true
},
"foam.decorations.links.enable": {
"description": "Enable decorations for links",
"type": "boolean",
"default": false
"default": true
},
"foam.openDailyNote.onStartup": {
"type": "boolean",
@@ -356,9 +361,11 @@
"build": "tsc -p ./",
"pretest": "yarn build",
"test": "node ./out/test/run-tests.js",
"lint": "tsdx lint",
"unit": "node ./out/test/run-tests.js --unit",
"e2e": "node ./out/test/run-tests.js --e2e",
"lint": "tsdx lint src",
"clean": "rimraf out",
"watch": "tsc --build ./tsconfig.json ../foam-core/tsconfig.json --watch",
"watch": "tsc --build ./tsconfig.json --watch",
"vscode:start-debugging": "yarn clean && yarn watch",
"vscode:prepublish": "yarn npm-install && yarn run build",
"npm-install": "rimraf node_modules && npm i",
@@ -371,34 +378,54 @@
},
"devDependencies": {
"@babel/core": "^7.11.0",
"@babel/plugin-transform-runtime": "^7.10.4",
"@babel/preset-env": "^7.11.0",
"@babel/preset-typescript": "^7.10.4",
"@types/dateformat": "^3.0.1",
"@types/github-slugger": "^1.3.0",
"@types/glob": "^7.1.1",
"@types/lodash": "^4.14.157",
"@types/markdown-it": "^12.0.1",
"@types/micromatch": "^4.0.1",
"@types/node": "^13.11.0",
"@types/picomatch": "^2.2.1",
"@types/remove-markdown": "^0.1.1",
"@types/vscode": "^1.47.1",
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
"babel-jest": "^26.2.2",
"eslint": "^6.8.0",
"glob": "^7.1.6",
"eslint-plugin-import": "^2.24.2",
"husky": "^4.2.5",
"jest": "^26.2.2",
"jest-environment-vscode": "^1.0.0",
"jest-extended": "^0.11.5",
"markdown-it": "^12.0.4",
"rimraf": "^3.0.2",
"ts-jest": "^26.4.4",
"typescript": "^3.8.3",
"tsdx": "^0.13.2",
"tslib": "^2.0.0",
"typescript": "^3.9.5",
"vscode-test": "^1.3.0"
},
"dependencies": {
"dateformat": "^3.0.3",
"foam-core": "^0.13.4",
"detect-newline": "^3.1.0",
"fast-array-diff": "^1.0.1",
"github-slugger": "^1.3.0",
"glob": "^7.1.6",
"gray-matter": "^4.0.2",
"lodash": "^4.17.21",
"markdown-it-regex": "^0.2.0",
"micromatch": "^4.0.2",
"remove-markdown": "^0.3.0"
"remark-frontmatter": "^2.0.0",
"remark-parse": "^8.0.2",
"remark-wiki-link": "^0.0.4",
"remove-markdown": "^0.3.0",
"replace-ext": "^2.0.0",
"title-case": "^3.0.2",
"unified": "^9.0.0",
"unist-util-visit": "^2.0.2",
"yaml": "^1.10.0"
}
}

View File

@@ -0,0 +1,36 @@
{
"rules": {
"no-restricted-imports": [
"error",
{
"name": "vscode",
"message": "Core submodule must not depend on VS Code."
}
]
// Ideally we would also prevent the core module from depending on other modules
// but I have been struggling to get it to work.
// For future reference, below are some configurations I think should achieve this
// (but I couldn't manage to get working).
//
// "import/no-internal-modules": [
// "error",
// {
// "allow": ["./src/core"]
// }
// ]
// "import/no-restricted-paths": [
// "error",
// {
// "zones": [
// {
// "target": "./src/core",
// "from": "./src/(!core)",
// "message": "Core module can't have outside dependencies."
// }
// ]
// }
// ]
// "import/no-relative-parent-imports": "error"
// note: https://github.com/import-js/eslint-plugin-import/issues/1610
}
}

View File

@@ -1,10 +1,11 @@
import { createConfigFromFolders } from '../src/config';
import { Logger } from '../src/utils/log';
import { URI } from '../src/model/uri';
import { createConfigFromFolders } from './config';
import { Logger } from './utils/log';
import { URI } from './model/uri';
import { TEST_DATA_DIR } from '../test/test-utils';
Logger.setLevel('error');
const testFolder = URI.joinPath(URI.file(__dirname), 'test-config');
const testFolder = URI.joinPath(TEST_DATA_DIR, 'test-config');
describe('Foam configuration', () => {
it('can read settings from config.json', () => {

View File

@@ -1,6 +1,6 @@
import { applyTextEdit } from '../../src/janitor/apply-text-edit';
import { Range } from '../../src/model/range';
import { Logger } from '../../src/utils/log';
import { Range } from '../model/range';
import { Logger } from '../utils/log';
import { applyTextEdit } from './apply-text-edit';
Logger.setLevel('error');

View File

@@ -1,7 +1,7 @@
import os from 'os';
import detectNewline from 'detect-newline';
import { Position } from '../model/position';
import { TextEdit } from '../index';
import { TextEdit } from '.';
/**
*

View File

@@ -1,14 +1,14 @@
import * as path from 'path';
import { generateHeading } from '../../src/janitor';
import { bootstrap } from '../../src/bootstrap';
import { createConfigFromFolders } from '../../src/config';
import { Resource } from '../../src/model/note';
import { FileDataStore, Matcher } from '../../src/services/datastore';
import { Logger } from '../../src/utils/log';
import { FoamWorkspace } from '../../src/model/workspace';
import { URI } from '../../src/model/uri';
import { Range } from '../../src/model/range';
import { MarkdownResourceProvider } from '../../src';
import { generateHeading } from '.';
import { TEST_DATA_DIR } from '../../test/test-utils';
import { createConfigFromFolders } from '../config';
import { MarkdownResourceProvider } from '../markdown-provider';
import { bootstrap } from '../model/foam';
import { Resource } from '../model/note';
import { Range } from '../model/range';
import { URI } from '../model/uri';
import { FoamWorkspace } from '../model/workspace';
import { FileDataStore, Matcher } from '../services/datastore';
import { Logger } from '../utils/log';
Logger.setLevel('error');
@@ -22,7 +22,7 @@ describe('generateHeadings', () => {
beforeAll(async () => {
const config = createConfigFromFolders([
URI.file(path.join(__dirname, '..', '__scaffold__')),
URI.joinPath(TEST_DATA_DIR, '__scaffold__'),
]);
const mdProvider = new MarkdownResourceProvider(
new Matcher(

View File

@@ -1,14 +1,14 @@
import * as path from 'path';
import { generateLinkReferences } from '../../src/janitor';
import { bootstrap } from '../../src/bootstrap';
import { createConfigFromFolders } from '../../src/config';
import { FileDataStore, Matcher } from '../../src/services/datastore';
import { Logger } from '../../src/utils/log';
import { FoamWorkspace } from '../../src/model/workspace';
import { URI } from '../../src/model/uri';
import { Resource } from '../../src/model/note';
import { Range } from '../../src/model/range';
import { MarkdownResourceProvider } from '../../src';
import { generateLinkReferences } from '.';
import { TEST_DATA_DIR } from '../../test/test-utils';
import { createConfigFromFolders } from '../config';
import { MarkdownResourceProvider } from '../markdown-provider';
import { bootstrap } from '../model/foam';
import { Resource } from '../model/note';
import { Range } from '../model/range';
import { URI } from '../model/uri';
import { FoamWorkspace } from '../model/workspace';
import { FileDataStore, Matcher } from '../services/datastore';
import { Logger } from '../utils/log';
Logger.setLevel('error');
@@ -22,7 +22,7 @@ describe('generateLinkReferences', () => {
beforeAll(async () => {
const config = createConfigFromFolders([
URI.file(path.join(__dirname, '..', '__scaffold__')),
URI.joinPath(TEST_DATA_DIR, '__scaffold__'),
]);
const mdProvider = new MarkdownResourceProvider(
new Matcher(
@@ -36,7 +36,7 @@ describe('generateLinkReferences', () => {
});
it('initialised test graph correctly', () => {
expect(_workspace.list().length).toEqual(6);
expect(_workspace.list().length).toEqual(10);
});
it('should add link references to a file that does not have them', () => {
@@ -105,6 +105,54 @@ describe('generateLinkReferences', () => {
expect(actual).toEqual(expected);
});
it('should put links with spaces in angel brackets', () => {
const note = findBySlug('angel-reference');
const expected = {
newText: textForNote(
note,
`
[//begin]: # "Autogenerated link references for markdown compatibility"
[Note being refered as angel]: <Note being refered as angel> "Note being refered as angel"
[//end]: # "Autogenerated link references"`
),
range: Range.create(3, 0, 3, 0),
};
const actual = generateLinkReferences(note, _workspace, false);
expect(actual!.range.start).toEqual(expected.range.start);
expect(actual!.range.end).toEqual(expected.range.end);
expect(actual!.newText).toEqual(expected.newText);
});
it('should not remove explicitly entered link references', () => {
const note = findBySlug('file-with-explicit-link-references');
const expected = null;
const actual = generateLinkReferences(note, _workspace, false);
expect(actual).toEqual(expected);
});
it('should not remove explicitly entered link references and have an implicit link', () => {
const note = findBySlug('file-with-explicit-and-implicit-link-references');
const expected = {
newText: textForNote(
note,
`[^footerlink]: https://foambubble.github.io/
[linkrefenrece]: https://foambubble.github.io/
[//begin]: # "Autogenerated link references for markdown compatibility"
[first-document]: first-document "First Document"
[//end]: # "Autogenerated link references"`
),
range: Range.create(5, 0, 10, 42),
};
const actual = generateLinkReferences(note, _workspace, false);
expect(actual).toEqual(expected);
});
});
/**

View File

@@ -59,17 +59,78 @@ export const generateLinkReferences = (
} else {
const first = note.definitions[0];
const last = note.definitions[note.definitions.length - 1];
var nonGeneratedReferenceDefinitions = note.definitions;
// if we have more definitions then referenced pages AND the page refers to a page
// we expect non-generated link definitions to be present
// Collect all non-generated definitions, by removing the generated ones
if (
note.definitions.length > markdownReferences.length &&
markdownReferences.length > 0
) {
// remove all autogenerated definitions
const beginIndex = note.definitions.findIndex(
({ label }) => label === '//begin'
);
const endIndex = note.definitions.findIndex(
({ label }) => label === '//end'
);
const generatedDefinitions = [...note.definitions].splice(
beginIndex,
endIndex - beginIndex + 1
);
nonGeneratedReferenceDefinitions = note.definitions.filter(
x => !generatedDefinitions.includes(x)
);
}
// When we only have explicitly defined link definitions &&
// no indication of previously defined generated links &&
// there is no reference to another page, return null
if (
nonGeneratedReferenceDefinitions.length > 0 &&
note.definitions.findIndex(({ label }) => label === '//begin') < 0 &&
markdownReferences.length === 0
) {
return null;
}
// Format link definitions for non-generated links
const nonGeneratedReferences = nonGeneratedReferenceDefinitions
.map(stringifyMarkdownLinkReferenceDefinition)
.join(note.source.eol);
const oldReferences = note.definitions
.map(stringifyMarkdownLinkReferenceDefinition)
.join(note.source.eol);
if (oldReferences === newReferences) {
// When the newly formatted references match the old ones, OR
// when non-generated references are present, but no new ones are generated
// return null
if (
oldReferences === newReferences ||
(nonGeneratedReferenceDefinitions.length > 0 &&
newReferences === '' &&
markdownReferences.length > 0)
) {
return null;
}
var fullReferences = `${newReferences}`;
// If there are any non-generated definitions, add those to the output as well
if (
nonGeneratedReferenceDefinitions.length > 0 &&
markdownReferences.length > 0
) {
fullReferences = `${nonGeneratedReferences}${note.source.eol}${newReferences}`;
}
return {
// @todo: do we need to ensure new lines?
newText: `${newReferences}`,
newText: `${fullReferences}`,
range: Range.createFromPosition(first.range!.start, last.range!.end),
};
}

View File

@@ -1,14 +1,15 @@
import {
createMarkdownParser,
createMarkdownReferences,
} from '../src/markdown-provider';
import { DirectLink } from '../src/model/note';
import { ParserPlugin } from '../src/plugins';
import { Logger } from '../src/utils/log';
import { uriToSlug } from '../src/utils/slug';
import { URI } from '../src/model/uri';
import { FoamGraph } from '../src/model/graph';
import { createTestWorkspace } from './core.test';
ParserPlugin,
} from './markdown-provider';
import { DirectLink, WikiLink } from './model/note';
import { Logger } from './utils/log';
import { uriToSlug } from './utils/slug';
import { URI } from './model/uri';
import { FoamGraph } from './model/graph';
import { Range } from './model/range';
import { createTestWorkspace } from '../test/test-utils';
Logger.setLevel('error');
@@ -130,6 +131,60 @@ this is a [link to intro](#introduction)
noteE.uri,
]);
});
it('Parses backlinks with an alias', () => {
const note = createNoteFromMarkdown(
'/path/to/page-a.md',
'this is [[link|link alias]]. A link with spaces [[other link | spaced]]'
);
expect(note.links.length).toEqual(2);
let link = note.links[0] as WikiLink;
expect(link.type).toEqual('wikilink');
expect(link.rawText).toEqual('[[link|link alias]]');
expect(link.label).toEqual('link alias');
expect(link.target).toEqual('link');
link = note.links[1] as WikiLink;
expect(link.type).toEqual('wikilink');
expect(link.rawText).toEqual('[[other link | spaced]]');
expect(link.label).toEqual('spaced');
expect(link.target).toEqual('other link');
});
it('Skips wikilinks in codeblocks', () => {
const noteA = createNoteFromMarkdown(
'/dir1/page-a.md',
`
this is some text with our [[first-wikilink]].
\`\`\`
this is inside a [[codeblock]]
\`\`\`
this is some text with our [[second-wikilink]].
`
);
expect(noteA.links.map(l => l.label)).toEqual([
'first-wikilink',
'second-wikilink',
]);
});
it('Skips wikilinks in inlined codeblocks', () => {
const noteA = createNoteFromMarkdown(
'/dir1/page-a.md',
`
this is some text with our [[first-wikilink]].
this is \`inside a [[codeblock]]\`
this is some text with our [[second-wikilink]].
`
);
expect(noteA.links.map(l => l.label)).toEqual([
'first-wikilink',
'second-wikilink',
]);
});
});
describe('Note Title', () => {
@@ -298,13 +353,51 @@ describe('tags plugin', () => {
const noteA = createNoteFromMarkdown(
'/dir1/page-a.md',
`
# this is a heading
this is some #text that includes #tags we #care-about.
# this is a #heading
#this is some #text that includes #tags we #care-about.
`
);
expect(noteA.tags).toEqual(new Set(['text', 'tags', 'care-about']));
expect(noteA.tags).toEqual([
{ label: 'heading', range: Range.create(1, 12, 1, 20) },
{ label: 'this', range: Range.create(2, 0, 2, 5) },
{ label: 'text', range: Range.create(2, 14, 2, 19) },
{ label: 'tags', range: Range.create(2, 34, 2, 39) },
{ label: 'care-about', range: Range.create(2, 43, 2, 54) },
]);
});
it('will skip tags in codeblocks', () => {
const noteA = createNoteFromMarkdown(
'/dir1/page-a.md',
`
this is some #text that includes #tags we #care-about.
\`\`\`
this is a #codeblock
\`\`\`
`
);
expect(noteA.tags.map(t => t.label)).toEqual([
'text',
'tags',
'care-about',
]);
});
it('will skip tags in inlined codeblocks', () => {
const noteA = createNoteFromMarkdown(
'/dir1/page-a.md',
`
this is some #text that includes #tags we #care-about.
this is a \`inlined #codeblock\`
`
);
expect(noteA.tags.map(t => t.label)).toEqual([
'text',
'tags',
'care-about',
]);
});
it('can find tags as text in yaml', () => {
const noteA = createNoteFromMarkdown(
'/dir1/page-a.md',
@@ -316,9 +409,14 @@ tags: hello, world this_is_good
this is some #text that includes #tags we #care-about.
`
);
expect(noteA.tags).toEqual(
new Set(['text', 'tags', 'care-about', 'hello', 'world', 'this_is_good'])
);
expect(noteA.tags.map(t => t.label)).toEqual([
'hello',
'world',
'this_is_good',
'text',
'tags',
'care-about',
]);
});
it('can find tags as array in yaml', () => {
@@ -332,22 +430,34 @@ tags: [hello, world, this_is_good]
this is some #text that includes #tags we #care-about.
`
);
expect(noteA.tags).toEqual(
new Set(['text', 'tags', 'care-about', 'hello', 'world', 'this_is_good'])
);
expect(noteA.tags.map(t => t.label)).toEqual([
'hello',
'world',
'this_is_good',
'text',
'tags',
'care-about',
]);
});
it('can find nested tags as array in yaml', () => {
it('provides rough range for tags in yaml', () => {
// For now it's enough to just get the YAML block range
// in the future we might want to be more specific
const noteA = createNoteFromMarkdown(
'/dir1/page-a.md',
`
---
tags: [hello, world, parent/child]
tags: [hello, world, this_is_good]
---
# this is a heading
this is some text
`
);
expect(noteA.tags).toEqual(new Set(['hello', 'world', 'parent/child']));
expect(noteA.tags[0]).toEqual({
label: 'hello',
range: Range.create(1, 0, 3, 3),
});
});
});

View File

@@ -24,13 +24,24 @@ import {
isNone,
isSome,
} from './utils';
import { ParserPlugin } from './plugins';
import { Logger } from './utils/log';
import { URI } from './model/uri';
import { FoamWorkspace } from './model/workspace';
import { ResourceProvider } from 'model/provider';
import { IDataStore, FileDataStore, IMatcher } from './services/datastore';
import { IDisposable } from 'common/lifecycle';
import { IDisposable } from './common/lifecycle';
import { ResourceProvider } from './model/provider';
const ALIAS_DIVIDER_CHAR = '|';
export interface ParserPlugin {
name?: string;
visit?: (node: Node, note: Resource, noteSource: string) => void;
onDidInitializeParser?: (parser: unified.Processor) => void;
onWillParseMarkdown?: (markdown: string) => string;
onWillVisitTree?: (tree: Node, note: Resource) => void;
onDidVisitTree?: (tree: Node, note: Resource) => void;
onDidFindProperties?: (properties: any, note: Resource, node: Node) => void;
}
export class MarkdownResourceProvider implements ResourceProvider {
private disposables: IDisposable[] = [];
@@ -48,7 +59,9 @@ export class MarkdownResourceProvider implements ResourceProvider {
async init(workspace: FoamWorkspace) {
const filesByFolder = await Promise.all(
this.matcher.include.map(glob => this.dataStore.list(glob))
this.matcher.include.map(glob =>
this.dataStore.list(glob, this.matcher.exclude)
)
);
const files = this.matcher
.match(filesByFolder.flat())
@@ -112,7 +125,7 @@ export class MarkdownResourceProvider implements ResourceProvider {
switch (link.type) {
case 'wikilink':
const definitionUri = resource.definitions.find(
def => def.label === link.slug
def => def.label === link.target
)?.url;
if (isSome(definitionUri)) {
const definedUri = URI.resolve(definitionUri, resource.uri);
@@ -121,8 +134,8 @@ export class MarkdownResourceProvider implements ResourceProvider {
URI.placeholder(definedUri.path);
} else {
targetUri =
workspace.find(link.slug, resource.uri)?.uri ??
URI.placeholder(link.slug);
workspace.find(link.target, resource.uri)?.uri ??
URI.placeholder(link.target);
}
break;
@@ -150,7 +163,7 @@ const getTextFromChildren = (root: Node): string => {
let text = '';
visit(root, 'text', node => {
if (node.type === 'text') {
text = text + node.value;
text = text + (node as any).value;
}
});
return text;
@@ -158,21 +171,46 @@ const getTextFromChildren = (root: Node): string => {
const tagsPlugin: ParserPlugin = {
name: 'tags',
onWillVisitTree: (tree, note) => {
note.tags = extractHashtags(note.source.text);
onDidFindProperties: (props, note, node) => {
if (isSome(props.tags)) {
const yamlTags = extractTagsFromProp(props.tags);
yamlTags.forEach(t => {
note.tags.push({
label: t,
range: astPositionToFoamRange(node.position!),
});
});
}
},
onDidFindProperties: (props, note) => {
const yamlTags = extractTagsFromProp(props.tags);
yamlTags.forEach(tag => note.tags.add(tag));
visit: (node, note) => {
if (node.type === 'text') {
const tags = extractHashtags((node as any).value);
tags.forEach(tag => {
let start = astPointToFoamPosition(node.position!.start);
start.character = start.character + tag.offset;
const end: Position = {
line: start.line,
character: start.character + tag.label.length + 1,
};
note.tags.push({
label: tag.label,
range: Range.createFromPosition(start, end),
});
});
}
},
};
const titlePlugin: ParserPlugin = {
name: 'title',
visit: (node, note) => {
if (note.title === '' && node.type === 'heading' && node.depth === 1) {
if (
note.title === '' &&
node.type === 'heading' &&
(node as any).depth === 1
) {
note.title =
((node as Parent)!.children?.[0]?.value as string) || note.title;
((node as Parent)!.children?.[0] as any)?.value || note.title;
}
},
onDidFindProperties: (props, note) => {
@@ -188,12 +226,29 @@ const titlePlugin: ParserPlugin = {
const wikilinkPlugin: ParserPlugin = {
name: 'wikilink',
visit: (node, note) => {
visit: (node, note, noteSource) => {
if (node.type === 'wikiLink') {
const text = (node as any).value;
const alias = node.data?.alias as string;
const literalContent = noteSource.substring(
node.position!.start.offset!,
node.position!.end.offset!
);
const hasAlias =
literalContent !== text && literalContent.includes(ALIAS_DIVIDER_CHAR);
note.links.push({
type: 'wikilink',
slug: node.value as string,
target: node.value as string,
rawText: literalContent,
label: hasAlias
? alias.trim()
: literalContent.substring(2, literalContent.length - 2),
target: hasAlias
? literalContent
.substring(2, literalContent.indexOf(ALIAS_DIVIDER_CHAR))
.replace(/\\/g, '')
.trim()
: text.trim(),
range: astPositionToFoamRange(node.position!),
});
}
@@ -219,9 +274,9 @@ const definitionsPlugin: ParserPlugin = {
visit: (node, note) => {
if (node.type === 'definition') {
note.definitions.push({
label: node.label as string,
url: node.url as string,
title: node.title as string,
label: (node as any).label,
url: (node as any).url,
title: (node as any).title,
range: astPositionToFoamRange(node.position!),
});
}
@@ -239,7 +294,9 @@ const handleError = (
): void => {
const name = plugin.name || '';
Logger.warn(
`Error while executing [${fnName}] in plugin [${name}] for file [${uri?.path}]`,
`Error while executing [${fnName}] in plugin [${name}]. ${
uri ? 'for file [' + URI.toString(uri) : ']'
}.`,
e
);
};
@@ -250,7 +307,7 @@ export function createMarkdownParser(
const parser = unified()
.use(markdownParse, { gfm: true })
.use(frontmatterPlugin, ['yaml'])
.use(wikiLinkPlugin);
.use(wikiLinkPlugin, { aliasDivider: ALIAS_DIVIDER_CHAR });
const plugins = [
titlePlugin,
@@ -270,7 +327,7 @@ export function createMarkdownParser(
const foamParser: ResourceParser = {
parse: (uri: URI, markdown: string): Resource => {
Logger.debug('Parsing:', uri);
Logger.debug('Parsing:', URI.toString(uri));
markdown = plugins.reduce((acc, plugin) => {
try {
return plugin.onWillParseMarkdown?.(acc) || acc;
@@ -287,7 +344,7 @@ export function createMarkdownParser(
type: 'note',
properties: {},
title: '',
tags: new Set(),
tags: [],
links: [],
definitions: [],
source: {
@@ -308,7 +365,7 @@ export function createMarkdownParser(
visit(tree, node => {
if (node.type === 'yaml') {
try {
const yamlProperties = parseYAML(node.value as string) ?? {};
const yamlProperties = parseYAML((node as any).value) ?? {};
note.properties = {
...note.properties,
...yamlProperties,
@@ -321,19 +378,22 @@ export function createMarkdownParser(
for (let i = 0, len = plugins.length; i < len; i++) {
try {
plugins[i].onDidFindProperties?.(yamlProperties, note);
plugins[i].onDidFindProperties?.(yamlProperties, note, node);
} catch (e) {
handleError(plugins[i], 'onDidFindProperties', uri, e);
}
}
} catch (e) {
Logger.warn(`Error while parsing YAML for [${uri}]`, e);
Logger.warn(
`Error while parsing YAML for [${URI.toString(uri)}]`,
e
);
}
}
for (let i = 0, len = plugins.length; i < len; i++) {
try {
plugins[i].visit?.(node, note);
plugins[i].visit?.(node, note, markdown);
} catch (e) {
handleError(plugins[i], 'visit', uri, e);
}
@@ -381,7 +441,9 @@ function getFoamDefinitions(
export function stringifyMarkdownLinkReferenceDefinition(
definition: NoteLinkDefinition
) {
let text = `[${definition.label}]: ${definition.url}`;
let url =
definition.url.indexOf(' ') > 0 ? `<${definition.url}>` : definition.url;
let text = `[${definition.label}]: ${url}`;
if (definition.title) {
text = `${text} "${definition.title}"`;
}
@@ -397,7 +459,9 @@ export function createMarkdownReferences(
// Should never occur since we're already in a file,
if (source?.type !== 'note') {
console.warn(
`Note ${noteUri} note found in workspace when attempting to generate markdown reference list`
`Note ${URI.toString(
noteUri
)} note found in workspace when attempting to generate markdown reference list`
);
return [];
}
@@ -408,7 +472,11 @@ export function createMarkdownReferences(
const targetUri = workspace.resolveLink(source, link);
const target = workspace.find(targetUri);
if (isNone(target)) {
Logger.warn(`Link ${targetUri} in ${noteUri} is not valid.`);
Logger.warn(
`Link ${URI.toString(targetUri)} in ${URI.toString(
noteUri
)} is not valid.`
);
return null;
}
if (target.type === 'placeholder') {
@@ -421,8 +489,15 @@ export function createMarkdownReferences(
? relativePath
: dropExtension(relativePath);
// [wiki-link-text]: path/to/file.md "Page title"
return { label: link.slug, url: pathToNote, title: target.title };
// [wikilink-text]: path/to/file.md "Page title"
return {
label:
link.rawText.indexOf('[[') > -1
? link.rawText.substring(2, link.rawText.length - 2)
: link.rawText || link.label,
url: pathToNote,
title: target.title,
};
})
.filter(isSome)
.sort();

View File

@@ -0,0 +1,59 @@
import { IDisposable } from '../common/lifecycle';
import { IDataStore, IMatcher, Matcher } from '../services/datastore';
import { FoamConfig } from '../config';
import { FoamWorkspace } from './workspace';
import { FoamGraph } from './graph';
import { ResourceParser } from './note';
import { ResourceProvider } from './provider';
import { createMarkdownParser } from '../markdown-provider';
import { FoamTags } from './tags';
export interface Services {
dataStore: IDataStore;
parser: ResourceParser;
matcher: IMatcher;
}
export interface Foam extends IDisposable {
services: Services;
workspace: FoamWorkspace;
graph: FoamGraph;
config: FoamConfig;
tags: FoamTags;
}
export const bootstrap = async (
config: FoamConfig,
dataStore: IDataStore,
initialProviders: ResourceProvider[]
) => {
const parser = createMarkdownParser([]);
const matcher = new Matcher(
config.workspaceFolders,
config.includeGlobs,
config.ignoreGlobs
);
const workspace = new FoamWorkspace();
await Promise.all(initialProviders.map(p => workspace.registerProvider(p)));
const graph = FoamGraph.fromWorkspace(workspace, true);
const tags = FoamTags.fromWorkspace(workspace, true);
const foam: Foam = {
workspace,
graph,
tags,
config,
services: {
dataStore,
parser,
matcher,
},
dispose: () => {
workspace.dispose();
graph.dispose();
},
};
return foam;
};

View File

@@ -2,9 +2,9 @@ import { diff } from 'fast-array-diff';
import { isEqual } from 'lodash';
import { Resource, ResourceLink } from './note';
import { URI } from './uri';
import { IDisposable } from '../index';
import { FoamWorkspace, uriToResourceName } from './workspace';
import { Range } from './range';
import { IDisposable } from '../common/lifecycle';
export type Connection = {
source: URI;
@@ -19,15 +19,15 @@ export class FoamGraph implements IDisposable {
/**
* Placehoders by key / slug / value
*/
public readonly placeholders: { [key: string]: URI } = {};
public readonly placeholders: Map<string, URI> = new Map();
/**
* Maps the connections starting from a URI
*/
public readonly links: { [key: string]: Connection[] } = {};
public readonly links: Map<string, Connection[]> = new Map();
/**
* Maps the connections arriving to a URI
*/
public readonly backlinks: { [key: string]: Connection[] } = {};
public readonly backlinks: Map<string, Connection[]> = new Map();
/**
* List of disposables to destroy with the workspace
@@ -42,28 +42,28 @@ export class FoamGraph implements IDisposable {
public getAllNodes(): URI[] {
return [
...Object.values(this.placeholders),
...Array.from(this.placeholders.values()),
...this.workspace.list().map(r => r.uri),
];
}
public getAllConnections(): Connection[] {
return Object.values(this.links).flat();
return Array.from(this.links.values()).flat();
}
public getConnections(uri: URI): Connection[] {
return [
...(this.links[uri.path] || []),
...(this.backlinks[uri.path] || []),
...(this.links.get(uri.path) || []),
...(this.backlinks.get(uri.path) || []),
];
}
public getLinks(uri: URI): Connection[] {
return this.links[uri.path] ?? [];
return this.links.get(uri.path) ?? [];
}
public getBacklinks(uri: URI): Connection[] {
return this.backlinks[uri.path] ?? [];
return this.backlinks.get(uri.path) ?? [];
}
/**
@@ -80,9 +80,7 @@ export class FoamGraph implements IDisposable {
): FoamGraph {
let graph = new FoamGraph(workspace);
Object.values(workspace.list()).forEach(resource =>
graph.resolveResource(resource)
);
workspace.list().forEach(resource => graph.resolveResource(resource));
if (keepMonitoring) {
graph.disposables.push(
workspace.onDidAdd(resource => {
@@ -102,10 +100,10 @@ export class FoamGraph implements IDisposable {
private updateLinksRelatedToAddedResource(resource: Resource) {
// check if any existing connection can be filled by new resource
const name = uriToResourceName(resource.uri);
if (name in this.placeholders) {
const placeholder = this.placeholders[name];
delete this.placeholders[name];
const resourcesToUpdate = this.backlinks[placeholder.path] ?? [];
const placeholder = this.placeholders.get(name);
if (placeholder) {
this.placeholders.delete(name);
const resourcesToUpdate = this.backlinks.get(placeholder.path) ?? [];
resourcesToUpdate.forEach(res =>
this.resolveResource(this.workspace.get(res.source))
);
@@ -143,15 +141,15 @@ export class FoamGraph implements IDisposable {
const uri = resource.uri;
// remove forward links from old resource
const resourcesPointedByDeletedNote = this.links[uri.path] ?? [];
delete this.links[uri.path];
const resourcesPointedByDeletedNote = this.links.get(uri.path) ?? [];
this.links.delete(uri.path);
resourcesPointedByDeletedNote.forEach(connection =>
this.disconnect(uri, connection.target, connection.link)
);
// recompute previous links to old resource
const notesPointingToDeletedResource = this.backlinks[uri.path] ?? [];
delete this.backlinks[uri.path];
const notesPointingToDeletedResource = this.backlinks.get(uri.path) ?? [];
this.backlinks.delete(uri.path);
notesPointingToDeletedResource.forEach(link =>
this.resolveResource(this.workspace.get(link.source))
);
@@ -161,13 +159,19 @@ export class FoamGraph implements IDisposable {
private connect(source: URI, target: URI, link: ResourceLink) {
const connection = { source, target, link };
this.links[source.path] = this.links[source.path] ?? [];
this.links[source.path].push(connection);
this.backlinks[target.path] = this.backlinks[target.path] ?? [];
this.backlinks[target.path].push(connection);
if (!this.links.has(source.path)) {
this.links.set(source.path, []);
}
this.links.get(source.path)?.push(connection);
if (!this.backlinks.get(target.path)) {
this.backlinks.set(target.path, []);
}
this.backlinks.get(target.path)?.push(connection);
if (URI.isPlaceholder(target)) {
this.placeholders[uriToPlaceholderId(target)] = target;
this.placeholders.set(uriToPlaceholderId(target), target);
}
return this;
}
@@ -189,24 +193,28 @@ export class FoamGraph implements IDisposable {
!URI.isEqual(source, c.source) || !URI.isEqual(target, c.target)
: (c: Connection) => !isSameConnection({ source, target, link }, c);
this.links[source.path] =
this.links[source.path]?.filter(connectionsToKeep) ?? [];
if (this.links[source.path].length === 0) {
delete this.links[source.path];
this.links.set(
source.path,
this.links.get(source.path)?.filter(connectionsToKeep) ?? []
);
if (this.links.get(source.path)?.length === 0) {
this.links.delete(source.path);
}
this.backlinks[target.path] =
this.backlinks[target.path]?.filter(connectionsToKeep) ?? [];
if (this.backlinks[target.path].length === 0) {
delete this.backlinks[target.path];
this.backlinks.set(
target.path,
this.backlinks.get(target.path)?.filter(connectionsToKeep) ?? []
);
if (this.backlinks.get(target.path)?.length === 0) {
this.backlinks.delete(target.path);
if (URI.isPlaceholder(target)) {
delete this.placeholders[uriToPlaceholderId(target)];
this.placeholders.delete(uriToPlaceholderId(target));
}
}
return this;
}
public resolveResource(resource: Resource) {
delete this.links[resource.uri.path];
this.links.delete(resource.uri.path);
// prettier-ignore
resource.links.forEach(link => {
const targetUri = this.workspace.resolveLink(resource, link);

View File

@@ -11,8 +11,9 @@ export interface NoteSource {
export interface WikiLink {
type: 'wikilink';
slug: string;
target: string;
label: string;
rawText: string;
range: Range;
}
@@ -32,13 +33,18 @@ export interface NoteLinkDefinition {
range?: Range;
}
export interface Tag {
label: string;
range: Range;
}
export interface Resource {
uri: URI;
type: string;
title: string;
properties: any;
// sections: NoteSection[]
tags: Set<string>;
tags: Tag[];
links: ResourceLink[];
// TODO to remove

View File

@@ -1,6 +1,6 @@
import { IDisposable } from 'common/lifecycle';
import { ResourceLink, URI } from 'index';
import { Resource } from './note';
import { IDisposable } from '../common/lifecycle';
import { Resource, ResourceLink } from './note';
import { URI } from './uri';
import { FoamWorkspace } from './workspace';
export interface ResourceProvider extends IDisposable {

View File

@@ -0,0 +1,138 @@
import { createTestNote, createTestWorkspace } from '../../test/test-utils';
import { FoamTags } from './tags';
describe('FoamTags', () => {
it('Collects tags from a list of resources', () => {
const ws = createTestWorkspace();
const pageA = createTestNote({
uri: '/page-a.md',
title: 'Page A',
links: [{ slug: 'placeholder-link' }],
tags: ['primary', 'secondary'],
});
const pageB = createTestNote({
uri: '/page-b.md',
title: 'Page B',
links: [{ slug: 'placeholder-link' }],
tags: ['primary', 'third'],
});
ws.set(pageA);
ws.set(pageB);
const tags = FoamTags.fromWorkspace(ws);
expect(tags.tags).toEqual(
new Map([
['primary', [pageA.uri, pageB.uri]],
['secondary', [pageA.uri]],
['third', [pageB.uri]],
])
);
});
it('Updates an existing tag when a note is tagged with an existing tag', () => {
const ws = createTestWorkspace();
const page = createTestNote({
uri: '/page-a.md',
title: 'Page A',
links: [{ slug: 'placeholder-link' }],
tags: ['primary'],
});
const taglessPage = createTestNote({
uri: '/page-b.md',
title: 'Page B',
});
ws.set(page);
ws.set(taglessPage);
const tags = FoamTags.fromWorkspace(ws);
expect(tags.tags).toEqual(new Map([['primary', [page.uri]]]));
const newPage = createTestNote({
uri: '/page-b.md',
title: 'Page B',
tags: ['primary'],
});
tags.updateResourceWithinTagIndex(taglessPage, newPage);
expect(tags.tags).toEqual(new Map([['primary', [page.uri, newPage.uri]]]));
});
it('Replaces the tag when a note is updated with an altered tag', () => {
const ws = createTestWorkspace();
const page = createTestNote({
uri: '/page-a.md',
title: 'Page A',
links: [{ slug: 'placeholder-link' }],
tags: ['primary'],
});
ws.set(page);
const tags = FoamTags.fromWorkspace(ws);
expect(tags.tags).toEqual(new Map([['primary', [page.uri]]]));
const pageEdited = createTestNote({
uri: '/page-a.md',
title: 'Page A',
links: [{ slug: 'placeholder-link' }],
tags: ['new'],
});
tags.updateResourceWithinTagIndex(page, pageEdited);
expect(tags.tags).toEqual(new Map([['new', [page.uri]]]));
});
it('Updates the metadata of a tag when the note is moved', () => {
const ws = createTestWorkspace();
const page = createTestNote({
uri: '/page-a.md',
title: 'Page A',
links: [{ slug: 'placeholder-link' }],
tags: ['primary'],
});
ws.set(page);
const tags = FoamTags.fromWorkspace(ws);
expect(tags.tags).toEqual(new Map([['primary', [page.uri]]]));
const pageEdited = createTestNote({
uri: '/new-place/page-a.md',
title: 'Page A',
links: [{ slug: 'placeholder-link' }],
tags: ['primary'],
});
tags.updateResourceWithinTagIndex(page, pageEdited);
expect(tags.tags).toEqual(new Map([['primary', [pageEdited.uri]]]));
});
it('Updates the metadata of a tag when a note is delete', () => {
const ws = createTestWorkspace();
const page = createTestNote({
uri: '/page-a.md',
title: 'Page A',
links: [{ slug: 'placeholder-link' }],
tags: ['primary'],
});
ws.set(page);
const tags = FoamTags.fromWorkspace(ws);
expect(tags.tags).toEqual(new Map([['primary', [page.uri]]]));
tags.removeResourceFromTagIndex(page);
expect(tags.tags).toEqual(new Map());
});
});

View File

@@ -0,0 +1,81 @@
import { FoamWorkspace } from './workspace';
import { URI } from './uri';
import { Resource } from './note';
import { IDisposable } from '../common/lifecycle';
export class FoamTags implements IDisposable {
public readonly tags: Map<string, URI[]> = new Map();
/**
* List of disposables to destroy with the tags
*/
private disposables: IDisposable[] = [];
/**
* Computes all tags in the workspace and keep them up-to-date
*
* @param workspace the target workspace
* @param keepMonitoring whether to recompute the links when the workspace changes
* @returns the FoamTags
*/
public static fromWorkspace(
workspace: FoamWorkspace,
keepMonitoring: boolean = false
): FoamTags {
let tags = new FoamTags();
workspace
.list()
.forEach(resource => tags.addResourceFromTagIndex(resource));
if (keepMonitoring) {
tags.disposables.push(
workspace.onDidAdd(resource => {
tags.addResourceFromTagIndex(resource);
}),
workspace.onDidUpdate(change => {
tags.updateResourceWithinTagIndex(change.old, change.new);
}),
workspace.onDidDelete(resource => {
tags.removeResourceFromTagIndex(resource);
})
);
}
return tags;
}
dispose(): void {
this.disposables.forEach(d => d.dispose());
this.disposables = [];
}
updateResourceWithinTagIndex(oldResource: Resource, newResource: Resource) {
this.removeResourceFromTagIndex(oldResource);
this.addResourceFromTagIndex(newResource);
}
addResourceFromTagIndex(resource: Resource) {
new Set(resource.tags.map(t => t.label)).forEach(tag => {
const tagMeta = this.tags.get(tag) ?? [];
tagMeta.push(resource.uri);
this.tags.set(tag, tagMeta);
});
}
removeResourceFromTagIndex(resource: Resource) {
resource.tags.forEach(t => {
const tag = t.label;
if (this.tags.has(tag)) {
const remainingLocations = this.tags
.get(tag)
?.filter(uri => !URI.isEqual(uri, resource.uri));
if (remainingLocations && remainingLocations.length > 0) {
this.tags.set(tag, remainingLocations);
} else {
this.tags.delete(tag);
}
}
});
}
}

View File

@@ -1,6 +1,6 @@
import { Logger } from '../src';
import { URI } from '../src/model/uri';
import { uriToSlug } from '../src/utils/slug';
import { Logger } from '../utils/log';
import { uriToSlug } from '../utils/slug';
import { URI } from './uri';
Logger.setLevel('error');
@@ -16,7 +16,7 @@ describe('Foam URIs', () => {
'../relative/file.md#section',
URI.parse('file:/path/relative/file.md#section'),
],
])('URI Parsing (%s) - %s', (input, exp) => {
])('URI Parsing (%s)', (input, exp) => {
const result = URI.resolve(input, base);
expect(result.scheme).toEqual(exp.scheme);
expect(result.authority).toEqual(exp.authority);

View File

@@ -1,4 +1,7 @@
// Some code in this file coming from https://github.com/microsoft/vscode/
// `URI` is mostly compatible with VSCode's `Uri`.
// Having a Foam-specific URI object allows for easier maintenance of the API.
// See https://github.com/foambubble/foam/pull/537 for more context.
// Some code in this file comes from https://github.com/microsoft/vscode/main/src/vs/base/common/uri.ts
// See LICENSE for details
import * as paths from 'path';
@@ -148,6 +151,10 @@ export abstract class URI {
return URI.file(posix.dirname(uri.path));
}
static getFileNameWithoutExtension(uri: URI) {
return URI.getBasename(uri).replace(/\.[^.]+$/, '');
}
/**
* Uses a placeholder URI, and a reference directory, to generate
* the URI of the corresponding resource

View File

@@ -1,8 +1,8 @@
import { getReferenceType } from '../src/model/workspace';
import { FoamGraph } from '../src/model/graph';
import { Logger } from '../src/utils/log';
import { createTestNote, createTestWorkspace } from './core.test';
import { URI } from '../src/model/uri';
import { getReferenceType } from './workspace';
import { FoamGraph } from './graph';
import { Logger } from '../utils/log';
import { URI } from './uri';
import { createTestNote, createTestWorkspace } from '../../test/test-utils';
Logger.setLevel('error');
@@ -64,6 +64,13 @@ describe('Workspace resources', () => {
expect(ws.find(uri)).toBeNull();
expect(() => ws.get(uri)).toThrow();
});
it('Should work with a resource named like a JS prototype property', () => {
const ws = createTestWorkspace();
const noteA = createTestNote({ uri: '/somewhere/constructor.md' });
ws.set(noteA);
expect(ws.list()).toEqual([noteA]);
});
});
describe('Graph', () => {
@@ -232,7 +239,7 @@ describe('Wikilinks', () => {
expect(graph.getAllConnections()[0]).toEqual({
source: noteA.uri,
target: noteB.uri,
link: expect.objectContaining({ type: 'wikilink', slug: 'page-b' }),
link: expect.objectContaining({ type: 'wikilink', label: 'page-b' }),
});
});
@@ -354,6 +361,51 @@ describe('Wikilinks', () => {
attachmentABis.uri,
]);
});
it('Allows for dendron-style wikilinks, including a dot', () => {
const noteA = createTestNote({
uri: '/path/to/page-a.md',
links: [{ slug: 'dendron.style' }],
});
const noteB1 = createTestNote({ uri: '/path/to/another/dendron.style.md' });
const ws = createTestWorkspace();
ws.set(noteA).set(noteB1);
const graph = FoamGraph.fromWorkspace(ws);
expect(graph.getLinks(noteA.uri).map(l => l.target)).toEqual([noteB1.uri]);
});
it('Handles capatalization of files and wikilinks correctly', () => {
const noteA = createTestNote({
uri: '/path/to/page-a.md',
links: [
// uppercased filename, lowercased slug
{ slug: 'page-b' },
// lowercased filename, camelcased wikilink
{ slug: 'Page-C' },
// lowercased filename, lowercased wikilink
{ slug: 'page-d' },
],
});
const ws = createTestWorkspace()
.set(noteA)
.set(createTestNote({ uri: '/somewhere/PAGE-B.md' }))
.set(createTestNote({ uri: '/path/another/page-c.md' }))
.set(createTestNote({ uri: '/path/another/page-d.md' }));
const graph = FoamGraph.fromWorkspace(ws);
expect(
graph
.getLinks(noteA.uri)
.map(link => link.target.path)
.sort()
).toEqual([
'/path/another/page-c.md',
'/path/another/page-d.md',
'/somewhere/PAGE-B.md',
]);
});
});
describe('markdown direct links', () => {
@@ -473,6 +525,23 @@ describe('Placeholders', () => {
link: expect.objectContaining({ type: 'wikilink' }),
});
});
it('Should work with a placeholder named like a JS prototype property', () => {
const ws = createTestWorkspace();
const noteA = createTestNote({
uri: '/page-a.md',
links: [{ slug: 'constructor' }],
});
ws.set(noteA);
const graph = FoamGraph.fromWorkspace(ws);
expect(
graph
.getAllNodes()
.map(uri => uri.path)
.sort()
).toEqual(['/page-a.md', 'constructor']);
});
});
describe('Updating workspace happy path', () => {

View File

@@ -3,8 +3,8 @@ import { Resource, ResourceLink } from './note';
import { URI } from './uri';
import { isSome, isNone } from '../utils';
import { Emitter } from '../common/event';
import { IDisposable } from '../index';
import { ResourceProvider } from './provider';
import { IDisposable } from '../common/lifecycle';
export function getReferenceType(
reference: URI | string
@@ -26,7 +26,8 @@ const pathToResourceId = (pathValue: string) => {
};
const uriToResourceId = (uri: URI) => pathToResourceId(uri.path);
const pathToResourceName = (pathValue: string) => path.parse(pathValue).name;
const pathToResourceName = (pathValue: string) =>
path.parse(pathValue).name.toLowerCase();
export const uriToResourceName = (uri: URI) => pathToResourceName(uri.path);
export class FoamWorkspace implements IDisposable {
@@ -42,11 +43,11 @@ export class FoamWorkspace implements IDisposable {
/**
* Resources by key / slug
*/
private resourcesByName: { [key: string]: string[] } = {};
private resourcesByName: Map<string, string[]> = new Map();
/**
* Resources by URI
*/
private resources: { [key: string]: Resource } = {};
private resources: Map<string, Resource> = new Map();
registerProvider(provider: ResourceProvider) {
this.providers.push(provider);
@@ -57,9 +58,11 @@ export class FoamWorkspace implements IDisposable {
const id = uriToResourceId(resource.uri);
const old = this.find(resource.uri);
const name = uriToResourceName(resource.uri);
this.resources[id] = resource;
this.resourcesByName[name] = this.resourcesByName[name] ?? [];
this.resourcesByName[name].push(id);
this.resources.set(id, resource);
if (!this.resourcesByName.has(name)) {
this.resourcesByName.set(name, []);
}
this.resourcesByName.get(name)?.push(id);
isSome(old)
? this.onDidUpdateEmitter.fire({ old: old, new: resource })
: this.onDidAddEmitter.fire(resource);
@@ -68,14 +71,16 @@ export class FoamWorkspace implements IDisposable {
delete(uri: URI) {
const id = uriToResourceId(uri);
const deleted = this.resources[id];
delete this.resources[id];
const deleted = this.resources.get(id);
this.resources.delete(id);
const name = uriToResourceName(uri);
this.resourcesByName[name] =
this.resourcesByName[name]?.filter(resId => resId !== id) ?? [];
if (this.resourcesByName[name].length === 0) {
delete this.resourcesByName[name];
this.resourcesByName.set(
name,
this.resourcesByName.get(name)?.filter(resId => resId !== id) ?? []
);
if (this.resourcesByName.get(name)?.length === 0) {
this.resourcesByName.delete(name);
}
isSome(deleted) && this.onDidDeleteEmitter.fire(deleted);
@@ -84,12 +89,13 @@ export class FoamWorkspace implements IDisposable {
public exists(uri: URI): boolean {
return (
!URI.isPlaceholder(uri) && isSome(this.resources[uriToResourceId(uri)])
!URI.isPlaceholder(uri) &&
isSome(this.resources.get(uriToResourceId(uri)))
);
}
public list(): Resource[] {
return Object.values(this.resources);
return Array.from(this.resources.values());
}
public get(uri: URI): Resource {
@@ -106,11 +112,18 @@ export class FoamWorkspace implements IDisposable {
switch (refType) {
case 'uri':
const uri = resourceId as URI;
return this.exists(uri) ? this.resources[uriToResourceId(uri)] : null;
return this.exists(uri)
? this.resources.get(uriToResourceId(uri)) ?? null
: null;
case 'key':
const name = pathToResourceName(resourceId as string);
const paths = this.resourcesByName[name];
let paths = this.resourcesByName.get(name);
if (isNone(paths) || paths.length === 0) {
paths = this.resourcesByName.get(resourceId as string);
}
if (isNone(paths) || paths.length === 0) {
return null;
}
@@ -118,11 +131,12 @@ export class FoamWorkspace implements IDisposable {
const sortedPaths = paths.length === 1
? paths
: paths.sort((a, b) => a.localeCompare(b));
return this.resources[sortedPaths[0]];
return this.resources.get(sortedPaths[0]) ?? null;
case 'absolute-path':
const resourceUri = URI.file(resourceId as string);
return this.resources[uriToResourceId(resourceUri)] ?? null;
return this.resources.get(uriToResourceId(resourceUri)) ?? null;
case 'relative-path':
if (isNone(reference)) {
@@ -130,7 +144,7 @@ export class FoamWorkspace implements IDisposable {
}
const relativePath = resourceId as string;
const targetUri = URI.computeRelativeURI(reference, relativePath);
return this.resources[uriToResourceId(targetUri)] ?? null;
return this.resources.get(uriToResourceId(targetUri)) ?? null;
default:
throw new Error('Unexpected reference type: ' + refType);

View File

@@ -1,11 +1,11 @@
import { Logger } from '../src/utils/log';
import { URI } from '../src/model/uri';
import { FileDataStore, Matcher } from '../src';
import { toMatcherPathFormat } from '../src/services/datastore';
import { TEST_DATA_DIR } from '../../test/test-utils';
import { URI } from '../model/uri';
import { Logger } from '../utils/log';
import { FileDataStore, Matcher, toMatcherPathFormat } from './datastore';
Logger.setLevel('error');
const testFolder = URI.joinPath(URI.file(__dirname), 'test-datastore');
const testFolder = URI.joinPath(TEST_DATA_DIR, 'test-datastore');
describe('Matcher', () => {
it('generates globs with the base dir provided', () => {

View File

@@ -100,7 +100,7 @@ export interface IDataStore {
* List the files matching the given glob from the
* store
*/
list: (glob: string) => Promise<URI[]>;
list: (glob: string, ignoreGlob?: string | string[]) => Promise<URI[]>;
/**
* Read the content of the file from the store
@@ -114,8 +114,10 @@ export interface IDataStore {
* File system based data store
*/
export class FileDataStore implements IDataStore {
async list(glob: string): Promise<URI[]> {
const res = await findAllFiles(glob);
async list(glob: string, ignoreGlob?: string | string[]): Promise<URI[]> {
const res = await findAllFiles(glob, {
ignore: ignoreGlob,
});
return res.map(URI.file);
}

View File

@@ -1,19 +1,19 @@
import crypto from 'crypto';
export function isNotNull<T>(value: T | null): value is T {
return value != null;
return value != null; // eslint-disable-line
}
export function isSome<T>(
value: T | null | undefined | void
): value is NonNullable<T> {
return value != null;
return value != null; // eslint-disable-line
}
export function isNone<T>(
value: T | null | undefined | void
): value is null | undefined | void {
return value == null;
return value == null; // eslint-disable-line
}
export function isNumeric(value: string): boolean {

View File

@@ -0,0 +1,21 @@
import { isSome } from './core';
const HASHTAG_REGEX = /(?<=^|\s)#([0-9]*[\p{L}/_-][\p{L}\p{N}/_-]*)/gmu;
const WORD_REGEX = /(?<=^|\s)([0-9]*[\p{L}/_-][\p{L}\p{N}/_-]*)/gmu;
export const extractHashtags = (
text: string
): Array<{ label: string; offset: number }> => {
return isSome(text)
? Array.from(text.matchAll(HASHTAG_REGEX)).map(m => ({
label: m[1],
offset: m.index!,
}))
: [];
};
export const extractTagsFromProp = (prop: string | string[]): string[] => {
const text = Array.isArray(prop) ? prop.join(' ') : prop;
return isSome(text)
? Array.from(text.matchAll(WORD_REGEX)).map(m => m[1])
: [];
};

View File

@@ -0,0 +1,77 @@
import { extractHashtags } from './index';
import { Logger } from './log';
Logger.setLevel('error');
describe('hashtag extraction', () => {
it('returns empty list if no tags are present', () => {
expect(extractHashtags('hello world')).toEqual([]);
});
it('works with simple strings', () => {
expect(
extractHashtags('hello #world on #this planet').map(t => t.label)
).toEqual(['world', 'this']);
});
it('detects the offset of the tag', () => {
expect(extractHashtags('#hello')).toEqual([{ label: 'hello', offset: 0 }]);
expect(extractHashtags(' #hello')).toEqual([{ label: 'hello', offset: 1 }]);
expect(extractHashtags('to #hello')).toEqual([
{ label: 'hello', offset: 3 },
]);
});
it('works with tags at beginning or end of text', () => {
expect(
extractHashtags('#hello world on this #planet').map(t => t.label)
).toEqual(['hello', 'planet']);
});
it('supports _ and -', () => {
expect(
extractHashtags('#hello-world on #this_planet').map(t => t.label)
).toEqual(['hello-world', 'this_planet']);
});
it('supports nested tags', () => {
expect(
extractHashtags('#parent/child on #planet').map(t => t.label)
).toEqual(['parent/child', 'planet']);
});
it('ignores tags that only have numbers in text', () => {
expect(
extractHashtags('this #123 tag should be ignore, but not #123four').map(
t => t.label
)
).toEqual(['123four']);
});
it('supports unicode letters like Chinese charaters', () => {
expect(
extractHashtags(`
this #tag_with_unicode_letters_汉字, pure Chinese tag like #纯中文标签 and
other mixed tags like #标签1 #123四 should work
`).map(t => t.label)
).toEqual([
'tag_with_unicode_letters_汉字',
'纯中文标签',
'标签1',
'123四',
]);
});
it('ignores hashes in plain text urls and links', () => {
expect(
extractHashtags(`
test text with url https://site.com/#section1 https://site.com/home#section2 and
https://site.com/home/#section3a
[link](https://site.com/#section4) with [link2](https://site.com/home#section5) #control
hello world
`).map(t => t.label)
).toEqual(['control']);
});
it('ignores hashes in links to sections', () => {
expect(
extractHashtags(`
this is a wikilink to [[#section1]] in the file and a [[link#section2]] in another
this is a [link](#section3) to a section
`)
).toEqual([]);
});
});

View File

@@ -0,0 +1,97 @@
import { workspace } from 'vscode';
import { createDailyNoteIfNotExists, getDailyNotePath } from './dated-notes';
import { URI } from './core/model/uri';
import { isWindows } from './utils';
import {
cleanWorkspace,
closeEditors,
createFile,
showInEditor,
} from './test/test-utils-vscode';
describe('getDailyNotePath', () => {
const date = new Date('2021-02-07T00:00:00Z');
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const isoDate = `${year}-0${month}-0${day}`;
test('Adds the root directory to relative directories', async () => {
const config = 'journal';
const expectedPath = URI.joinPath(
workspace.workspaceFolders[0].uri,
config,
`${isoDate}.md`
);
const oldValue = await workspace
.getConfiguration('foam')
.get('openDailyNote.directory');
await workspace
.getConfiguration('foam')
.update('openDailyNote.directory', config);
const foamConfiguration = workspace.getConfiguration('foam');
expect(URI.toFsPath(getDailyNotePath(foamConfiguration, date))).toEqual(
URI.toFsPath(expectedPath)
);
await workspace
.getConfiguration('foam')
.update('openDailyNote.directory', oldValue);
});
test('Uses absolute directories without modification', async () => {
const config = isWindows
? 'c:\\absolute_path\\journal'
: '/absolute_path/journal';
const expectedPath = isWindows
? `${config}\\${isoDate}.md`
: `${config}/${isoDate}.md`;
const oldValue = await workspace
.getConfiguration('foam')
.get('openDailyNote.directory');
await workspace
.getConfiguration('foam')
.update('openDailyNote.directory', config);
const foamConfiguration = workspace.getConfiguration('foam');
expect(URI.toFsPath(getDailyNotePath(foamConfiguration, date))).toMatch(
expectedPath
);
await workspace
.getConfiguration('foam')
.update('openDailyNote.directory', oldValue);
});
});
describe('Daily note template', () => {
it('Uses the daily note variables in the template', async () => {
const targetDate = new Date(2021, 8, 12);
// eslint-disable-next-line no-template-curly-in-string
await createFile('hello ${FOAM_DATE_MONTH_NAME} ${FOAM_DATE_DATE} hello', [
'.foam',
'templates',
'daily-note.md',
]);
const config = workspace.getConfiguration('foam');
const uri = getDailyNotePath(config, targetDate);
await createDailyNoteIfNotExists(config, uri, targetDate);
const doc = await showInEditor(uri);
const content = doc.editor.document.getText();
expect(content).toEqual('hello September 12 hello');
});
afterAll(async () => {
await cleanWorkspace();
await closeEditors();
});
});

View File

@@ -1,49 +0,0 @@
import { Uri, workspace } from 'vscode';
import { getDailyNotePath } from './dated-notes';
import { URI } from 'foam-core';
import { isWindows } from './utils';
describe('getDailyNotePath', () => {
const date = new Date('2021-02-07T00:00:00Z');
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const isoDate = `${year}-0${month}-0${day}`;
test('Adds the root directory to relative directories', async () => {
const config = 'journal';
const expectedPath = Uri.joinPath(
workspace.workspaceFolders[0].uri,
config,
`${isoDate}.md`
);
await workspace
.getConfiguration('foam')
.update('openDailyNote.directory', config);
const foamConfiguration = workspace.getConfiguration('foam');
expect(URI.toFsPath(getDailyNotePath(foamConfiguration, date))).toEqual(
expectedPath.fsPath
);
});
test('Uses absolute directories without modification', async () => {
const config = isWindows
? 'c:\\absolute_path\\journal'
: '/absolute_path/journal';
const expectedPath = isWindows
? `${config}\\${isoDate}.md`
: `${config}/${isoDate}.md`;
await workspace
.getConfiguration('foam')
.update('openDailyNote.directory', config);
const foamConfiguration = workspace.getConfiguration('foam');
expect(URI.toFsPath(getDailyNotePath(foamConfiguration, date))).toMatch(
expectedPath
);
});
});

View File

@@ -1,11 +1,19 @@
import { workspace, WorkspaceConfiguration, Uri } from 'vscode';
import { workspace, WorkspaceConfiguration } from 'vscode';
import dateFormat from 'dateformat';
import * as fs from 'fs';
import { isAbsolute } from 'path';
import { docConfig, focusNote, pathExists } from './utils';
import { URI } from 'foam-core';
import { focusNote, pathExists } from './utils';
import { URI } from './core/model/uri';
import { createNoteFromDailyNoteTemplate } from './features/create-from-template';
async function openDailyNoteFor(date?: Date) {
/**
* Open the daily note file.
*
* In the case that the daily note file does not exist,
* it gets created along with any folders in its path.
*
* @param date A given date to be formatted as filename.
*/
export async function openDailyNoteFor(date?: Date) {
const foamConfiguration = workspace.getConfiguration('foam');
const currentDate = date !== undefined ? date : new Date();
@@ -19,7 +27,20 @@ async function openDailyNoteFor(date?: Date) {
await focusNote(dailyNotePath, isNew);
}
function getDailyNotePath(
/**
* Get the daily note file path.
*
* This function first checks the `foam.openDailyNote.directory` configuration string,
* defaulting to the current directory.
*
* In the case that the directory path is not absolute,
* the resulting path will start on the current workspace top-level.
*
* @param configuration The current workspace configuration.
* @param date A given date to be formatted as filename.
* @returns The path to the daily note file.
*/
export function getDailyNotePath(
configuration: WorkspaceConfiguration,
date: Date
): URI {
@@ -28,7 +49,7 @@ function getDailyNotePath(
const dailyNoteFilename = getDailyNoteFileName(configuration, date);
if (isAbsolute(dailyNoteDirectory)) {
return URI.joinPath(Uri.file(dailyNoteDirectory), dailyNoteFilename);
return URI.joinPath(URI.file(dailyNoteDirectory), dailyNoteFilename);
} else {
return URI.joinPath(
workspace.workspaceFolders[0].uri,
@@ -38,7 +59,18 @@ function getDailyNotePath(
}
}
function getDailyNoteFileName(
/**
* Get the daily note filename (basename) to use.
*
* Fetch the filename format and extension from
* `foam.openDailyNote.filenameFormat` and
* `foam.openDailyNote.fileExtension`, respectively.
*
* @param configuration The current workspace configuration.
* @param date A given date to be formatted as filename.
* @returns The daily note's filename.
*/
export function getDailyNoteFileName(
configuration: WorkspaceConfiguration,
date: Date
): string {
@@ -52,44 +84,43 @@ function getDailyNoteFileName(
return `${dateFormat(date, filenameFormat, false)}.${fileExtension}`;
}
async function createDailyNoteIfNotExists(
/**
* Create a daily note if it does not exist.
*
* In the case that the folders referenced in the file path also do not exist,
* this function will create all folders in the path.
*
* @param configuration The current workspace configuration.
* @param dailyNotePath The path to daily note file.
* @param currentDate The current date, to be used as a title.
* @returns Wether the file was created.
*/
export async function createDailyNoteIfNotExists(
configuration: WorkspaceConfiguration,
dailyNotePath: URI,
currentDate: Date
targetDate: Date
) {
if (await pathExists(dailyNotePath)) {
return false;
}
await createDailyNoteDirectoryIfNotExists(dailyNotePath);
const titleFormat: string =
configuration.get('openDailyNote.titleFormat') ??
configuration.get('openDailyNote.filenameFormat');
await fs.promises.writeFile(
URI.toFsPath(dailyNotePath),
`# ${dateFormat(currentDate, titleFormat, false)}${docConfig.eol}${
docConfig.eol
}`
const templateFallbackText: string = `---
foam_template:
name: New Daily Note
description: Foam's default daily note template
---
# ${dateFormat(targetDate, titleFormat, false)}
`;
await createNoteFromDailyNoteTemplate(
dailyNotePath,
templateFallbackText,
targetDate
);
return true;
}
async function createDailyNoteDirectoryIfNotExists(dailyNotePath: URI) {
const dailyNoteDirectory = URI.getDir(dailyNotePath);
if (!(await pathExists(dailyNoteDirectory))) {
await fs.promises.mkdir(URI.toFsPath(dailyNoteDirectory), {
recursive: true,
});
}
}
export {
openDailyNoteFor,
getDailyNoteFileName,
createDailyNoteIfNotExists,
getDailyNotePath,
};

View File

@@ -1,19 +1,15 @@
import { workspace, ExtensionContext, window } from 'vscode';
import {
bootstrap,
FoamConfig,
Logger,
FileDataStore,
Matcher,
MarkdownResourceProvider,
ResourceProvider,
} from 'foam-core';
import { FoamConfig } from './core/config';
import { MarkdownResourceProvider } from './core/markdown-provider';
import { bootstrap } from './core/model/foam';
import { FileDataStore, Matcher } from './core/services/datastore';
import { Logger } from './core/utils/log';
import { features } from './features';
import { getConfigFromVscode } from './services/config';
import { VsCodeOutputLogger, exposeLogger } from './services/logging';
function createMarkdownProvider(config: FoamConfig): ResourceProvider {
function createMarkdownProvider(config: FoamConfig): MarkdownResourceProvider {
const matcher = new Matcher(
config.workspaceFolders,
config.includeGlobs,

View File

@@ -1,16 +1,16 @@
import { workspace, window } from 'vscode';
import { URI, FoamGraph } from 'foam-core';
import { createTestNote, createTestWorkspace } from '../test/test-utils';
import {
cleanWorkspace,
closeEditors,
createNote,
createTestNote,
createTestWorkspace,
} from '../test/test-utils';
} from '../test/test-utils-vscode';
import { BacklinksTreeDataProvider, BacklinkTreeItem } from './backlinks';
import { ResourceTreeItem } from '../utils/grouped-resources-tree-data-provider';
import { OPEN_COMMAND } from './utility-commands';
import { toVsCodeUri } from '../utils/vsc-utils';
import { FoamGraph } from '../core/model/graph';
import { URI } from '../core/model/uri';
describe('Backlinks panel', () => {
beforeAll(async () => {

Some files were not shown because too many files have changed in this diff Show More