mirror of
https://github.com/foambubble/foam.git
synced 2026-01-11 06:58:11 -05:00
Compare commits
167 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d223683f1 | ||
|
|
94bf3ea469 | ||
|
|
de9224b5c7 | ||
|
|
6c0064390a | ||
|
|
2903acb34e | ||
|
|
d55b592264 | ||
|
|
e525051617 | ||
|
|
9a49c9ff66 | ||
|
|
b0727307b0 | ||
|
|
a004e61b2a | ||
|
|
1a7e633edc | ||
|
|
fb78e2baff | ||
|
|
9d143394dc | ||
|
|
249e3dd924 | ||
|
|
3398ab08ac | ||
|
|
2a197cfee5 | ||
|
|
e95aa05059 | ||
|
|
dc8df6fd1e | ||
|
|
babcbb1ec1 | ||
|
|
82e46b22ff | ||
|
|
1999b04ea2 | ||
|
|
ebc9c5761e | ||
|
|
f37f2e20a2 | ||
|
|
f11a779132 | ||
|
|
20694278a6 | ||
|
|
6a849d220b | ||
|
|
6001dc0214 | ||
|
|
93cedcc490 | ||
|
|
cad0c38965 | ||
|
|
bdb95a0832 | ||
|
|
e0580d39bf | ||
|
|
279b3b48f1 | ||
|
|
e3c63fca89 | ||
|
|
948b7db5ef | ||
|
|
503a8f5f18 | ||
|
|
8ab4f13543 | ||
|
|
894bf12899 | ||
|
|
a3b375e248 | ||
|
|
c840070a3a | ||
|
|
8a6551f281 | ||
|
|
88ae96cf25 | ||
|
|
acfd2e1fc1 | ||
|
|
6b02a87538 | ||
|
|
1a99e693df | ||
|
|
dd467ce86f | ||
|
|
7d7446ef7e | ||
|
|
6be4f002b8 | ||
|
|
bb6faee06d | ||
|
|
31cfeb3034 | ||
|
|
5d11818ffc | ||
|
|
e7ee143544 | ||
|
|
aa311b2688 | ||
|
|
0fca141a7b | ||
|
|
6a4bd341ab | ||
|
|
764750f591 | ||
|
|
2686b9a365 | ||
|
|
5a6ef644bd | ||
|
|
d7c92f8284 | ||
|
|
c2e5e4bf2a | ||
|
|
9d0ba879d2 | ||
|
|
9606dcc64c | ||
|
|
d70e441790 | ||
|
|
dde11f8c6f | ||
|
|
cd9ee4d556 | ||
|
|
a8296c2c88 | ||
|
|
13a340eb1d | ||
|
|
d2dd979e70 | ||
|
|
4989796cb0 | ||
|
|
d24814d065 | ||
|
|
4a410d1f5c | ||
|
|
ccb92ad5ee | ||
|
|
e6512cffa8 | ||
|
|
1fa4f37d96 | ||
|
|
27b9b451ad | ||
|
|
362d6f8e09 | ||
|
|
cef8d2a532 | ||
|
|
22b837f252 | ||
|
|
07e02c2d69 | ||
|
|
931ad7a5b6 | ||
|
|
db7eb9775f | ||
|
|
b25152d115 | ||
|
|
1545079c62 | ||
|
|
4835164902 | ||
|
|
06efdc2865 | ||
|
|
b68fd7e138 | ||
|
|
d8baa2fd36 | ||
|
|
7f587095e8 | ||
|
|
77ad245319 | ||
|
|
b892c783da | ||
|
|
e4f6259104 | ||
|
|
aa197239fc | ||
|
|
8f3c23dd60 | ||
|
|
9a027c08ba | ||
|
|
959d0f1ea1 | ||
|
|
57e32c4349 | ||
|
|
f168f66368 | ||
|
|
103ff12b2d | ||
|
|
96a3afa132 | ||
|
|
d586e63104 | ||
|
|
2fba6e9008 | ||
|
|
cdbb965661 | ||
|
|
0c958e31f6 | ||
|
|
fd84fcfd74 | ||
|
|
becf495edc | ||
|
|
4d99883c03 | ||
|
|
8bd679c751 | ||
|
|
8986ee286c | ||
|
|
51b1af1981 | ||
|
|
4276e8043f | ||
|
|
8d1e9b15ce | ||
|
|
bfcfad32e8 | ||
|
|
abe18cc961 | ||
|
|
9490aa2dad | ||
|
|
6c3f4588b3 | ||
|
|
21b8c5b827 | ||
|
|
c66ed74aea | ||
|
|
3876811fb6 | ||
|
|
d9299ee9d4 | ||
|
|
23e21a62f3 | ||
|
|
e7c8d5a4eb | ||
|
|
3ef1b69b2e | ||
|
|
5859b2a9c6 | ||
|
|
54086fdd7e | ||
|
|
a308dfd109 | ||
|
|
e327115673 | ||
|
|
c019767476 | ||
|
|
5e8b817a82 | ||
|
|
e0acc0ba8c | ||
|
|
df4efc5138 | ||
|
|
1e2b3b1bc3 | ||
|
|
eee364de50 | ||
|
|
3ed2bcd37b | ||
|
|
797aa9f29a | ||
|
|
30ab58485c | ||
|
|
ba98f1990c | ||
|
|
6c1d6868f7 | ||
|
|
e773e1ff68 | ||
|
|
86e2bb1ba0 | ||
|
|
fc2fb6a0ab | ||
|
|
956d0119be | ||
|
|
8ddb6a2d12 | ||
|
|
fb9447630f | ||
|
|
06a5988a52 | ||
|
|
fac2247382 | ||
|
|
b089b997bb | ||
|
|
a504054504 | ||
|
|
a00d18cfbb | ||
|
|
5ca7c3eb52 | ||
|
|
571b6a3528 | ||
|
|
b6c9eac86c | ||
|
|
557330413c | ||
|
|
20894a1166 | ||
|
|
d0b3d5ff11 | ||
|
|
34fb62bb0b | ||
|
|
f297139e0c | ||
|
|
09e13f77b0 | ||
|
|
56d8c4c7a0 | ||
|
|
626a323193 | ||
|
|
25d9b5e459 | ||
|
|
c2241f16de | ||
|
|
5dee7cb2c0 | ||
|
|
154ded382b | ||
|
|
5de69ff3c3 | ||
|
|
8aefcfd515 | ||
|
|
e0e08a2a0f | ||
|
|
93c5d2f80c | ||
|
|
1c294d84c5 |
@@ -1022,8 +1022,153 @@
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "hezhizhen",
|
||||
"name": "Zhizhen He",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/7611700?v=4",
|
||||
"profile": "https://t.me/littlepoint",
|
||||
"contributions": [
|
||||
"tool"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "tcheneau",
|
||||
"name": "Tony Cheneau",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/952059?v=4",
|
||||
"profile": "https://amnesiak.org/me",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "nicholas-l",
|
||||
"name": "Nicholas Latham",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/12977174?v=4",
|
||||
"profile": "https://github.com/nicholas-l",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "thara",
|
||||
"name": "Tomochika Hara",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/1532891?v=4",
|
||||
"profile": "https://thara.dev",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "dcarosone",
|
||||
"name": "Daniel Carosone",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/11495017?v=4",
|
||||
"profile": "https://github.com/dcarosone",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "MABruni",
|
||||
"name": "Miguel Angel Bruni Montero",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/100445384?v=4",
|
||||
"profile": "https://github.com/MABruni",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "Walshkev",
|
||||
"name": "Kevin Walsh ",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/77123083?v=4",
|
||||
"profile": "https://github.com/Walshkev",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "hereistheusername",
|
||||
"name": "Xinglan Liu",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/33437051?v=4",
|
||||
"profile": "http://hereistheusername.github.io/",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "Hegghammer",
|
||||
"name": "Thomas Hegghammer",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/64712218?v=4",
|
||||
"profile": "http://www.hegghammer.com",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "PiotrAleksander",
|
||||
"name": "Piotr Mrzygłosz",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/6314591?v=4",
|
||||
"profile": "https://github.com/PiotrAleksander",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "markschaver",
|
||||
"name": "Mark Schaver",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/7584?v=4",
|
||||
"profile": "http://schaver.com/",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "n8layman",
|
||||
"name": "Nathan Layman",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/25353944?v=4",
|
||||
"profile": "https://github.com/n8layman",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "emmanuel-ferdman",
|
||||
"name": "Emmanuel Ferdman",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/35470921?v=4",
|
||||
"profile": "https://github.com/emmanuel-ferdman",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "Tenormis",
|
||||
"name": "Tenormis",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/61572102?v=4",
|
||||
"profile": "https://github.com/Tenormis",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "djplaner",
|
||||
"name": "David Jones",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/225052?v=4",
|
||||
"profile": "http://djon.es/blog",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "s-jacob-powell",
|
||||
"name": "S. Jacob Powell",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/109111499?v=4",
|
||||
"profile": "https://github.com/s-jacob-powell",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 7,
|
||||
"skipCi": true
|
||||
"skipCi": true,
|
||||
"commitType": "docs"
|
||||
}
|
||||
|
||||
8
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
8
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@@ -74,13 +74,13 @@ body:
|
||||
id: os
|
||||
attributes:
|
||||
label: Operating System Version
|
||||
description: What opearting system are you using?
|
||||
description: What operating system are you using?
|
||||
placeholder: |
|
||||
- OS: [e.g. macOS, Windows, Linux]
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: vscode_version
|
||||
id: vscode_version
|
||||
attributes:
|
||||
label: Visual Studio Code Version
|
||||
description: |
|
||||
@@ -92,6 +92,6 @@ body:
|
||||
id: additional
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: |
|
||||
description: |
|
||||
Add any other context about the problem here.
|
||||
The Foam log output for VSCode can be found here: https://github.com/foambubble/foam/blob/master/docs/features/foam-logging-in-vscode.md
|
||||
The Foam log output for VSCode can be found here: https://github.com/foambubble/foam/blob/main/docs/user/tools/foam-logging-in-vscode.md
|
||||
|
||||
27
.github/workflows/ci.yml
vendored
27
.github/workflows/ci.yml
vendored
@@ -3,12 +3,22 @@ name: CI
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
|
||||
jobs:
|
||||
typos-check:
|
||||
name: Spell Check with Typos
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Actions Repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Check spelling with custom config file
|
||||
uses: crate-ci/typos@v1.14.8
|
||||
with:
|
||||
config: ./typos.toml
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: ubuntu-22.04
|
||||
@@ -34,12 +44,13 @@ jobs:
|
||||
|
||||
test:
|
||||
name: Build and Test
|
||||
strategy:
|
||||
matrix:
|
||||
os: [macos-12, ubuntu-22.04, windows-2022]
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
OS: ${{ matrix.os }}
|
||||
# strategy:
|
||||
# matrix:
|
||||
# os: [macos-12, ubuntu-22.04, windows-2022]
|
||||
# runs-on: ${{ matrix.os }}
|
||||
runs-on: ubuntu-22.04
|
||||
# env:
|
||||
# OS: ${{ matrix.os }}
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
10
.github/workflows/update-docs.yml
vendored
10
.github/workflows/update-docs.yml
vendored
@@ -3,9 +3,11 @@ name: Update Docs
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
paths:
|
||||
- docs/user/**/*
|
||||
- docs/.vscode/**/*
|
||||
- docs/assets/**/*
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
@@ -20,11 +22,15 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
path: foam
|
||||
- name: Copy and fixup user docs files
|
||||
- name: Copy and fixup user docs files
|
||||
id: copy
|
||||
run: |
|
||||
rm -r foam-template/docs
|
||||
rm -r foam-template/assets
|
||||
rm -r foam-template/.vscode
|
||||
cp -r foam/docs/user foam-template/docs
|
||||
cp -r foam/docs/assets foam-template/assets
|
||||
cp -r foam/docs/.vscode foam-template/.vscode
|
||||
|
||||
# Strip autogenerated wikileaks references because
|
||||
# they are not an appropriate default user experience.
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
||||
node_modules
|
||||
.DS_Store
|
||||
.vscode-test/
|
||||
.vscode-test-web/
|
||||
*.tsbuildinfo
|
||||
*.vsix
|
||||
*.log
|
||||
|
||||
23
.vscode/tasks.json
vendored
23
.vscode/tasks.json
vendored
@@ -7,7 +7,28 @@
|
||||
"label": "watch: foam-vscode",
|
||||
"type": "npm",
|
||||
"script": "watch",
|
||||
"problemMatcher": "$tsc-watch",
|
||||
"problemMatcher": {
|
||||
"owner": "typescript",
|
||||
"fileLocation": ["relative", "${workspaceFolder}"],
|
||||
"pattern": [
|
||||
{
|
||||
"regexp": "^(.*?)\\((\\d+),(\\d+)\\):\\s+(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"message": 4
|
||||
}
|
||||
],
|
||||
"background": {
|
||||
"activeOnStart": true,
|
||||
"beginsPattern": {
|
||||
"regexp": ".*"
|
||||
},
|
||||
"endsPattern": {
|
||||
"regexp": ".*"
|
||||
}
|
||||
}
|
||||
},
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"reveal": "always"
|
||||
|
||||
10
docs/.vscode/extensions.json
vendored
10
docs/.vscode/extensions.json
vendored
@@ -5,17 +5,11 @@
|
||||
// Foam's own extension
|
||||
"foam.foam-vscode",
|
||||
|
||||
// Prettier for auto formatting code
|
||||
"esbenp.prettier-vscode",
|
||||
|
||||
// GitLens for seeing version history inline
|
||||
"eamodio.gitlens",
|
||||
|
||||
// Tons of markdown goodies (lists, tables of content, so much more)
|
||||
"yzhang.markdown-all-in-one",
|
||||
|
||||
// Graph visualizer
|
||||
"tchayen.markdown-links",
|
||||
// Prettier for auto formatting code
|
||||
"esbenp.prettier-vscode",
|
||||
|
||||
// Understated grayscale theme (light and dark variants)
|
||||
"philipbe.theme-gray-matter"
|
||||
|
||||
4
docs/.vscode/foam.json
vendored
4
docs/.vscode/foam.json
vendored
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"purpose": "this file exists to tell the foam-vscode plugin that it's currently in a foam workspace",
|
||||
"future": "we may use this for custom configuration"
|
||||
}
|
||||
2
docs/.vscode/keybindings.json
vendored
2
docs/.vscode/keybindings.json
vendored
@@ -3,6 +3,6 @@
|
||||
[
|
||||
{
|
||||
"key": "cmd+shift+n",
|
||||
"command": "vscodeMarkdownNotes.newNote"
|
||||
"command": "foam-vscode.create-note"
|
||||
}
|
||||
]
|
||||
|
||||
13
docs/.vscode/settings.json
vendored
13
docs/.vscode/settings.json
vendored
@@ -5,7 +5,6 @@
|
||||
"editor.overviewRulerBorder": false,
|
||||
"editor.lineHeight": 24,
|
||||
"foam.edit.linkReferenceDefinitions": "withExtensions",
|
||||
"vscodeMarkdownNotes.noteCompletionConvention": "noExtension",
|
||||
"[markdown]": {
|
||||
"editor.quickSuggestions": {
|
||||
"other": true,
|
||||
@@ -13,21 +12,11 @@
|
||||
"strings": false
|
||||
}
|
||||
},
|
||||
"cSpell.language": "en-GB",
|
||||
"git.enableSmartCommit": true,
|
||||
"git.postCommitCommand": "sync",
|
||||
"spellright.language": [
|
||||
"en"
|
||||
],
|
||||
"spellright.documentTypes": [
|
||||
"markdown",
|
||||
"plaintext"
|
||||
],
|
||||
"files.exclude": {
|
||||
"_site/**": true
|
||||
},
|
||||
"files.insertFinalNewline": true,
|
||||
"markdown.styles": [
|
||||
".vscode/custom-tag-style.css"
|
||||
]
|
||||
"markdown.styles": [".vscode/custom-tag-style.css"]
|
||||
}
|
||||
|
||||
1
docs/.vscode/spellright.dict
vendored
1
docs/.vscode/spellright.dict
vendored
@@ -1 +0,0 @@
|
||||
Backlinking
|
||||
BIN
docs/assets/images/note-embed-type-demo.gif
Normal file
BIN
docs/assets/images/note-embed-type-demo.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 568 KiB |
BIN
docs/assets/images/pdf_output.png
Normal file
BIN
docs/assets/images/pdf_output.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
@@ -1,3 +1,8 @@
|
||||
---
|
||||
redirect_from:
|
||||
- /code-of-conduct
|
||||
---
|
||||
|
||||
# Code of Conduct
|
||||
|
||||
We follow the [Contributor Covenant](https://www.contributor-covenant.org/) code of conduct.
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
---
|
||||
tags: todo, good-first-task
|
||||
---
|
||||
|
||||
# Contribution Guide
|
||||
|
||||
Foam is open to contributions of any kind, including but not limited to code, documentation, ideas, and feedback.
|
||||
This guide aims to help guide new and seasoned contributors getting around the Foam codebase. For a comprehensive guide about contributing to open-source projects in general, [see here](https://sqldbawithabeard.com/2019/11/29/how-to-fork-a-github-repository-and-contribute-to-an-open-source-project/).
|
||||
This guide aims to help guide new and seasoned contributors getting around the Foam codebase. For a comprehensive guide about contributing to open-source projects in general, [see here](https://blog.robsewell.com/blog/how-to-fork-a-github-repository-and-contribute-to-an-open-source-project/).
|
||||
|
||||
## Getting Up To Speed
|
||||
|
||||
@@ -13,6 +14,8 @@ Before you start contributing we recommend that you read the following links:
|
||||
- [[principles]] - This document describes the guiding principles behind Foam.
|
||||
- [[code-of-conduct]] - Rules we hope every contributor aims to follow, allowing everyone to participate in our community!
|
||||
|
||||
To get yourself familiar with the codebase you can also browse [this repo](https://app.komment.ai/wiki/github/foambubble/foam)
|
||||
|
||||
## Diving In
|
||||
|
||||
We understand that diving in an unfamiliar codebase may seem scary,
|
||||
@@ -44,19 +47,19 @@ You should now be ready to start working!
|
||||
|
||||
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]].
|
||||
- [/docs](https://github.com/foambubble/foam/tree/main/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/).
|
||||
This project uses [Yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/).
|
||||
|
||||
Originally Foam had:
|
||||
|
||||
- [/packages/foam-core](https://github.com/foambubble/foam/tree/ee7a8919761f168d3931079adf21c5ad4d63db59/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.
|
||||
- [/packages/foam-vscode](https://github.com/foambubble/foam/tree/main/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.
|
||||
|
||||
@@ -81,7 +84,7 @@ Tests live alongside the code in `src`.
|
||||
|
||||
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. 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.
|
||||
1. Now we'll use the launch configuration defined at [`.vscode/launch.json`](https://github.com/foambubble/foam/blob/main/.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.
|
||||
|
||||
@@ -93,7 +96,7 @@ After you have made your changes to your copy of the project, it is time to try
|
||||
|
||||
1. Return to the project's [home repository page](https://github.com/foambubble/foam).
|
||||
2. Github should show you an button called "Compare & pull request" linking your forked repository to the community repository.
|
||||
3. Click that button and confirm that your repository is going to be merged into the community repository. See [this guide](https://sqldbawithabeard.com/2019/11/29/how-to-fork-a-github-repository-and-contribute-to-an-open-source-project/) for more specifics.
|
||||
3. Click that button and confirm that your repository is going to be merged into the community repository. See [this guide](https://blog.robsewell.com/blog/how-to-fork-a-github-repository-and-contribute-to-an-open-source-project/) for more specifics.
|
||||
4. Add as many relevant details to the PR message to make it clear to the project maintainers and other members of the community what you have accomplished with your new changes. Link to any issues the changes are related to.
|
||||
5. Your PR will then need to be reviewed and accepted by the other members of the community. Any discussion about the changes will occur in your PR thread.
|
||||
6. Once reviewed and accept you can complete the merge request!
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
# Foam Core 2020-07-11
|
||||
|
||||
Present: @jevakallio, @riccardoferretti
|
||||
|
||||
### Tests
|
||||
|
||||
- How do we know this approach works?
|
||||
- Supports renaming
|
||||
- Supports searching with (attribute-x)
|
||||
- Find dead links
|
||||
|
||||
### Getting started
|
||||
|
||||
- Land work to master
|
||||
- Create a foam-core package
|
||||
|
||||
-
|
||||
|
||||
### Open questions
|
||||
|
||||
- How should writing to files work
|
||||
- What if affected notes have unsaved changes
|
||||
|
||||
### Graph methods
|
||||
|
||||
- get all
|
||||
- search by
|
||||
- tag
|
||||
- free text
|
||||
- [[todo]]: how do vs code search editors work? are they pluggable? what do they need?
|
||||
- find dead links
|
||||
- for linters
|
||||
- serialize/toJSON (for visualizers)
|
||||
- subscribe to changes
|
||||
- find if a link exists (and which link) in a given row / column position + return it's start and end position - this would probably be needed e.g. to CTRL-hovering to work properly
|
||||
|
||||
### Node methods
|
||||
|
||||
- rename node and all links to that node
|
||||
- get links
|
||||
- forward links (for link lists)
|
||||
- backlinks (with surrounding context)
|
||||
|
||||
### Node definition
|
||||
|
||||
What do we need the node (and edge metadata) to contain:
|
||||
|
||||
- `id`: tbd
|
||||
- should be unique, needs some kind of unique gen function
|
||||
- should be reconstructable even if links are not updated every time
|
||||
- what happens during rename? is reparenting the graph going to be hard?
|
||||
- do id's need to be persistent, or can we create them per in-memory session, keep them stable despite renames, and then next session generate a new id?
|
||||
- Ideally should be a path to file, so it's easy to look up from the graph by id for renaming
|
||||
- `type`: Note | Image | etc
|
||||
- `title`: can be read from markdown title or frontmatter metadata
|
||||
- `path`: full path to file, relative to workspace (graph) root
|
||||
- `links`:
|
||||
- `id`: File to link to
|
||||
- `text`: The link label
|
||||
- `type` markdown | mediawiki | image | http
|
||||
- `section`: : Anchor link to a heading in target note, if we want to add support for linking to sections
|
||||
- `block` (ref)
|
||||
- Positional data from AST?
|
||||
- `tags`
|
||||
|
||||
### Markdown layer
|
||||
|
||||
- `source`: raw markdown (rename?)
|
||||
- `ast`: raw markdown ast
|
||||
- `checksum`: if we do caching
|
||||
|
||||
### Link text
|
||||
|
||||
// some-file.md
|
||||
// # Some File
|
||||
|
||||
Write -> Store on disk
|
||||
[[Some File]] -> [Some File](some-file.md)
|
||||
|
||||
Editing
|
||||
[Some File](some-file.md)
|
||||
|
||||
On disk (could be solved by migration)
|
||||
[[some-file]]
|
||||
[[Some File]]
|
||||
|
||||
- docs/index.md -> Index
|
||||
- notes/index.md -> Index
|
||||
|
||||
[[Index]]
|
||||
[[Index | notes/index.md]]
|
||||
|
||||
[Index] docs/index.md
|
||||
[Index | notes/index.md]: notes/index.md
|
||||
|
||||
[[Some File | path/to/some-file.md]]
|
||||
|
||||
Do we apply any constraints:
|
||||
|
||||
- `[[file-name-without-extension]]`
|
||||
- `[[file-name-with-extension.md]]`
|
||||
- `[[Title Cased File Name]]`
|
||||
|
||||
Not supported by Markdown Notes:
|
||||
|
||||
- `[[path/to/file-name.md]]` - Just use markdown links
|
||||
- `[[Target Note Title]]`
|
||||
|
||||
Issues:
|
||||
|
||||
- Name clashes in directories
|
||||
- Name clashes between extensions
|
||||
- Renaming
|
||||
- Change filename/title needs to reflect everywhere
|
||||
- Orphaning
|
||||
|
||||
- If we can't rely on in-memory process to rename things correctly while changes happen (e.g. file is renamed, moved, deleted, or titled) <ref id="1" />
|
||||
|
||||
Solving this issue is necessarily heuristic. We could try to write smart solutions, plus a linter for orphans
|
||||
|
||||
How others solve this:
|
||||
|
||||
- Unique ids -- could support optionally as part of file name or front matter metadata. Should not be required.
|
||||
|
||||
[//begin]: # "Autogenerated link references for markdown compatibility"
|
||||
[todo]: ../todo.md "Todo"
|
||||
[Index]: ../../index.md "Foam"
|
||||
[//end]: # "Autogenerated link references"
|
||||
@@ -14,7 +14,7 @@ Currently it is not possible within Foam to include other notes into a note. Nex
|
||||
|
||||
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.
|
||||
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 possibilities 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
|
||||
|
||||
@@ -29,7 +29,7 @@ The minimal functionality is the ability to fully include a note. Markup used in
|
||||
|
||||
### 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:
|
||||
It could be interesting to only include a section of a note instead of the entire note. In order to do so the user should be able to use the following syntax:
|
||||
|
||||
`![[wikilink#section-b]]`
|
||||
|
||||
@@ -37,11 +37,11 @@ As a result it will include the section title + section content until the next s
|
||||
|
||||
### 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:
|
||||
As a user I could be interested in collecting the value of any given property 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.
|
||||
The property value should be looked up 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:
|
||||
|
||||
|
||||
@@ -66,8 +66,9 @@ The potential solution:
|
||||
- For edit-time
|
||||
- Make edit-time link reference definition generation optional via user settings. They should be on by default, and generating valid markdown links with a relative path to a `.md` file.
|
||||
- Make format of the link reference definition configurable (whether to include '.md' or not)
|
||||
- Out of recommended extensions, currently only "markdown links" doesn't support them (?). However even its [code](https://github.com/tchayen/markdown-links/blob/master/src/parsing.ts#L25) seems to include wikilink parser, so it might just be a bug?
|
||||
- Out of recommended extensions, currently only "markdown links" doesn't support them (?). However even its [code](https://github.com/tchayen/markdown-links/blob/main/src/parsing.ts#L25) seems to include wikilink parser, so it might just be a bug?
|
||||
- For build-time
|
||||
|
||||
- To satisfy mutually incompatible constraints between GitHub UI, VSCode UI, and GitHub Pages, we should add a pre-processing/build step for pushing to GitHub Pages.
|
||||
- This would be a GitHub action (or a local script, ran via foam-cli) that outputs publish-friendly markdown format for static site generators and other publishing tools
|
||||
- This build step should be pluggable, so that other transformations could be ran during it
|
||||
@@ -117,7 +118,7 @@ The potential solution:
|
||||
enum LinkReferenceDefinitions {
|
||||
Off, // link reference definitions are not generated
|
||||
WithExtensions, // link reference definitions contain .md (or similar) file extensions
|
||||
WithoutExtensions // link reference definitions do not contain file extenions
|
||||
WithoutExtensions // link reference definitions do not contain file extensions
|
||||
}
|
||||
|
||||
```
|
||||
@@ -125,6 +126,7 @@ 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.
|
||||
- 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).
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ If you want to pick up work in this category, you should have a plan on how long
|
||||
|
||||
Everything else, categorised into themes. Just because something is on this list doesn't mean it'll get done. If you're interested in working on items in this category, check the [[contribution-guide]] for how to get started.
|
||||
|
||||
If a roadmap item is a stub, **consider** opening a [GitHub issue](https://github.com/foambubble/foam/issues) to start a conversation to avoid situations where the implementation does not fit long term vision and roadmap. _Note that this is optional. The only centralised governance in Foam is to decide what ends up in the official [template](https://github.com/foambubble/foam-template), [documentation](https://github.com/foambubble/foam) and [extension](https://github.com/foambubble/foam/tree/master/packages/foam-vscode). You are free to build whatever you want for yourself, and we'd love if you shared it with us, but you are by no means obligated to do so!_
|
||||
If a roadmap item is a stub, **consider** opening a [GitHub issue](https://github.com/foambubble/foam/issues) to start a conversation to avoid situations where the implementation does not fit long term vision and roadmap. _Note that this is optional. The only centralised governance in Foam is to decide what ends up in the official [template](https://github.com/foambubble/foam-template), [documentation](https://github.com/foambubble/foam) and [extension](https://github.com/foambubble/foam/tree/main/packages/foam-vscode). You are free to build whatever you want for yourself, and we'd love if you shared it with us, but you are by no means obligated to do so!_
|
||||
|
||||
**When creating GitHub issues to discuss roadmap items, link them here.**
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
# Releasing Foam
|
||||
|
||||
1. Get to the latest code
|
||||
- `git checkout master && git fetch && git rebase`
|
||||
- `git checkout main && git fetch && git rebase`
|
||||
2. Sanity checks
|
||||
- `yarn reset`
|
||||
- `yarn test`
|
||||
3. Update change log
|
||||
3. Update change log
|
||||
- `./packages/foam-vscode/CHANGELOG.md`
|
||||
- `git add *`
|
||||
- `git commit -m"Preparation for next release"`
|
||||
4. Update version
|
||||
- `$ yarn version-extension <version>` (where `version` is `patch/minor/major`)
|
||||
- `$ yarn version-extension <version>` (where `version` is `patch/minor/major`)
|
||||
5. Package extension
|
||||
- `$ yarn package-extension`
|
||||
6. Publish extension
|
||||
@@ -20,6 +20,6 @@
|
||||
- select "tags" in top left
|
||||
- select the tag that was just released, click "edit" and copy release information from changelog
|
||||
- publish (no need to attach artifacts)
|
||||
8. Annouce on Discord
|
||||
8. Announce on Discord
|
||||
|
||||
Steps 1 to 6 should really be replaced by a GitHub action...
|
||||
Steps 1 to 6 should really be replaced by a GitHub action...
|
||||
|
||||
@@ -10,7 +10,6 @@ Uncategorised thoughts, to be added
|
||||
- Investigate other similar extensions:
|
||||
- [Unotes](https://marketplace.visualstudio.com/items?itemName=ryanmcalister.Unotes)
|
||||
- [vscode-memo](https://github.com/svsool/vscode-memo)
|
||||
- [gistpad wiki](https://github.com/jevakallio/gistpad/tree/master/src/repos/wiki)
|
||||
- Open in Foam
|
||||
- When you want to open a Foam published website in your own VS Code, we could have a "Open in Foam" link that opens the link in VS Code via a url binding (if possible), downloads the github repo locally, and opens it as a Foam workspace.
|
||||
- Every Foam could have a different theme even in the editor, so you'll see it like they see it
|
||||
|
||||
@@ -60,17 +60,17 @@ These instructions assume you have a GitHub account, and you have Visual Studio
|
||||
|
||||
<a class="github-button" href="https://github.com/foambubble/foam-template/generate" data-icon="octicon-repo-template" data-size="large" aria-label="Use this template foambubble/foam-template on GitHub">Use this template</a>
|
||||
|
||||
*If you want to keep your thoughts to yourself, remember to set the repository private, or if you don't want to use GitHub to host your workspace at all, choose [**Download as ZIP**](https://github.com/foambubble/foam-template/archive/master.zip) instead of **Use this template**.*
|
||||
_If you want to keep your thoughts to yourself, remember to set the repository private, or if you don't want to use GitHub to host your workspace at all, choose [**Download as ZIP**](https://github.com/foambubble/foam-template/archive/main.zip) instead of **Use this template**._
|
||||
|
||||
2. [Clone the repository locally](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) and open it in VS Code.
|
||||
|
||||
*Open the repository as a folder using the `File > Open...` menu item. In VS Code, "open workspace" refers to [multi-root workspaces](https://code.visualstudio.com/docs/editor/multi-root-workspaces).*
|
||||
_Open the repository as a folder using the `File > Open...` menu item. In VS Code, "open workspace" refers to [multi-root workspaces](https://code.visualstudio.com/docs/editor/multi-root-workspaces)._
|
||||
|
||||
3. When prompted to install recommended extensions, click **Install all** (or **Show Recommendations** if you want to review and install them one by one)
|
||||
|
||||
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.*
|
||||
- _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]].
|
||||
|
||||
@@ -249,6 +249,28 @@ If that sounds like something you're interested in, I'd love to have you along o
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://yongliangliu.com"><img src="https://avatars.githubusercontent.com/u/41845017?v=4?s=60" width="60px;" alt="Liu YongLiang"/><br /><sub><b>Liu YongLiang</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=tlylt" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://scottakerman.com"><img src="https://avatars.githubusercontent.com/u/15224439?v=4?s=60" width="60px;" alt="Scott Akerman"/><br /><sub><b>Scott Akerman</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=Skakerman" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://www.jim-graham.net/"><img src="https://avatars.githubusercontent.com/u/430293?v=4?s=60" width="60px;" alt="Jim Graham"/><br /><sub><b>Jim Graham</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=jimgraham" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://t.me/littlepoint"><img src="https://avatars.githubusercontent.com/u/7611700?v=4?s=60" width="60px;" alt="Zhizhen He"/><br /><sub><b>Zhizhen He</b></sub></a><br /><a href="#tool-hezhizhen" title="Tools">🔧</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://amnesiak.org/me"><img src="https://avatars.githubusercontent.com/u/952059?v=4?s=60" width="60px;" alt="Tony Cheneau"/><br /><sub><b>Tony Cheneau</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=tcheneau" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/nicholas-l"><img src="https://avatars.githubusercontent.com/u/12977174?v=4?s=60" width="60px;" alt="Nicholas Latham"/><br /><sub><b>Nicholas Latham</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=nicholas-l" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://thara.dev"><img src="https://avatars.githubusercontent.com/u/1532891?v=4?s=60" width="60px;" alt="Tomochika Hara"/><br /><sub><b>Tomochika Hara</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=thara" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/dcarosone"><img src="https://avatars.githubusercontent.com/u/11495017?v=4?s=60" width="60px;" alt="Daniel Carosone"/><br /><sub><b>Daniel Carosone</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=dcarosone" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/MABruni"><img src="https://avatars.githubusercontent.com/u/100445384?v=4?s=60" width="60px;" alt="Miguel Angel Bruni Montero"/><br /><sub><b>Miguel Angel Bruni Montero</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=MABruni" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Walshkev"><img src="https://avatars.githubusercontent.com/u/77123083?v=4?s=60" width="60px;" alt="Kevin Walsh "/><br /><sub><b>Kevin Walsh </b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=Walshkev" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://hereistheusername.github.io/"><img src="https://avatars.githubusercontent.com/u/33437051?v=4?s=60" width="60px;" alt="Xinglan Liu"/><br /><sub><b>Xinglan Liu</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=hereistheusername" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://www.hegghammer.com"><img src="https://avatars.githubusercontent.com/u/64712218?v=4?s=60" width="60px;" alt="Thomas Hegghammer"/><br /><sub><b>Thomas Hegghammer</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=Hegghammer" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/PiotrAleksander"><img src="https://avatars.githubusercontent.com/u/6314591?v=4?s=60" width="60px;" alt="Piotr Mrzygłosz"/><br /><sub><b>Piotr Mrzygłosz</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=PiotrAleksander" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://schaver.com/"><img src="https://avatars.githubusercontent.com/u/7584?v=4?s=60" width="60px;" alt="Mark Schaver"/><br /><sub><b>Mark Schaver</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=markschaver" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/n8layman"><img src="https://avatars.githubusercontent.com/u/25353944?v=4?s=60" width="60px;" alt="Nathan Layman"/><br /><sub><b>Nathan Layman</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=n8layman" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/emmanuel-ferdman"><img src="https://avatars.githubusercontent.com/u/35470921?v=4?s=60" width="60px;" alt="Emmanuel Ferdman"/><br /><sub><b>Emmanuel Ferdman</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=emmanuel-ferdman" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Tenormis"><img src="https://avatars.githubusercontent.com/u/61572102?v=4?s=60" width="60px;" alt="Tenormis"/><br /><sub><b>Tenormis</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=Tenormis" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="http://djon.es/blog"><img src="https://avatars.githubusercontent.com/u/225052?v=4?s=60" width="60px;" alt="David Jones"/><br /><sub><b>David Jones</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=djplaner" title="Documentation">📖</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/s-jacob-powell"><img src="https://avatars.githubusercontent.com/u/109111499?v=4?s=60" width="60px;" alt="S. Jacob Powell"/><br /><sub><b>S. Jacob Powell</b></sub></a><br /><a href="https://github.com/foambubble/foam/commits?author=s-jacob-powell" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
# Backlinking
|
||||
|
||||
When using [[wikilinks]], you can find all notes that link to a specific note in the **Backlinks Explorer**
|
||||
When using [[wikilinks]], you can find all notes that link to a specific note in the **Connections Explorer**
|
||||
|
||||
- Run `Cmd` + `Shift` + `P` (`Ctrl` + `Shift` + `P` for Windows), type "backlinks" and run the **Explorer: Focus on Backlinks** view.
|
||||
- Run `Cmd` + `Shift` + `P` (`Ctrl` + `Shift` + `P` for Windows), type "connections" and run the **Explorer: Focus on Connections** view.
|
||||
- Keep this pane always visible to discover relationships between your thoughts
|
||||
- You can drag the backlinks pane to a different section in VS Code if you prefer. See: [[make-backlinks-more-prominent]]
|
||||
- You can drag the connections panel to a different section in VS Code if you prefer. See: [[make-backlinks-more-prominent]]
|
||||
- You can filter the connections to see just backlinks, forward links, or all connections
|
||||
- Finding backlinks in published Foam workspaces via [[materialized-backlinks]] is on the [[roadmap]] but not yet implemented.
|
||||
|
||||
[//begin]: # "Autogenerated link references for markdown compatibility"
|
||||
|
||||
29
docs/user/features/built-in-note-embedding-types.md
Normal file
29
docs/user/features/built-in-note-embedding-types.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Built-In Note Embedding Types
|
||||
|
||||
When embedding a note, there are a few ways to modify the scope of the content as well as its display style. The following are Foam keywords that are used to describe note embedding.
|
||||
|
||||
Note, this only applies to note embedding, not embedding of attachments or images.
|
||||
|
||||

|
||||
|
||||
## Scope
|
||||
|
||||
- `full` - the entire note in the case of `![[note]]` or the entire section in the case of `![[note#section1]]`
|
||||
- `content` - everything excluding the title of the section. So the entire note minus the title for `![[note]]`, or the entire section minus the section header for `![[note#section1]]`
|
||||
|
||||
## Style
|
||||
|
||||
- `card` - outlines the embedded note with a border
|
||||
- `inline` - adds the note continuously as if the text were part of the calling note
|
||||
|
||||
## Default Setting
|
||||
|
||||
Foam expresses note display type as `<scope>-<style>`.
|
||||
|
||||
By default, Foam configures note embedding to be `full-card`. That is, whenever the standard embedding syntax is used, `![[note]]`, the note will have `full` scope and `card` style display. This setting is stored under `foam.preview.embedNoteStyle` and can be modified.
|
||||
|
||||
## Explicit Modifiers
|
||||
|
||||
Prepend the wikilink with one of the scope or style keywords, or a combination of the two to explicitly modify a note embedding if you would like to override the default setting.
|
||||
|
||||
For example, given your `foam.embedNoteStyle` is set to `content-card`, embedding a note with standard syntax `![[note-a]]` would show a bordered note without its title. Say, for a specific `note-b` you would like to display the title. You can simply use one of the above keywords to override your default setting like so: `full![[note-b]]`. In this case, `full` overrides the default `content` scope and because a style is not specified, it falls back to the default style setting, `card`. If you would like it to be inline, override that as well: `full-inline![[note-b]]`.
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Foam has various commands that you can explore by calling the command palette and typing "Foam".
|
||||
|
||||
In particular, some commands can be very customizible and can help with custom workflows and use cases.
|
||||
In particular, some commands can be very customizable and can help with custom workflows and use cases.
|
||||
|
||||
## foam-vscode.create-note command
|
||||
|
||||
@@ -10,13 +10,13 @@ This command creates a note.
|
||||
Although it works fine on its own, it can be customized to achieve various use cases.
|
||||
Here are the settings available for the command:
|
||||
|
||||
- notePath: The path of the note to create. If relative it will be resolved against the workspace root.
|
||||
- templatePath: The path of the template to use. If relative it will be resolved against the workspace root.
|
||||
- title: The title of the note (that is, the `FOAM_TITLE` variable)
|
||||
- text: The text to use for the note. If also a template is provided, the template has precedence
|
||||
- variables: Variables to use in the text or template
|
||||
- date: The date used to resolve the FOAM*DATE*\* variables. in `YYYY-MM-DD` format
|
||||
- onFileExists?: 'overwrite' | 'open' | 'ask' | 'cancel': What to do in case the target file already exists
|
||||
- `notePath`: The path of the note to create. If relative it will be resolved against the workspace root.
|
||||
- `templatePath`: The path of the template to use. If relative it will be resolved against the workspace root.
|
||||
- `title`: The title of the note (that is, the `FOAM_TITLE` variable)
|
||||
- `text`: The text to use for the note. If also a template is provided, the template has precedence
|
||||
- `variables`: Variables to use in the text or template
|
||||
- `date`: The date used to resolve the FOAM*DATE*\* variables. in `YYYY-MM-DD` format
|
||||
- `onFileExists?: 'overwrite' | 'open' | 'ask' | 'cancel'`: What to do in case the target file already exists
|
||||
|
||||
To customize a command and associate a key binding to it, open the key binding settings and add the appropriate configuration, here are some examples:
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Daily Notes
|
||||
|
||||
Daily notes allow you to quickly create and access a new notes file for each day. This is a surpisingly effective and increasingly common strategy to organize notes and manage events.
|
||||
Daily notes allow you to quickly create and access a new notes file for each day. This is a surprisingly effective and increasingly common strategy to organize notes and manage events.
|
||||
|
||||
View today's note file by running the `Foam: Open Daily Note` command, by using the shortcut `alt+d` (note: shortcuts can be [overridden](https://code.visualstudio.com/docs/getstarted/keybindings)), or by using [#snippets](#Snippets). The name, location, and title of daily notes files is [#configurable](#Configuration).
|
||||
View today's note file by running the `Foam: Open Daily Note` command, by using the shortcut `alt+d` (note: shortcuts can be [overridden](https://code.visualstudio.com/docs/getstarted/keybindings)), or by using [#snippets](#Snippets). The name, location, and title of daily notes files are [#configurable](#Configuration).
|
||||
|
||||
## Roam-style Automatic Daily Notes
|
||||
|
||||
@@ -29,11 +29,11 @@ Create a link to a recent daily note using [snippets](https://code.visualstudio.
|
||||
|
||||
## Configuration
|
||||
|
||||
By default, Daily Notes will be created in a file called `yyyy-mm-dd.md` in the workspace's `journals` folder, with a heading `yyyy-mm-dd`.
|
||||
By default, Daily Notes will be created in a file called `yyyy-mm-dd.md` in the workspace's `journals` folder, with the heading `yyyy-mm-dd`.
|
||||
|
||||
These settings can be overridden in your workspace or global `.vscode/settings.json` file, using the [**dateformat** date masking syntax](https://github.com/felixge/node-dateformat#mask-options):
|
||||
|
||||
It's possible to customize path and heading of your daily notes, by following the [dateformat masking syntax](https://github.com/felixge/node-dateformat#mask-options).
|
||||
It's possible to customize the path and heading of your daily notes, by following the [dateformat masking syntax](https://github.com/felixge/node-dateformat#mask-options).
|
||||
The following properties can be used:
|
||||
|
||||
```json
|
||||
@@ -45,7 +45,7 @@ The following properties can be used:
|
||||
|
||||
The above configuration would create a file `journal/daily-note-2020-07-25.mdx`, with the heading `Journal Entry, Sunday, July 25`.
|
||||
|
||||
> NOTE: It is possible to set the filepath of a daily note according to the date using the special [[note-properties]] configurable for [[Note Templates]]. Specifically see [[note-templates#Example of date-based|Example of date-based filepath]]. Using the template property will override any setting configured through `.vscode/settings.json`.
|
||||
> NOTE: It is possible to set the filepath of a daily note according to the date using the special [[note-properties]] configurable for [[Note Templates]]. Specifically, see [[note-templates#Example of date-based|Example of date-based filepath]]. Using the template property will override any setting configured through `.vscode/settings.json`.
|
||||
|
||||
## Extend Functionality (Weekly, Monthly, Quarterly Notes)
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ A sample configuration object is provided below, you can provide as many or as l
|
||||
"foam.graph.style": {
|
||||
"background": "#202020",
|
||||
"fontSize": 12,
|
||||
"fontFamily": "Sans-Serif",
|
||||
"lineColor": "#277da1",
|
||||
"lineWidth": 0.2,
|
||||
"particleWidth": 1.0,
|
||||
@@ -50,6 +51,7 @@ A sample configuration object is provided below, you can provide as many or as l
|
||||
|
||||
- `background` background color of the graph, adjust to increase contrast
|
||||
- `fontSize` size of the title font for each node
|
||||
- `fontFamily` font of the title font for each node
|
||||
- `lineColor` color of the edges between nodes in the graph
|
||||
- `lineWidth` thickness of the edges between nodes
|
||||
- `particleWidth` size of the particle animation showing link direction when highlighting a node
|
||||
@@ -62,7 +64,7 @@ It is possible to customize the style of a node based on the `type` property in
|
||||
|
||||
There are a few default node types defined by Foam that are displayed in the graph:
|
||||
|
||||
- `note` defines the color for regular nodes whose documents have not overriden the `type` property.
|
||||
- `note` defines the color for regular nodes whose documents have not overridden the `type` property.
|
||||
- `placeholder` defines the color for links that don't match any existing note. This is a [[placeholder]] because no file with such name exists.
|
||||
- see [[wikilinks]] for more info <!--NOTE: this placeholder link should NOT have an associated file. This is to demonstrate the custom coloring-->
|
||||
- `tag` defines the color for nodes representing #tags, allowing tags to be used as graph nodes similar to backlinks.
|
||||
|
||||
@@ -4,17 +4,20 @@ In some situations it might be useful to include the content of another note in
|
||||
|
||||
## Including a note
|
||||
|
||||
Including a note can be done by adding an `!` before a wikilink defintion. For example `![[wikilink]]`.
|
||||
Including a note can be done by adding an `!` before a wikilink definition. For example `![[wikilink]]`.
|
||||
|
||||
## Custom styling
|
||||
|
||||
Displaying the inclusion of notes allows for some custom styling, see [[custom-markdown-preview-styles]]
|
||||
To modify how an embedded note looks and the scope of its content, see [[built-in-note-embedding-types]]
|
||||
|
||||
For more fine-grained 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]: ../../dev/proposals/inclusion-of-notes.md "Inclusion of notes Proposal "
|
||||
[//end]: # "Autogenerated link references"
|
||||
[//begin]: # 'Autogenerated link references for markdown compatibility'
|
||||
[built-in-note-embedding-types]: built-in-note-embedding-types.md 'Built-In Note Embedding Types'
|
||||
[custom-markdown-preview-styles]: custom-markdown-preview-styles.md 'Custom Markdown Preview Styles'
|
||||
[inclusion-of-notes]: ../../dev/proposals/inclusion-of-notes.md 'Inclusion of notes Proposal '
|
||||
[//end]: # 'Autogenerated link references'
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
# Link Reference Definitions
|
||||
|
||||
When you use `[[wikilinks]]`, the [foam-vscode](https://github.com/foambubble/foam/tree/master/packages/foam-vscode) extension can automatically generate [Markdown Link Reference Definitions](https://spec.commonmark.org/0.29/#link-reference-definitions) at the bottom of the file. This is not needed to navigate your workspace with foam-vscode, but is useful for files to remain compatible with various Markdown tools (e.g. parsers, static site generators, VS code plugins etc), which don't support `[[wikilinks]]`.
|
||||
When you use `[[wikilinks]]`, the [foam-vscode](https://github.com/foambubble/foam/tree/main/packages/foam-vscode) extension can automatically generate [Markdown Link Reference Definitions](https://spec.commonmark.org/0.29/#link-reference-definitions) at the bottom of the file. This is not needed to navigate your workspace with foam-vscode, but is useful for files to remain 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
|
||||
- [[wikilinks]]
|
||||
- [[github-pages]]
|
||||
```
|
||||
```md
|
||||
- [[wikilinks]]
|
||||
- [[github-pages]]
|
||||
```
|
||||
|
||||
...generates the following link reference definitions to the bottom of the file:
|
||||
|
||||
```md
|
||||
[wikilinks]: wikilinks "Wikilinks"
|
||||
[github-pages]: github-pages "GitHub Pages"
|
||||
```
|
||||
```md
|
||||
[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
|
||||
You can open the [raw markdown](https://foambubble.github.io/foam/user/features/link-reference-definitions.md) to see them at the bottom of this file
|
||||
|
||||
## Specification
|
||||
|
||||
@@ -52,15 +53,15 @@ There are three options for excluding files from your Foam project:
|
||||
|
||||
1. `files.exclude` (from VSCode) will prevent the folder from showing in the file explorer.
|
||||
|
||||
> "Configure glob patterns for excluding files and folders. For example, the file explorer decides which files and folders to show or hide based on this setting. Refer to the Search: Exclude setting to define search-specific excludes."
|
||||
> "Configure glob patterns for excluding files and folders. For example, the file explorer decides which files and folders to show or hide based on this setting. Refer to the Search: Exclude setting to define search-specific excludes."
|
||||
|
||||
2. `files.watcherExclude` (from VSCode) prevents VSCode from constantly monitoring files for changes.
|
||||
|
||||
> "Configure paths or glob patterns to exclude from file watching. Paths or basic glob patterns that are relative (for example `build/output` or `*.js`) will be resolved to an absolute path using the currently opened workspace. Complex glob patterns must match on absolute paths (i.e. prefix with `**/` or the full path and suffix with `/**` to match files within a path) to match properly (for example `**/build/output/**` or `/Users/name/workspaces/project/build/output/**`). When you experience the file watcher process consuming a lot of CPU, make sure to exclude large folders that are of less interest (such as build output folders)."
|
||||
> "Configure paths or glob patterns to exclude from file watching. Paths or basic glob patterns that are relative (for example `build/output` or `*.js`) will be resolved to an absolute path using the currently opened workspace. Complex glob patterns must match on absolute paths (i.e. prefix with `**/` or the full path and suffix with `/**` to match files within a path) to match properly (for example `**/build/output/**` or `/Users/name/workspaces/project/build/output/**`). When you experience the file watcher process consuming a lot of CPU, make sure to exclude large folders that are of less interest (such as build output folders)."
|
||||
|
||||
3. `foam.files.ignore` (from Foam) ignores files from being added to the Foam graph.
|
||||
|
||||
> "Specifies the list of globs that will be ignored by Foam (e.g. they will not be considered when creating the graph). To ignore the all the content of a given folder, use `<folderName>/**/*`" (requires reloading VSCode to take effect).
|
||||
> "Specifies the list of globs that will be ignored by Foam (e.g. they will not be considered when creating the graph). To ignore the all the content of a given folder, use `<folderName>/**/*`" (requires reloading VSCode to take effect).
|
||||
|
||||
For instance, if you're using a local instance of [Jekyll](https://jekyllrb.com/), you may find that it writes copies of each `.md` file into a `_site` directory, which may lead to Foam generating references to them instead of the original source notes.
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ keywords: hello world, bonjour
|
||||
---
|
||||
```
|
||||
|
||||
This sets the `type` of this document to `feature` and sets **three** keywords for the document: `hello`, `world`, and `bonjour`. The YAML parser will treat both spaces and commas as the seperators for these YAML properties. If you want to use multi-word values for these properties, you will need to combine the words with dashes or underscores (i.e. instead of `hello world`, use `hello_world` or `hello-world`).
|
||||
This sets the `type` of this document to `feature` and sets **three** keywords for the document: `hello`, `world`, and `bonjour`. The YAML parser will treat both spaces and commas as the separators for these YAML properties. If you want to use multi-word values for these properties, you will need to combine the words with dashes or underscores (i.e. instead of `hello world`, use `hello_world` or `hello-world`).
|
||||
|
||||
> You can set as many custom properties for a document as you like, but there are a few [special properties](#special-properties) defined by Foam.
|
||||
|
||||
@@ -27,11 +27,12 @@ This sets the `type` of this document to `feature` and sets **three** keywords f
|
||||
|
||||
Some properties have special meaning for Foam:
|
||||
|
||||
| Name | Description |
|
||||
| -------------------- | ------------------- |
|
||||
| `title` | will assign the name to the note that you will see in the graph, regardless of the filename or the first heading (also see how to [[write-notes-in-foam]]) |
|
||||
| `type` | can be used to style notes differently in the graph (also see [[graph-visualization]]). The default type for a document is `note` unless otherwise specified with this property. |
|
||||
| `tags` | can be used to add tags to a note (see [[tags]]) |
|
||||
| Name | Description |
|
||||
| ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `title` | will assign the name to the note that you will see in the graph, regardless of the filename or the first heading (also see how to [[write-notes-in-foam]]) |
|
||||
| `type` | can be used to style notes differently in the graph (also see [[graph-visualization]]). The default type for a document is `note` unless otherwise specified with this property. |
|
||||
| `tags` | can be used to add tags to a note (see [[tags]]) |
|
||||
| `alias` | can be used to add aliases to the note. an alias will show up in the link autocompletion |
|
||||
|
||||
For example:
|
||||
|
||||
@@ -40,7 +41,7 @@ For example:
|
||||
title: "Note Title"
|
||||
type: "daily-note"
|
||||
tags: daily, funny, planning
|
||||
|
||||
alias: alias1, alias2
|
||||
---
|
||||
```
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ Note templates are `.md` files located in the special `.foam/templates` director
|
||||
|
||||
Create a template:
|
||||
|
||||
* Run the `Foam: Create New Template` command from the command palette
|
||||
* OR manually create a regular `.md` file in the `.foam/templates` directory
|
||||
- Run the `Foam: Create New Template` command from the command palette
|
||||
- OR manually create a regular `.md` file in the `.foam/templates` directory
|
||||
|
||||

|
||||
|
||||
@@ -17,8 +17,8 @@ _Theme: Ayu Light_
|
||||
|
||||
To create a note from a template:
|
||||
|
||||
* Run the `Foam: Create New Note From Template` command and follow the instructions. Don't worry if you've not created a template yet! You'll be prompted to create a new template if none exist.
|
||||
* OR run the `Foam: Create New Note` command, which uses the special default template (`.foam/templates/new-note.md`, if it exists)
|
||||
- Run the `Foam: Create New Note From Template` command and follow the instructions. Don't worry if you've not created a template yet! You'll be prompted to create a new template if none exist.
|
||||
- OR run the `Foam: Create New Note` command, which uses the special default template (`.foam/templates/new-note.md`, if it exists)
|
||||
|
||||

|
||||
|
||||
@@ -29,7 +29,7 @@ _Theme: Ayu Light_
|
||||
### 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. To begin it is *recommended* to define the YAML Front-Matter of the template similar to the following:
|
||||
Customize this template to contain content that you want included every time you create a note. To begin it is _recommended_ to define the YAML Front-Matter of the template similar to the following:
|
||||
|
||||
```markdown
|
||||
---
|
||||
@@ -40,7 +40,7 @@ type: basic-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. To begin it is *recommended* to define the YAML Front-Matter of the template similar to the following:
|
||||
Customize this template to contain content that you want included every time you create a daily note. To begin it is _recommended_ to define the YAML Front-Matter of the template similar to the following:
|
||||
|
||||
```markdown
|
||||
---
|
||||
@@ -54,11 +54,12 @@ Templates can use all the variables available in [VS Code Snippets](https://code
|
||||
|
||||
In addition, you can also use variables provided by Foam:
|
||||
|
||||
| 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 |
|
||||
| `FOAM_TITLE` | The title of the note. If used, Foam will prompt you to enter a title for the note. |
|
||||
| `FOAM_SLUG` | The sluggified title of the note (using the default github slug method). If used, Foam will prompt you to enter a title for the note unless `FOAM_TITLE` has already caused the prompt. |
|
||||
| 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 |
|
||||
| `FOAM_TITLE` | The title of the note. If used, Foam will prompt you to enter a title for the note. |
|
||||
| `FOAM_TITLE_SAFE` | The title of the note in a file system safe format. If used, Foam will prompt you to enter a title for the note unless `FOAM_TITLE` has already caused the prompt. |
|
||||
| `FOAM_SLUG` | The sluggified title of the note (using the default github slug method). If used, Foam will prompt you to enter a title for the note unless `FOAM_TITLE` has already caused the prompt. |
|
||||
| `FOAM_DATE_*` | `FOAM_DATE_YEAR`, `FOAM_DATE_MONTH`, `FOAM_DATE_WEEK` 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. |
|
||||
|
||||
### `FOAM_DATE_*` variables
|
||||
@@ -69,7 +70,7 @@ For example, `FOAM_DATE_YEAR` has the same behaviour as VS Code's `CURRENT_YEAR`
|
||||
|
||||
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.
|
||||
|
||||
For more nitty-gritty details about the supported date formats, [see here](https://github.com/foambubble/foam/blob/master/packages/foam-vscode/src/services/variable-resolver.ts).
|
||||
For more nitty-gritty details about the supported date formats, [see here](https://github.com/foambubble/foam/blob/main/packages/foam-vscode/src/services/variable-resolver.ts).
|
||||
|
||||
#### Relative daily notes
|
||||
|
||||
@@ -83,8 +84,8 @@ For example, given this daily note template (`.foam/templates/daily-note.md`):
|
||||
|
||||
## Here's what I'm going to do today
|
||||
|
||||
* Thing 1
|
||||
* Thing 2
|
||||
- Thing 1
|
||||
- Thing 2
|
||||
```
|
||||
|
||||
When the `/tomorrow` snippet is used, `FOAM_DATE_` variables will be populated with tomorrow's date, as expected.
|
||||
@@ -96,11 +97,11 @@ When creating notes in any other scenario, the `FOAM_DATE_` values are computed
|
||||
|
||||
Templates can also contain metadata about the templates themselves. The metadata is defined in YAML "Frontmatter" blocks within the templates.
|
||||
|
||||
| Name | Description |
|
||||
| ------------- | ---------------------- |
|
||||
| Name | Description |
|
||||
| ------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `filepath` | The filepath to use when creating the new note. If the filepath is a relative filepath, it is relative to the current workspace. |
|
||||
| `name` | A human readable name to show in the template picker. |
|
||||
| `description` | A human readable description to show in the template picker. |
|
||||
| `name` | A human readable name to show in the template picker. |
|
||||
| `description` | A human readable description to show in the template picker. |
|
||||
|
||||
Foam-specific variables (e.g. `$FOAM_TITLE`) can be used within template metadata. However, VS Code snippet variables are ([currently](https://github.com/foambubble/foam/pull/655)) not supported.
|
||||
|
||||
@@ -145,9 +146,10 @@ It is possible to vary the `filepath` value based on the current date using the
|
||||
---
|
||||
type: daily-note
|
||||
foam_template:
|
||||
description: Daily Note for $FOAM_TITLE
|
||||
filepath: "C:\\Users\\foam_user\\foam_notes\\journal\\$FOAM_DATE_YEAR\\$FOAM_DATE_MONTH-$FOAM_DATE_MONTH_NAME_SHORT\\$FOAM_DATE_YEAR-$FOAM_DATE_MONTH-$FOAM_DATE_DATE-daily-note.md"
|
||||
description: Daily Note for $FOAM_TITLE
|
||||
filepath: "C:\\Users\\foam_user\\foam_notes\\journal\\$FOAM_DATE_YEAR\\$FOAM_DATE_MONTH-$FOAM_DATE_MONTH_NAME_SHORT\\$FOAM_DATE_YEAR-$FOAM_DATE_MONTH-$FOAM_DATE_DATE-daily-note.md"
|
||||
---
|
||||
|
||||
# $FOAM_DATE_YEAR-$FOAM_DATE_MONTH-$FOAM_DATE_DATE Daily Notes
|
||||
```
|
||||
|
||||
@@ -165,7 +167,7 @@ If your template already has a YAML Frontmatter block, you can add the Foam temp
|
||||
|
||||
#### Limitations
|
||||
|
||||
Foam only supports adding the template metadata to *YAML* Frontmatter blocks. If the existing Frontmatter block uses some other format (e.g. JSON), you will have to add the template metadata to its own YAML Frontmatter block.
|
||||
Foam only supports adding the template metadata to _YAML_ Frontmatter blocks. If the existing Frontmatter block uses some other format (e.g. JSON), you will have to add the template metadata to its own YAML Frontmatter block.
|
||||
|
||||
Further, the template metadata must be provided as a [YAML block mapping](https://yaml.org/spec/1.2/spec.html#id2798057), with the attributes placed on the lines immediately following the `foam_template` line:
|
||||
|
||||
@@ -193,7 +195,7 @@ You can add the template metadata to its own YAML Frontmatter block at the start
|
||||
foam_template:
|
||||
name: My Note Template
|
||||
description: This is my note template
|
||||
filepath: `journal/$FOAM_TITLE.md`
|
||||
filepath: 'journal/$FOAM_TITLE.md'
|
||||
---
|
||||
This is the rest of the template
|
||||
```
|
||||
@@ -205,11 +207,11 @@ If the note already has a Frontmatter block, a Foam-specific Frontmatter block c
|
||||
foam_template:
|
||||
name: My Note Template
|
||||
description: This is my note template
|
||||
filepath: `journal/$FOAM_TITLE.md`
|
||||
filepath: 'journal/$FOAM_TITLE.md'
|
||||
---
|
||||
|
||||
---
|
||||
existing_frontmatter: "Existing Frontmatter block"
|
||||
existing_frontmatter: 'Existing Frontmatter block'
|
||||
---
|
||||
This is the rest of the template
|
||||
```
|
||||
|
||||
@@ -15,6 +15,10 @@ There are two ways of creating a tag:
|
||||
|
||||
Tags can also be hierarchical, so you can have `#parent/child` such as #my-tag3/info.
|
||||
|
||||
### Tag completion
|
||||
|
||||
Typing the `#` character will launch VS Code's "Intellisense." This provider will show a list of possible tags that match the character. If you are editing in the frontmatter [[note-properties|note property]], you can invoke tag completion on the `tags:` line by either typing the `#` character, or using the ["trigger suggest"](https://code.visualstudio.com/docs/editor/intellisense) keybinding (usually `ctrl+space`). If the `#` is used in the frontmatter, it will be removed when the tag is inserted.
|
||||
|
||||
## Using *Tag Explorer*
|
||||
|
||||
It's possible to navigate tags via the Tag Explorer panel. Expand the Tag Explorer view in the left side bar which will list all the tags found in current Foam environment. Then, each level of tags can be expanded until the options to search by tag and a list of all files containing a particular tag are shown.
|
||||
@@ -33,7 +37,7 @@ It is possible to customize the way that tags look in the Markdown Preview panel
|
||||
|
||||
> Note: the file path for the stylesheet will be relative to the currently open folder in the workspace when changing this setting for the current workspace. If changing this setting for the user, then the file path will be relative to your global [VSCode settings](https://code.visualstudio.com/docs/getstarted/settings).
|
||||
|
||||
The end result will be a CSS file that looks similiar to the content below. Now you can make your tags standout in your note previews.
|
||||
The end result will be a CSS file that looks similar to the content below. Now you can make your tags standout in your note previews.
|
||||
|
||||
```css
|
||||
.foam-tag{
|
||||
@@ -49,7 +53,10 @@ The end result will be a CSS file that looks similiar to the content below. Now
|
||||
Given the power of backlinks, some people prefer to use them as tags.
|
||||
For example you can tag your notes about books with [[book]].
|
||||
|
||||
[note-properties|note property]: note-properties.md "Note Properties"
|
||||
[graph-visualization]: graph-visualization.md "Graph Visualization"
|
||||
|
||||
[//begin]: # "Autogenerated link references for markdown compatibility"
|
||||
[note-properties|note property]: note-properties.md "Note Properties"
|
||||
[graph-visualization]: graph-visualization.md "Graph Visualization"
|
||||
[//end]: # "Autogenerated link references"
|
||||
[//end]: # "Autogenerated link references"
|
||||
@@ -20,7 +20,10 @@ Remember, with `CTRL/CMD+click` on a wikilink you can navigate to the note, or c
|
||||
|
||||
## Support for sections
|
||||
|
||||
Foam supports autocompletion, navigation, embedding and diagnostics for note sections. Just use the standard wiki syntax of `[[resource#Section Title]]`.
|
||||
Foam supports autocompletion, navigation, embedding and diagnostics for note sections. Just use the standard wiki syntax of `[[resource#Section Title]]`.
|
||||
- If it's an external file, `[your link will need the filename](other-file.md#that-section-I-want-to-link-to)`, but
|
||||
- if it's an anchor within the same document, `[you just need an octothorpe and the section name](#that-section-above)`.
|
||||
- Doesn't matter what heading-level the anchor is; whether you're linking to an `H1` like `# MEN WALK ON MOON` or an `H2` like `## Astronauts Land on Plain`, the link syntax uses a single octothorpe: `[Walk!](#men-walk-on-moon)` and `[Land!](#astronauts-land-on-plain-collect-rocks-plant-flag)`. Autocomplete is your friend here.
|
||||
|
||||
## Markdown compatibility
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ This list is subject to change.
|
||||
|
||||
- [Foam for VSCode](https://marketplace.visualstudio.com/items?itemName=foam.foam-vscode) (alpha)
|
||||
- [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)
|
||||
- [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
|
||||
|
||||
## Extensions For Additional Features
|
||||
|
||||
These extensions are not (yet?) defined in `.vscode/extensions.json`, but have been used by others and shown to play nice with Foam.
|
||||
These extensions are not defined in `.vscode/extensions.json`, but have been used by others and shown to play nice with Foam.
|
||||
|
||||
- [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)
|
||||
|
||||
@@ -14,7 +14,7 @@ strategies for getting the most out of Foam. The full docs are included in the
|
||||
- [[recommended-extensions]]
|
||||
- [[creating-new-notes]]
|
||||
- [[write-notes-in-foam]]
|
||||
- [[sync-notes-with-soruce-control]]
|
||||
- [[sync-notes-with-source-control]]
|
||||
- [[keyboard-shortcuts]]
|
||||
|
||||
## Features
|
||||
@@ -57,7 +57,7 @@ See [[publishing]] for more details.
|
||||
[recommended-extensions]: getting-started/recommended-extensions.md "Recommended Extensions"
|
||||
[creating-new-notes]: getting-started/creating-new-notes.md "Creating New Notes"
|
||||
[write-notes-in-foam]: getting-started/write-notes-in-foam.md "Writing Notes"
|
||||
[sync-notes-with-soruce-control]: getting-started/sync-notes-with-soruce-control.md "Sync notes with source control"
|
||||
[sync-notes-with-source-control]: getting-started/sync-notes-with-source-control.md "Sync notes with source control"
|
||||
[keyboard-shortcuts]: getting-started/keyboard-shortcuts.md "Keyboard Shortcuts"
|
||||
[wikilinks]: features/wikilinks.md "Wikilinks"
|
||||
[tags]: features/tags.md "Tags"
|
||||
|
||||
@@ -50,7 +50,7 @@ In our case, we'll be using the latter tag to wrap our {% raw %}`{{ content }}`{
|
||||
|
||||
You may have noticed that we only made modifications to the template `_layouts/page.html`, which means that `_layouts/home.html` won't have KaTeX support. If you wan't to render math in Foam's home page, you'll need to make the same modifications to `_layouts/home.html` as well.
|
||||
|
||||
Finally, if all goes well, then our site hosted on Vercel will support rendering math equations with KaTeX after commiting these changes to GitHub. Here's a demo of the default template with KaTeX support: [Foam Template with KaTeX support](https://foam-template.vercel.app/).
|
||||
Finally, if all goes well, then our site hosted on Vercel will support rendering math equations with KaTeX after committing these changes to GitHub. Here's a demo of the default template with KaTeX support: [Foam Template with KaTeX support](https://foam-template.vercel.app/).
|
||||
|
||||
[//begin]: # "Autogenerated link references for markdown compatibility"
|
||||
[math-support-with-mathjax]: math-support-with-mathjax.md "Math Support"
|
||||
|
||||
@@ -36,31 +36,31 @@ _Note that first entry in `.order` file defines wiki's home page._
|
||||
|
||||
While you are pushing changes to GitHub, you won't see the wiki updated if you don't add Azure as a remote. You can push to multiple repositories simultaneously.
|
||||
|
||||
1. First open a terminal and check if Azure is added running: `git remote show origin`. If you don't see Azure add it in the output then follow these steps.
|
||||
2. Rename your current remote (most likely named origin) to a different name by running: `git remote rename origin main`
|
||||
3. You can then add the remote for your second remote repository, in this case, Azure. e.g `git remote add azure https://<YOUR_ID>@dev.azure.com/<YOUR_ID>/foam-notes/_git/foam-notes`. You can get it from: Repos->Files->Clone and copy the URL.
|
||||
4. Now, you need to set up your origin remote to push to both of these. So run: `git config -e` and edit it.
|
||||
5. Add the `remote origin` section to the bottom of the file with the URLs from each remote repository you'd like to push to. You'll see something like that:
|
||||
1. First open a terminal and check if Azure is added running: `git remote show origin`. If you don't see Azure add it in the output then follow these steps.
|
||||
2. Rename your current remote (most likely named origin) to a different name by running: `git remote rename origin main`
|
||||
3. You can then add the remote for your second remote repository, in this case, Azure. e.g `git remote add azure https://<YOUR_ID>@dev.azure.com/<YOUR_ID>/foam-notes/_git/foam-notes`. You can get it from: Repos->Files->Clone and copy the URL.
|
||||
4. Now, you need to set up your origin remote to push to both of these. So run: `git config -e` and edit it.
|
||||
5. Add the `remote origin` section to the bottom of the file with the URLs from each remote repository you'd like to push to. You'll see something like that:
|
||||
|
||||
```bash
|
||||
[core]
|
||||
```bash
|
||||
[core]
|
||||
...
|
||||
(ignore this part)
|
||||
...
|
||||
(ignore this part)
|
||||
...
|
||||
[branch "master"]
|
||||
remote = github
|
||||
merge = refs/heads/master
|
||||
[branch "main"]
|
||||
remote = github
|
||||
merge = refs/heads/main
|
||||
[remote "github"]
|
||||
url = git@github.com:username/repo.git
|
||||
fetch = +refs/heads/*:refs/remotes/github/*
|
||||
url = git@github.com:username/repo.git
|
||||
fetch = +refs/heads/*:refs/remotes/github/*
|
||||
[remote "azure"]
|
||||
url = https://<YOUR_ID>@dev.azure.com/<YOUR_ID>/foam-notes/_git/foam-notes
|
||||
fetch = +refs/heads/*:refs/remotes/azure/*
|
||||
url = https://<YOUR_ID>@dev.azure.com/<YOUR_ID>/foam-notes/_git/foam-notes
|
||||
fetch = +refs/heads/*:refs/remotes/azure/*
|
||||
[remote "origin"]
|
||||
url = git@github.com:username/repo.git
|
||||
url = https://<YOUR_ID>@dev.azure.com/<YOUR_ID>/foam-notes/_git/foam-notes
|
||||
```
|
||||
url = git@github.com:username/repo.git
|
||||
url = https://<YOUR_ID>@dev.azure.com/<YOUR_ID>/foam-notes/_git/foam-notes
|
||||
```
|
||||
|
||||
6. You can then push to both repositories by: `git push origin master` or a single one using: `git push github master` or `git push azure master`
|
||||
6. You can then push to both repositories by: `git push origin main` or a single one using: `git push github main` or `git push azure main`
|
||||
|
||||
For more information, read the [Azure DevOps documentation](https://docs.microsoft.com/en-us/azure/devops/project/wiki/publish-repo-to-wiki).
|
||||
|
||||
@@ -65,7 +65,7 @@ gem "jekyll-katex" # Optional, the package that enables KaTeX math rendering
|
||||
|
||||
Besides adding the plugin `jekyll-katex` in `_config.yml` and `Gemfile`, we'll also have to follow the guides in [[math-support-with-katex]] to let our site fully support using KaTeX to render math equations.
|
||||
|
||||
### Commiting changes to GitHub repo
|
||||
### Committing changes to GitHub repo
|
||||
|
||||
Finally, commit the newly created files to GitHub.
|
||||
|
||||
|
||||
@@ -2,8 +2,12 @@
|
||||
|
||||
This #recipe allows you to paste images on to your notes.
|
||||
|
||||
You can directly link and paste images that are copied to the clipboard using either the [Paste
|
||||
Image](https://marketplace.visualstudio.com/items?itemName=mushan.vscode-paste-image)
|
||||
extension, or the [Markdown Image](https://marketplace.visualstudio.com/items?itemName=hancel.markdown-image) extension.
|
||||
VScode (since
|
||||
[1.79](https://code.visualstudio.com/updates/v1_79#_copy-external-media-files-into-workspace-on-drop-or-paste-for-markdown))
|
||||
now has the ability to paste images from the clipboard, or drag-and-drop image
|
||||
files, directly into markdown documents. The file will be created in the
|
||||
workspace, and a link generated in Markdown format.
|
||||
|
||||
The former does not have MDX support (yet), the latter does.
|
||||
VSCode settings under `Markdown > Copy Files` and `Markdown > Editor > Drop` can
|
||||
be used to configure where the files get placed in your workspace, how they're
|
||||
named, how conflicts with existing files are handled, and more.
|
||||
|
||||
@@ -6,7 +6,7 @@ With this #recipe you can create notes on your iOS device, which will automatica
|
||||
|
||||
* You use [Foam for VSCode](https://marketplace.visualstudio.com/items?itemName=foam.foam-vscode) to manage your notes
|
||||
* You wish to adopt a practice such as [A writing inbox for transient and incomplete notes](https://notes.andymatuschak.org/A%20writing%20inbox%20for%20transient%20and%20incomplete%20notes)
|
||||
* You wish to use [Shorcuts](https://support.apple.com/guide/shortcuts/welcome/ios) to capture quick notes into your Foam notes from your iOS device
|
||||
* You wish to use [Shortcuts](https://support.apple.com/guide/shortcuts/welcome/ios) to capture quick notes into your Foam notes from your iOS device
|
||||
|
||||
## Other tools
|
||||
|
||||
@@ -29,6 +29,9 @@ on:
|
||||
jobs:
|
||||
store_data:
|
||||
runs-on: ubuntu-latest
|
||||
# If you encounter a 403 error from a workflow run, try uncommenting the following 2 lines (taken from: https://stackoverflow.com/questions/75880266/cant-make-push-on-a-repo-with-github-actions accepted answer)
|
||||
# permissions:
|
||||
# contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: anglinb/foam-capture-action@main
|
||||
|
||||
53
docs/user/recipes/export-to-pdf.md
Normal file
53
docs/user/recipes/export-to-pdf.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Export to PDF
|
||||
|
||||
This #recipe shows how to export a note to PDF.
|
||||
|
||||
## Required extensions
|
||||
|
||||
- **[vscode-pandoc](https://marketplace.visualstudio.com/items?itemName=chrischinchilla.vscode-pandoc)**
|
||||
|
||||
## Required third-party tools
|
||||
|
||||
- [Pandoc](https://pandoc.org/installing.html)
|
||||
- A [LaTeX distribution](https://www.latex-project.org/get/) such as TeXLive (Linux), MacTeX (MacOS), or MikTeX (Windows)
|
||||
|
||||
Check that Pandoc is installed by opening a terminal and running `pandoc --version`.
|
||||
|
||||
Check that Pandoc can produce PDFs with LaTeX by running the following in the terminal.
|
||||
|
||||
```
|
||||
echo It is working > test.md
|
||||
pandoc test.md -o test.pdf
|
||||
```
|
||||
|
||||
## Instructions
|
||||
|
||||
1. Create a folder in your workspace named `.pandoc`. Take note of the full path to this directory. The rest of this recipe will refer to this path as `$WORKSPACE/.pandoc`.
|
||||
|
||||
2. Download the template file [`foam.latex`](https://raw.githubusercontent.com/Hegghammer/foam-templates/main/foam.latex) from [Hegghammer/foam-templates](https://github.com/Hegghammer/foam-templates) and place it in `$WORKSPACE/.pandoc`.
|
||||
|
||||
3. In VSCode, open `settings.json` for your user (or just for your workspace if you prefer), and add the following line:
|
||||
|
||||
```
|
||||
"pandoc.pdfOptString": "--from=markdown+wikilinks_title_after_pipe --resource-path $WORKSPACE/.pandoc --template foam --listings",
|
||||
```
|
||||
|
||||
Make sure to replace `$WORKSPACE/.pandoc` with the real full path to the `.pandoc` directory you created earlier.
|
||||
|
||||
4. Open a Foam note in VSCode.
|
||||
|
||||
5. Press `Ctrl` + `k`, `p`. Choose "pdf", and press `Enter`.
|
||||
|
||||
The PDF should look something like this:
|
||||
|
||||

|
||||
|
||||
## Options
|
||||
|
||||
If you include a name in the `author` parameter in the YAML of the Foam note, that name will feature in the PDF header on the top left.
|
||||
|
||||
If you don't want syntax highlighting and frames around the codeblocks, remove `--listings` from the `pandoc.pdfOptString` parameter in `settings.json`.
|
||||
|
||||
## Further customization
|
||||
|
||||
If you know some LaTeX, you can [tweak](https://bookdown.org/yihui/rmarkdown-cookbook/latex-template.html) the `foam.latex` template to your needs. Alternatively, you can supply another ready-made template such as [Eisvogel](https://github.com/Wandmalfarbe/pandoc-latex-template); just place the `TEMPLATE_NAME.latex` file in `$WORKSPACE/.pandoc`. You can also use all of Pandoc's [other functionalities](https://learnbyexample.github.io/customizing-pandoc/) by tweaking the `pandoc.pdfOptString` parameter in `settings.json`.
|
||||
173
docs/user/recipes/generate-material-for-mkdocs-site.md
Normal file
173
docs/user/recipes/generate-material-for-mkdocs-site.md
Normal file
@@ -0,0 +1,173 @@
|
||||
# Generate a site using the Material for MkDocs theme
|
||||
|
||||
Configuring a static-site generator (SSG) to publish your Foam provides access to functionality not available through Foam's default publishing mechanism. For example, compare the [original Foam documentation site](https://foambubble.github.io/foam/) with a [Material for MkDocs version](https://djplaner.github.io/foam-with-material-for-mkdocs/) created using the simple configuration detailed below. Try out the search functionality on the Material for MkDocs version. This [digital garden](https://djon.es/memex) and this [blog](https://djon.es/blog/) provide more advanced examples of Foam content published using Material for MkDocs.
|
||||
|
||||
The following explains how to configure the [Material for MkDocs theme](https://squidfunk.github.io/mkdocs-material/) for the [MkDocs SSG](https://www.mkdocs.org) to publish your Foam.
|
||||
|
||||
Like most SSGs (e.g. [Gatsby](https://www.gatsbyjs.com/) is another SSG that can be [used to publish your Foam](https://foambubble.github.io/foam/user/publishing/generate-gatsby-site)) site content is accepted in the form of Markdown files. Like those produced by Foam. SSGs differ in the languages they are written in (MkDocs is Python, Gatsby is Javascript and React) and the features they provide. MkDocs and Material for MkDocs are designed to support project documentation. Gatsby is more general purpose and provides a nice feature set.
|
||||
|
||||
You choose your poison.
|
||||
|
||||
## Requirements
|
||||
|
||||
To use Material for MkDocs to publish your Foam you need:
|
||||
|
||||
- An existing Foam workspace with content.
|
||||
- [Python installed on your computer](https://realpython.com/installing-python/).
|
||||
- Some familiarity and comfort with using the command line on your computer.
|
||||
|
||||
## Instructions
|
||||
|
||||
Configuring Material for MkDocs to publish your Foam involves the following steps:
|
||||
|
||||
1. [Install Material for MkDocs and other requirements](#install-material-for-mkdocs-and-other-requirements).
|
||||
|
||||
Install the Material for MkDocs theme, MkDocs, and other required Python modules.
|
||||
|
||||
2. [Configure Material for MkDocs for your Foam](#configure-material-for-mkdocs-for-your-foam).
|
||||
|
||||
Create a `mkdocs.yml` file in the root of your Foam workspace directory. This file configures Material for MkDocs to work with your Foam.
|
||||
|
||||
2. [Preview and test your site locally](#preview-and-test-your-site-locally).
|
||||
|
||||
Run MkDocs to preview and test your Material for MkDocs Foam site locally. Good for testing and local use.
|
||||
|
||||
3. [Further customise Material for MkDocs](#further-customise-material-for-mkdocs).
|
||||
|
||||
Explore and leverage the additional configuration settings, possible customisations, and additional themes and plugins to customise your site to your needs.
|
||||
|
||||
4. [Publish your site](#publish-your-site).
|
||||
|
||||
Publish your Material for MkDocs Foam site to the web for others to enjoy. There are many options for publishing your site, including GitHub, GitLab, Netlify, and others.
|
||||
|
||||
### Install Material for MkDocs and other requirements
|
||||
|
||||
Material for MkDocs provides [detailed installation instructions](https://squidfunk.github.io/mkdocs-material/getting-started/) which cover the full range of options for installing and configuring Material for MkDocs. The following is a summary of the recommended process.
|
||||
|
||||
1. Within your Foam workspace directory, create a [Python virtual environment](https://realpython.com/what-is-pip/#using-pip-in-a-python-virtual-environment)
|
||||
|
||||
- `python -m venv .venv`
|
||||
- `source .venv/bin/activate` (Linux/Mac) or `.venv\Scripts\activate` (Windows)
|
||||
|
||||
2. Install Material for MkDocs
|
||||
|
||||
- `pip install mkdocs-material`
|
||||
|
||||
3. Install additional Python modules
|
||||
|
||||
- `pip install mkdocs-roamlinks-plugin`
|
||||
- `pip install mkdocs-exclude`
|
||||
|
||||
### Configure Material for MkDocs for your Foam
|
||||
|
||||
To configure Material for MkDocs for your Foam workspace, create a `mkdocs.yml` file in the root of your Foam workspace directory. Below you will find a sample `mkdocs.yml` file (adapted from the [foam-mkdocs-template repository](https://github.com/Jackiexiao/foam-mkdocs-template/tree/master)). Copy and paste it into your `mkdocs.yml` file, then edit it to suit your needs. In particular, don't forget to change the `site_name` and `site_url` to match your Foam workspace. Though this can be left a little later.
|
||||
|
||||
Material for MkDocs provides documentation on both [minimal](https://squidfunk.github.io/mkdocs-material/creating-your-site/#minimal-configuration) and [advanced](https://squidfunk.github.io/mkdocs-material/creating-your-site/#advanced-configuration) configuration of `mkdocs.yml`. Which are revisited in the [customise section below](#further-customise-your-site)
|
||||
|
||||
```yaml
|
||||
site_name: My site # Change this to your site name
|
||||
site_url: https://mydomain.org/mysite # change this
|
||||
theme:
|
||||
name: material
|
||||
features:
|
||||
- navigation.expand
|
||||
- tabs
|
||||
markdown_extensions:
|
||||
- attr_list
|
||||
- pymdownx.tabbed
|
||||
- nl2br
|
||||
- toc:
|
||||
permalink: '#'
|
||||
slugify: !!python/name:pymdownx.slugs.uslugify
|
||||
- admonition
|
||||
- codehilite:
|
||||
guess_lang: false
|
||||
linenums: false
|
||||
- footnotes
|
||||
- meta
|
||||
- def_list
|
||||
- pymdownx.arithmatex
|
||||
- pymdownx.betterem:
|
||||
smart_enable: all
|
||||
- pymdownx.caret
|
||||
- pymdownx.critic
|
||||
- pymdownx.details
|
||||
- pymdownx.inlinehilite
|
||||
- pymdownx.magiclink
|
||||
- pymdownx.mark
|
||||
- pymdownx.smartsymbols
|
||||
- pymdownx.superfences
|
||||
- pymdownx.tasklist
|
||||
- pymdownx.tilde
|
||||
plugins:
|
||||
- search
|
||||
- roamlinks
|
||||
- exclude:
|
||||
glob:
|
||||
- "*.tmp"
|
||||
- "*.pdf"
|
||||
- "*.gz"
|
||||
regex:
|
||||
- '.*\.(tmp|bin|tar)$'
|
||||
```
|
||||
|
||||
### Preview and test your site locally
|
||||
|
||||
MkDocs provides a live preview server allowing you to preview and test your Material for MkDocs Foam site. The server will continue to rebuid your site as you write.
|
||||
|
||||
The simplest method to use the preview service is to run the following command whilst in the rood directory of your Foam workspace:
|
||||
|
||||
```bash
|
||||
mkdocs serve
|
||||
```
|
||||
|
||||
See the Material for MkDocs site for more, including [how to run the preview server via docker](https://squidfunk.github.io/mkdocs-material/creating-your-site/#previewing-as-you-write)
|
||||
|
||||
### Further customise your site
|
||||
|
||||
Further customisation is available through expanding the configuration of Material for MkDocs, using additional MkDocs plugins, customising HTML/CSS, using Markdown extensions, writing your own Python scripts, and more.
|
||||
|
||||
For more on the available customisation paths, see the following:
|
||||
|
||||
- Material for MkDocs [Advanced configuration](https://squidfunk.github.io/mkdocs-material/creating-your-site/#advanced-configuration) or the [Set up section](https://squidfunk.github.io/mkdocs-material/setup/)
|
||||
|
||||
For more configuration options to be included in your `mkdocs.yml` file, including customising: colours, fonts, language, icons, navigation, header, footer etc.
|
||||
|
||||
- Material for MkDocs [Customisation](https://squidfunk.github.io/mkdocs-material/customization/)
|
||||
|
||||
For advice on enhancing the visual design of your site by customising and replacing provided HTML, CSS, and Javascript.
|
||||
|
||||
- Material for MkDocs [Reference](https://squidfunk.github.io/mkdocs-material/reference/)
|
||||
|
||||
An overview of customisation methods that can be used directly within your Markdown files, including: admonitions, annotations, buttons, code blocks, content tabs, data tables, diagrams, grids, Mathematics, etc.
|
||||
|
||||
- a [catalog of 300 MkDocs projects and plugins](https://github.com/mkdocs/catalog#readme)
|
||||
|
||||
For functionality and ideas not included in Material for MkDocs, including: additional themes, plugins, and extensions.
|
||||
|
||||
### Building and publishing your site
|
||||
|
||||
As a Static Site Generator (SSG), MkDocs generates a collection of static HTML and other types of files. Publishing your site involves building those HTML files and placing them onto your web server. The method will vary depending on your web server and hosting provider.
|
||||
|
||||
The MkDocs documentation site provides an explanation of the [simplest method to publish your site to any provider](https://www.mkdocs.org/user-guide/deploying-your-docs/#other-providers) using `mkdocs build` and `scp`.
|
||||
|
||||
The Material for MkDocs [publish page](https://squidfunk.github.io/mkdocs-material/publishing-your-site/) lists options for publishing to
|
||||
|
||||
- GitHub using [mkdocs](https://squidfunk.github.io/mkdocs-material/publishing-your-site/#with-mkdocs)
|
||||
|
||||
Perhaps the simplest method, if you are already using GitHub to host your Foam workspace.
|
||||
|
||||
- GitHub using [GitHub actions](https://squidfunk.github.io/mkdocs-material/publishing-your-site/github-actions/)
|
||||
|
||||
A more automated method of publishing your site to GitHub, using GitHub actions.
|
||||
|
||||
- [GitLab](https://squidfunk.github.io/mkdocs-material/publishing-your-site/#with-mkdocs)
|
||||
|
||||
- [Cloudflage pages](https://deborahwrites.com/guides/deploy-host-mkdocs/deploy-mkdocs-material-cloudflare/)
|
||||
|
||||
- [Netlify](https://deborahwrites.com/guides/deploy-host-mkdocs/deploy-mkdocs-material-netlify/)
|
||||
|
||||
- [Fly.io](https://documentation.breadnet.co.uk/cloud/fly/mkdocs-on-fly/#prerequisites)
|
||||
|
||||
- [Scaleway](https://www.scaleway.com/en/docs/tutorials/using-bucket-website-with-mkdocs/)
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<!-- omit in toc -->
|
||||
|
||||
# Recipes
|
||||
|
||||
A #recipe is a guide, tip or strategy for getting the most out of your Foam workspace!
|
||||
|
||||
- [Contribute](#contribute)
|
||||
- [Take smart notes](#take-smart-notes)
|
||||
- [Discover](#discover)
|
||||
- [Organise](#organise)
|
||||
- [Write](#write)
|
||||
- [Version control](#version-control)
|
||||
- [Publish](#publish)
|
||||
- [Collaborate](#collaborate)
|
||||
- [Workflow](#workflow)
|
||||
- [Creative ideas](#creative-ideas)
|
||||
- [Other](#other)
|
||||
- [Recipes](#recipes)
|
||||
- [Contribute](#contribute)
|
||||
- [Take smart notes](#take-smart-notes)
|
||||
- [Discover](#discover)
|
||||
- [Organise](#organise)
|
||||
- [Write](#write)
|
||||
- [Version control](#version-control)
|
||||
- [Publish](#publish)
|
||||
- [Collaborate](#collaborate)
|
||||
- [Workflow](#workflow)
|
||||
- [Creative ideas](#creative-ideas)
|
||||
- [Other](#other)
|
||||
|
||||
## Contribute
|
||||
|
||||
@@ -75,11 +77,12 @@ A #recipe is a guide, tip or strategy for getting the most out of your Foam work
|
||||
- Publish using community templates
|
||||
- [[publish-to-netlify-with-eleventy]] by [@juanfrank77](https://github.com/juanfrank77)
|
||||
- [[generate-gatsby-site]] by [@mathieudutour](https://github.com/mathieudutour) and [@hikerpig](https://github.com/hikerpig)
|
||||
- [foamy-nextjs](https://github.com/yenly/foamy-nextjs) by [@yenly](https://github.com/yenly)
|
||||
- [[generate-material-for-mkdocs-site]] by [@djplaner](https://github.com/djplaner)
|
||||
- Make the site your own by [[publish-to-github]].
|
||||
- Render math symbols, by either
|
||||
- adding client-side [[math-support-with-mathjax]] to the default [[publish-to-github-pages]] site
|
||||
- adding a custom Jekyll plugin to support [[math-support-with-katex]]
|
||||
- Export note to PDF [[export-to-pdf]]
|
||||
|
||||
## Collaborate
|
||||
|
||||
@@ -137,9 +140,11 @@ _See [[contribution-guide]] and [[how-to-write-recipes]]._
|
||||
[publish-to-vercel]: ../publishing/publish-to-vercel.md "Publish to Vercel"
|
||||
[publish-to-netlify-with-eleventy]: ../publishing/publish-to-netlify-with-eleventy.md "Publish to Netlify with Eleventy"
|
||||
[generate-gatsby-site]: ../publishing/generate-gatsby-site.md "Generate a site using Gatsby"
|
||||
[generate-material-for-mkdocs-site]: generate-material-for-mkdocs-site.md "Generate a site using the Material for MkDocs theme"
|
||||
[publish-to-github]: ../publishing/publish-to-github.md "Publish to GitHub"
|
||||
[math-support-with-mathjax]: ../publishing/math-support-with-mathjax.md "Math Support"
|
||||
[math-support-with-katex]: ../publishing/math-support-with-katex.md "Katex Math Rendering"
|
||||
[export-to-pdf]: export-to-pdf.md "Export to PDF"
|
||||
[real-time-collaboration]: real-time-collaboration.md "Real-time Collaboration"
|
||||
[capture-notes-with-drafts-pro]: capture-notes-with-drafts-pro.md "Capture Notes With Drafts Pro"
|
||||
[capture-notes-with-shortcuts-and-github-actions]: capture-notes-with-shortcuts-and-github-actions.md "Capture Notes With Shortcuts and GitHub Actions"
|
||||
|
||||
@@ -53,7 +53,7 @@ If such an app was worth building, it would have to have the following features:
|
||||
|
||||
- Instant loading and syncing for quick notes
|
||||
- Sleek, simple, beautifully designed user experience.
|
||||
- Ability to search and navigate forward links and back links (onlly in paid GitJournal version)
|
||||
- Ability to search and navigate forward links and back links (only in paid GitJournal version)
|
||||
- Killer feature that makes it the best note taking tool for Foam (?)
|
||||
|
||||
Given the effort vs reward ratio, it's a low priority for core team, but if someone wants to work on this, we can provide support! Talk to us on the #mobile-apps channel on [Foam Discord](https://foambubble.github.io/join-discord/w).
|
||||
|
||||
@@ -44,7 +44,7 @@ When editing a file, you can easily navigate `[[links]]` by hovering over them t
|
||||
|
||||
You can view a page's backlinks using either of the following techniques:
|
||||
|
||||
1. Expanding the file's node in the `Repositories` tree, since it's child nodes will represent backlinks. This makes it easy to browse your pages and their backlinks in a single hierachical view.
|
||||
1. Expanding the file's node in the `Repositories` tree, since it's child nodes will represent backlinks. This makes it easy to browse your pages and their backlinks in a single hierarchical view.
|
||||
|
||||
1. Opening a file, and then viewing it's backlinks list at the bottom of the editor view. This makes it easy to read a page and then see its backlinks in a contextually rich way.
|
||||
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
],
|
||||
"npmClient": "yarn",
|
||||
"useWorkspaces": true,
|
||||
"version": "0.22.2"
|
||||
"version": "0.26.12"
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"reset": "yarn && yarn clean && yarn build",
|
||||
"clean": "lerna run clean",
|
||||
"build": "lerna run build",
|
||||
"test": "yarn workspace foam-vscode test",
|
||||
"test": "yarn workspace foam-vscode test --stream",
|
||||
"lint": "lerna run lint",
|
||||
"watch": "lerna run watch --concurrency 20 --stream"
|
||||
},
|
||||
|
||||
@@ -6,6 +6,7 @@ out/**/*.spec.*
|
||||
test-data/**
|
||||
src/**
|
||||
jest.config.js
|
||||
esbuild.js
|
||||
.test-workspace
|
||||
.gitignore
|
||||
vsc-extension-quickstart.md
|
||||
|
||||
@@ -4,6 +4,217 @@ 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.26.12] - 2025-06-18
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Fix YAML parsing (#1467)
|
||||
- Improved regex parsing (#1479 - thanks @s-jacob-powell)
|
||||
|
||||
## [0.26.11] - 2025-04-19
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Support for custom fonts in graph view (#1457 - thanks @Tenormis)
|
||||
|
||||
## [0.26.10] - 2025-03-29
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- General improvment of wiki embeds (#1443)
|
||||
|
||||
## [0.26.9] - 2025-03-29
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Defensive get of link object ID in graph (#1438)
|
||||
|
||||
Internal:
|
||||
|
||||
- Updated `force-graph` library
|
||||
|
||||
## [0.26.8] - 2025-03-14
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Tag hierarchy now visible in graph (#1436)
|
||||
- Improved Notes Explorer layout
|
||||
|
||||
## [0.26.7] - 2025-03-09
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Improved parsing of tags (fixes #1434)
|
||||
|
||||
## [0.26.6] - 2025-03-08
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Improved graph based navigation when running in virtual workspace
|
||||
- Improved wikilink embeds and fixed cycle detection issue (#1430)
|
||||
- Added links in tags to navigate to corresponding tag explorer item (#1432)
|
||||
|
||||
Internal:
|
||||
|
||||
- Renamed branch from `master` to `main`
|
||||
|
||||
## [0.26.5] - 2025-02-21
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Improved handling of virtual FS URIs (#1426)
|
||||
|
||||
## [0.26.4] - 2024-11-12
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Improved handling of virtual FS URIs (#1409)
|
||||
|
||||
## [0.26.3] - 2024-11-12
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Finetuned use of triemap (#1411 - thanks @pderaaij)
|
||||
|
||||
## [0.26.2] - 2024-11-06
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Performance improvements (#1406 - thanks @pderaaij)
|
||||
|
||||
## [0.26.1] - 2024-10-09
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Fixed issue with Buffer in web extension (#1401 - thanks @pderaaij)
|
||||
|
||||
## [0.26.0] - 2024-10-01
|
||||
|
||||
Features:
|
||||
|
||||
- Foam is now a web extension! (#1395 - many thanks @pderaaij)
|
||||
|
||||
## [0.25.12] - 2024-07-13
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Improved YAML support (#1367)
|
||||
- Added convesion of wikilinks to markdown links (#1365 - thanks @hereistheusername)
|
||||
- Refactored util and settings code
|
||||
|
||||
## [0.25.11] - 2024-03-18
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Actually fixed bug in graph computation (#1345)
|
||||
|
||||
## [0.25.10] - 2024-03-18
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Fixed bug in graph computation (#1345)
|
||||
|
||||
## [0.25.9] - 2024-03-17
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Improved note creation from placeholder (#1344)
|
||||
|
||||
## [0.25.8] - 2024-02-21
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Upgraded dataformat to improve support for daily note naming (#1326 - thanks @rcyeh)
|
||||
|
||||
## [0.25.7] - 2024-01-16
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Modifies url encoding to target only the filename and skip spaces (#1322 - thanks @MABruni)
|
||||
- Minor tweak to quick action menu with suggestions for section name
|
||||
|
||||
## [0.25.6] - 2023-12-13
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Fixed wikilink definition encoding (#1311 - thanks @MABruni)
|
||||
|
||||
## [0.25.5] - 2023-11-30
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Using note title in preview (#1309)
|
||||
|
||||
## [0.25.4] - 2023-09-19
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Added support for linking sections within same document (#1289)
|
||||
- Fixed note embedding bug (#1286 - thanks @badsketch)
|
||||
|
||||
## [0.25.3] - 2023-09-07
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Fixed incorrect handling of embedding of non-existing notes (#1283 - thanks @badsketch)
|
||||
- Introduced Note Embedding Sytanx (#1281 - thanks @badsketch)
|
||||
- Attachments are not considered when computing orphan notes (#1242)
|
||||
|
||||
## [0.25.2] - 2023-09-02
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Added content-only embed styles (#1279 - thanks @badsketch)
|
||||
- Added expand-all button to tree views (#1276)
|
||||
|
||||
## [0.25.1] - 2023-08-23
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Added support for path parameter in filter (#1250)
|
||||
- Added grouping and filtering to tag explorer (#1275)
|
||||
- Added new setting to control note embedding (#1273 - thanks @badsketch)
|
||||
- Added last week's days to snippets (#1248 - thanks @jimgraham)
|
||||
|
||||
Internal:
|
||||
|
||||
- Updated jest to v29 (#1271 - thanks @nicholas-l)
|
||||
- Improved test cleanup and management (#1274)
|
||||
|
||||
## [0.25.0] - 2023-06-30
|
||||
|
||||
Features:
|
||||
|
||||
- Support for multiple extensions and custom default extension (#1235)
|
||||
- Added `FOAM_TITLE_SAFE` template variable (#1232)
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Connections panel tweaks (#1233)
|
||||
|
||||
## [0.24.0] - 2023-05-19
|
||||
|
||||
Features:
|
||||
|
||||
- Converted backlinks panel into more general connections panel (#1230)
|
||||
|
||||
Internal:
|
||||
|
||||
- Improved janitor code (#1228)
|
||||
- Refactored code related to tree view panels (#1226)
|
||||
- Lint and cleanup (#1224)
|
||||
|
||||
## [0.23.0] - 2023-05-06
|
||||
|
||||
Features:
|
||||
|
||||
- Added notes explorer (#1223)
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
- Enabled tag completion in front matter (#1191 - thanks @jimgraham)
|
||||
- Various improvements to tree views (#1220)
|
||||
|
||||
## [0.22.2] - 2023-04-20
|
||||
|
||||
Fixes and Improvements:
|
||||
|
||||
111
packages/foam-vscode/esbuild.js
Normal file
111
packages/foam-vscode/esbuild.js
Normal file
@@ -0,0 +1,111 @@
|
||||
// also see https://code.visualstudio.com/api/working-with-extensions/bundling-extension
|
||||
const assert = require('assert');
|
||||
const esbuild = require('esbuild');
|
||||
const polyfillPlugin = require('esbuild-plugin-polyfill-node');
|
||||
|
||||
// pass the platform to esbuild as an argument
|
||||
|
||||
function getPlatform() {
|
||||
const args = process.argv.slice(2);
|
||||
const pArg = args.find(arg => arg.startsWith('--platform='));
|
||||
if (pArg) {
|
||||
return pArg.split('=')[1];
|
||||
}
|
||||
throw new Error('No platform specified. Pass --platform <web|node>.');
|
||||
}
|
||||
|
||||
const platform = getPlatform();
|
||||
assert(['web', 'node'].includes(platform), 'Platform must be "web" or "node".');
|
||||
|
||||
const production = process.argv.includes('--production');
|
||||
const watch = process.argv.includes('--watch');
|
||||
|
||||
const config = {
|
||||
web: {
|
||||
platform: 'browser',
|
||||
format: 'cjs',
|
||||
outfile: `out/bundles/extension-web.js`,
|
||||
plugins: [
|
||||
polyfillPlugin.polyfillNode({
|
||||
// Options (optional)
|
||||
}),
|
||||
{
|
||||
name: 'path-browserify',
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /^path$/ }, args => {
|
||||
return { path: require.resolve('path-browserify') };
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'wikilink-embed',
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /wikilink-embed/ }, args => {
|
||||
return {
|
||||
path: require.resolve(
|
||||
args.resolveDir + '/wikilink-embed-web-extension.ts'
|
||||
),
|
||||
};
|
||||
});
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
node: {
|
||||
platform: 'node',
|
||||
format: 'cjs',
|
||||
outfile: `out/bundles/extension-node.js`,
|
||||
plugins: [],
|
||||
},
|
||||
};
|
||||
|
||||
async function main() {
|
||||
const ctx = await esbuild.context({
|
||||
...config[platform],
|
||||
entryPoints: ['src/extension.ts'],
|
||||
bundle: true,
|
||||
minify: production,
|
||||
sourcemap: !production,
|
||||
sourcesContent: false,
|
||||
external: ['vscode'],
|
||||
logLevel: 'silent',
|
||||
plugins: [
|
||||
...config[platform].plugins,
|
||||
/* add to the end of plugins array */
|
||||
esbuildProblemMatcherPlugin,
|
||||
],
|
||||
});
|
||||
if (watch) {
|
||||
await ctx.watch();
|
||||
} else {
|
||||
await ctx.rebuild();
|
||||
await ctx.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {import('esbuild').Plugin}
|
||||
*/
|
||||
const esbuildProblemMatcherPlugin = {
|
||||
name: 'esbuild-problem-matcher',
|
||||
|
||||
setup(build) {
|
||||
build.onStart(() => {
|
||||
console.log('[watch] build started');
|
||||
});
|
||||
build.onEnd(result => {
|
||||
result.errors.forEach(({ text, location }) => {
|
||||
console.error(`✘ [ERROR] ${text}`);
|
||||
console.error(
|
||||
` ${location.file}:${location.line}:${location.column}:`
|
||||
);
|
||||
});
|
||||
console.log('[watch] build finished');
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
main().catch(e => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -8,11 +8,11 @@
|
||||
"type": "git"
|
||||
},
|
||||
"homepage": "https://github.com/foambubble/foam",
|
||||
"version": "0.22.2",
|
||||
"version": "0.26.12",
|
||||
"license": "MIT",
|
||||
"publisher": "foam",
|
||||
"engines": {
|
||||
"vscode": "^1.70.0"
|
||||
"vscode": "^1.96.0"
|
||||
},
|
||||
"icon": "assets/icon/FOAM_ICON_256.png",
|
||||
"categories": [
|
||||
@@ -21,7 +21,8 @@
|
||||
"activationEvents": [
|
||||
"workspaceContains:.vscode/foam.json"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"main": "./out/bundles/extension-node.js",
|
||||
"browser": "./out/bundles/extension-web.js",
|
||||
"capabilities": {
|
||||
"untrustedWorkspaces": {
|
||||
"supported": "limited",
|
||||
@@ -56,28 +57,34 @@
|
||||
"views": {
|
||||
"explorer": [
|
||||
{
|
||||
"id": "foam-vscode.backlinks",
|
||||
"name": "Backlinks",
|
||||
"id": "foam-vscode.connections",
|
||||
"name": "Connections",
|
||||
"icon": "$(references)",
|
||||
"contextualTitle": "Backlinks"
|
||||
"contextualTitle": "Foam"
|
||||
},
|
||||
{
|
||||
"id": "foam-vscode.tags-explorer",
|
||||
"name": "Tag Explorer",
|
||||
"icon": "$(tag)",
|
||||
"contextualTitle": "Tags Explorer"
|
||||
"contextualTitle": "Foam"
|
||||
},
|
||||
{
|
||||
"id": "foam-vscode.notes-explorer",
|
||||
"name": "Notes",
|
||||
"icon": "$(notebook)",
|
||||
"contextualTitle": "Foam"
|
||||
},
|
||||
{
|
||||
"id": "foam-vscode.orphans",
|
||||
"name": "Orphans",
|
||||
"icon": "$(debug-gripper)",
|
||||
"contextualTitle": "Orphans"
|
||||
"contextualTitle": "Foam"
|
||||
},
|
||||
{
|
||||
"id": "foam-vscode.placeholders",
|
||||
"name": "Placeholders",
|
||||
"icon": "$(debug-disconnect)",
|
||||
"contextualTitle": "Placeholders"
|
||||
"contextualTitle": "Foam"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -87,8 +94,8 @@
|
||||
"contents": "No tags found. Notes that contain tags will show up here. You may add tags to a note with a hashtag (#tag) or by adding a tag list to the front matter (tags: tag1, tag2)."
|
||||
},
|
||||
{
|
||||
"view": "foam-vscode.backlinks",
|
||||
"contents": "No backlinks found for selected resource."
|
||||
"view": "foam-vscode.connections",
|
||||
"contents": "Nothing found for the selected resource and the current filter."
|
||||
},
|
||||
{
|
||||
"view": "foam-vscode.orphans",
|
||||
@@ -101,6 +108,21 @@
|
||||
],
|
||||
"menus": {
|
||||
"view/title": [
|
||||
{
|
||||
"command": "foam-vscode.views.connections.show:backlinks",
|
||||
"when": "view == foam-vscode.connections && foam-vscode.views.connections.show == 'all links'",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.connections.show:forward-links",
|
||||
"when": "view == foam-vscode.connections && foam-vscode.views.connections.show == 'backlinks'",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.connections.show:all-links",
|
||||
"when": "view == foam-vscode.connections && foam-vscode.views.connections.show == 'forward links'",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.orphans.group-by:folder",
|
||||
"when": "view == foam-vscode.orphans && foam-vscode.views.orphans.group-by == 'off'",
|
||||
@@ -111,6 +133,31 @@
|
||||
"when": "view == foam-vscode.orphans && foam-vscode.views.orphans.group-by == 'folder'",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.show:for-current-file",
|
||||
"when": "view == foam-vscode.tags-explorer && foam-vscode.views.tags-explorer.show == 'all'",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.show:all",
|
||||
"when": "view == foam-vscode.tags-explorer && foam-vscode.views.tags-explorer.show == 'for-current-file'",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.group-by:folder",
|
||||
"when": "view == foam-vscode.tags-explorer && foam-vscode.views.tags-explorer.group-by == 'off'",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.group-by:off",
|
||||
"when": "view == foam-vscode.tags-explorer && foam-vscode.views.tags-explorer.group-by == 'folder'",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.expand-all",
|
||||
"when": "view == foam-vscode.tags-explorer",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.placeholders.show:for-current-file",
|
||||
"when": "view == foam-vscode.placeholders && foam-vscode.views.placeholders.show == 'all'",
|
||||
@@ -130,6 +177,26 @@
|
||||
"command": "foam-vscode.views.placeholders.group-by:off",
|
||||
"when": "view == foam-vscode.placeholders && foam-vscode.views.placeholders.group-by == 'folder'",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.placeholders.expand-all",
|
||||
"when": "view == foam-vscode.placeholders",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.notes-explorer.show:notes",
|
||||
"when": "view == foam-vscode.notes-explorer && foam-vscode.views.notes-explorer.show == 'all'",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.notes-explorer.show:all",
|
||||
"when": "view == foam-vscode.notes-explorer && foam-vscode.views.notes-explorer.show == 'notes-only'",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.notes-explorer.expand-all",
|
||||
"when": "view == foam-vscode.notes-explorer",
|
||||
"group": "navigation"
|
||||
}
|
||||
],
|
||||
"commandPalette": [
|
||||
@@ -141,6 +208,18 @@
|
||||
"command": "foam-vscode.update-graph",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.connections.show:all-links",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.connections.show:backlinks",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.connections.show:forward-links",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.orphans.group-by:folder",
|
||||
"when": "false"
|
||||
@@ -149,6 +228,26 @@
|
||||
"command": "foam-vscode.views.orphans.group-by:off",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.show:for-current-file",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.show:all",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.group-by:folder",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.group-by:off",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.expand-all",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.placeholders.show:for-current-file",
|
||||
"when": "false"
|
||||
@@ -165,6 +264,22 @@
|
||||
"command": "foam-vscode.views.placeholders.group-by:off",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.placeholders.expand-all",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.notes-explorer.show:all",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.notes-explorer.show:notes",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.notes-explorer.expand-all",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.open-resource",
|
||||
"when": "false"
|
||||
@@ -186,19 +301,19 @@
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.update-graph",
|
||||
"title": "Foam: Update graph"
|
||||
"title": "Foam: Update Graph"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.set-log-level",
|
||||
"title": "Foam: Set log level"
|
||||
"title": "Foam: Set Log Level"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.show-graph",
|
||||
"title": "Foam: Show graph"
|
||||
"title": "Foam: Show Graph"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.update-wikilinks",
|
||||
"title": "Foam: Update Markdown Reference List"
|
||||
"command": "foam-vscode.update-wikilink-definitions",
|
||||
"title": "Foam: Update Wikilink Definitions"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.open-daily-note",
|
||||
@@ -232,16 +347,69 @@
|
||||
"command": "foam-vscode.open-resource",
|
||||
"title": "Foam: Open Resource"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.convert-link-style-inplace",
|
||||
"title": "Foam: Convert Link Style in Place"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.convert-link-style-incopy",
|
||||
"title": "Foam: Convert Link Format in Copy"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.orphans.group-by:folder",
|
||||
"title": "Group By Folder",
|
||||
"icon": "$(list-tree)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.connections.show:backlinks",
|
||||
"title": "Show Backlinks",
|
||||
"icon": "$(arrow-left)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.connections.show:forward-links",
|
||||
"title": "Show Links",
|
||||
"icon": "$(arrow-right)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.connections.show:all-links",
|
||||
"title": "Show All",
|
||||
"icon": "$(arrow-swap)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.orphans.group-by:off",
|
||||
"title": "Flat list",
|
||||
"icon": "$(list-flat)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.show:for-current-file",
|
||||
"title": "Show tags in current file",
|
||||
"icon": "$(file)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.show:all",
|
||||
"title": "Show tags in workspace",
|
||||
"icon": "$(files)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.group-by:folder",
|
||||
"title": "Group By Folder",
|
||||
"icon": "$(list-tree)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.group-by:off",
|
||||
"title": "Flat list",
|
||||
"icon": "$(list-flat)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.expand-all",
|
||||
"title": "Expand all",
|
||||
"icon": "$(expand-all)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.tags-explorer.focus",
|
||||
"title": "Focus on tag",
|
||||
"icon": "$(symbol-number)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.placeholders.show:for-current-file",
|
||||
"title": "Show placeholders in current file",
|
||||
@@ -262,6 +430,26 @@
|
||||
"title": "Flat list",
|
||||
"icon": "$(list-flat)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.placeholders.expand-all",
|
||||
"title": "Expand all",
|
||||
"icon": "$(expand-all)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.notes-explorer.show:all",
|
||||
"title": "Show all resources",
|
||||
"icon": "$(files)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.notes-explorer.expand-all",
|
||||
"title": "Expand all",
|
||||
"icon": "$(expand-all)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.views.notes-explorer.show:notes",
|
||||
"title": "Show only notes",
|
||||
"icon": "$(file)"
|
||||
},
|
||||
{
|
||||
"command": "foam-vscode.create-new-template",
|
||||
"title": "Foam: Create New Template"
|
||||
@@ -274,6 +462,13 @@
|
||||
"configuration": {
|
||||
"title": "Foam",
|
||||
"properties": {
|
||||
"foam.supportedLanguages": {
|
||||
"type": "array",
|
||||
"default": [
|
||||
"markdown"
|
||||
],
|
||||
"description": "List of languages to treat as Markdown-like documents."
|
||||
},
|
||||
"foam.completion.label": {
|
||||
"type": "string",
|
||||
"default": "path",
|
||||
@@ -319,6 +514,16 @@
|
||||
"default": "pdf mp3 webm wav m4a mp4 avi mov rtf txt doc docx pages xls xlsx numbers ppt pptm pptx",
|
||||
"description": "Space separated list of file extensions that will be considered attachments"
|
||||
},
|
||||
"foam.files.notesExtensions": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"description": "Space separated list of extra file extensions that will be considered text notes (e.g. 'mdx txt markdown')"
|
||||
},
|
||||
"foam.files.defaultNoteExtension": {
|
||||
"type": "string",
|
||||
"default": "md",
|
||||
"description": "The default extension for new notes"
|
||||
},
|
||||
"foam.files.newNotePath": {
|
||||
"type": "string",
|
||||
"default": "root",
|
||||
@@ -425,10 +630,21 @@
|
||||
],
|
||||
"description": "Whether or not to navigate to the target daily note when a daily note snippet is selected."
|
||||
},
|
||||
"foam.preview.embedNoteInContainer": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Wrap embedded notes in a container when displayed in preview panel"
|
||||
"foam.preview.embedNoteType": {
|
||||
"type": "string",
|
||||
"default": "full-card",
|
||||
"enum": [
|
||||
"full-inline",
|
||||
"full-card",
|
||||
"content-inline",
|
||||
"content-card"
|
||||
],
|
||||
"enumDescriptions": [
|
||||
"Include the section with title and style inline",
|
||||
"Include the section with title and style it within a container",
|
||||
"Include the section without title and style inline",
|
||||
"Include the section without title and style it within a container"
|
||||
]
|
||||
},
|
||||
"foam.graph.titleMaxLength": {
|
||||
"type": "number",
|
||||
@@ -454,28 +670,30 @@
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc -p ./",
|
||||
"pretest": "yarn build",
|
||||
"test": "node ./out/test/run-tests.js",
|
||||
"pretest:unit": "yarn build",
|
||||
"test:unit": "node ./out/test/run-tests.js --unit",
|
||||
"pretest:e2e": "yarn build",
|
||||
"test:e2e": "node ./out/test/run-tests.js --e2e",
|
||||
"build:node": "node esbuild.js --platform=node",
|
||||
"build:web": "node esbuild.js --platform=web",
|
||||
"build": "yarn build:node && yarn build:web",
|
||||
"vscode:prepublish": "yarn clean && yarn build:node --production && yarn build:web --production",
|
||||
"compile": "tsc -p ./",
|
||||
"test-reset-workspace": "rm -rf .test-workspace && mkdir .test-workspace && touch .test-workspace/.keep",
|
||||
"test-setup": "yarn compile && yarn build && yarn test-reset-workspace",
|
||||
"test": "yarn test-setup && node ./out/test/run-tests.js",
|
||||
"test:unit": "yarn test-setup && node ./out/test/run-tests.js --unit",
|
||||
"test:e2e": "yarn test-setup && node ./out/test/run-tests.js --e2e",
|
||||
"lint": "dts lint src",
|
||||
"clean": "rimraf out",
|
||||
"watch": "tsc --build ./tsconfig.json --watch",
|
||||
"watch": "nodemon --watch 'src/**/*.ts' --exec 'yarn build' --ext ts",
|
||||
"vscode:start-debugging": "yarn clean && yarn watch",
|
||||
"esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node",
|
||||
"vscode:prepublish": "yarn run esbuild-base -- --minify",
|
||||
"package-extension": "npx vsce package --yarn",
|
||||
"install-extension": "code --install-extension ./foam-vscode-$npm_package_version.vsix",
|
||||
"open-in-browser": "vscode-test-web --quality=stable --browser=chromium --extensionDevelopmentPath=. ",
|
||||
"publish-extension-openvsx": "npx ovsx publish foam-vscode-$npm_package_version.vsix -p $OPENVSX_TOKEN",
|
||||
"publish-extension-vscode": "npx vsce publish --packagePath foam-vscode-$npm_package_version.vsix",
|
||||
"publish-extension": "yarn publish-extension-vscode && yarn publish-extension-openvsx"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/dateformat": "^3.0.1",
|
||||
"@types/jest": "^27.5.1",
|
||||
"@types/jest": "^29.5.3",
|
||||
"@types/lodash": "^4.14.157",
|
||||
"@types/markdown-it": "^12.0.1",
|
||||
"@types/micromatch": "^4.0.1",
|
||||
@@ -485,39 +703,45 @@
|
||||
"@types/vscode": "^1.70.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
||||
"@typescript-eslint/parser": "^5.51.0",
|
||||
"@vscode/test-web": "^0.0.62",
|
||||
"dts-cli": "^1.6.3",
|
||||
"esbuild": "^0.17.7",
|
||||
"esbuild-plugin-polyfill-node": "^0.3.0",
|
||||
"eslint": "^8.33.0",
|
||||
"eslint-import-resolver-typescript": "^3.5.3",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-jest": "^27.2.1",
|
||||
"husky": "^4.2.5",
|
||||
"jest": "^27.5.1",
|
||||
"jest": "^29.6.2",
|
||||
"jest-extended": "^3.2.3",
|
||||
"markdown-it": "^12.0.4",
|
||||
"micromatch": "^4.0.2",
|
||||
"nodemon": "^3.1.7",
|
||||
"rimraf": "^3.0.2",
|
||||
"ts-jest": "^27.1.5",
|
||||
"ts-jest": "^29.1.1",
|
||||
"tslib": "^2.0.0",
|
||||
"typescript": "^4.9.5",
|
||||
"vscode-test": "^1.3.0",
|
||||
"wait-for-expect": "^3.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"dateformat": "^3.0.3",
|
||||
"dateformat": "4.5.1",
|
||||
"detect-newline": "^3.1.0",
|
||||
"github-slugger": "^1.4.0",
|
||||
"gray-matter": "^4.0.2",
|
||||
"js-sha1": "^0.7.0",
|
||||
"lodash": "^4.17.21",
|
||||
"lru-cache": "^7.14.1",
|
||||
"markdown-it-regex": "^0.2.0",
|
||||
"mnemonist": "^0.39.8",
|
||||
"path-browserify": "^1.0.1",
|
||||
"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"
|
||||
"yaml": "^2.2.2"
|
||||
},
|
||||
"__metadata": {
|
||||
"id": "b85c6625-454b-4b61-8a22-c42f3d0f2e1e",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// taken from https://github.com/microsoft/vscode/tree/master/src/vs/base/common
|
||||
// taken from https://github.com/microsoft/vscode/tree/main/src/vs/base/common
|
||||
|
||||
import { Emitter, Event } from './event';
|
||||
import { IDisposable } from './lifecycle';
|
||||
@@ -29,7 +29,7 @@ export interface CancellationToken {
|
||||
) => IDisposable;
|
||||
}
|
||||
|
||||
const shortcutEvent: Event<any> = Object.freeze(function(
|
||||
const shortcutEvent: Event<any> = Object.freeze(function (
|
||||
callback,
|
||||
context?
|
||||
): IDisposable {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// taken from https://github.com/microsoft/vscode/tree/master/src/vs/base/common
|
||||
// taken from https://github.com/microsoft/vscode/tree/main/src/vs/base/common
|
||||
|
||||
// Names from https://blog.codinghorror.com/ascii-pronunciation-rules-for-programmers/
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// taken from https://github.com/microsoft/vscode/tree/master/src/vs/base/common
|
||||
// taken from https://github.com/microsoft/vscode/tree/main/src/vs/base/common
|
||||
|
||||
export interface ErrorListenerCallback {
|
||||
(error: any): void;
|
||||
@@ -21,7 +21,7 @@ export class ErrorHandler {
|
||||
constructor() {
|
||||
this.listeners = [];
|
||||
|
||||
this.unexpectedErrorHandler = function(e: any) {
|
||||
this.unexpectedErrorHandler = function (e: any) {
|
||||
setTimeout(() => {
|
||||
if (e.stack) {
|
||||
throw new Error(e.message + '\n\n' + e.stack);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// taken from https://github.com/microsoft/vscode/tree/master/src/vs/base/common
|
||||
// taken from https://github.com/microsoft/vscode/tree/main/src/vs/base/common
|
||||
|
||||
import { onUnexpectedError } from './errors';
|
||||
import { once as onceFn } from './functional';
|
||||
@@ -115,7 +115,7 @@ export namespace Event {
|
||||
* Given an event, returns the same event but typed as `Event<void>`.
|
||||
*/
|
||||
export function signal<T>(event: Event<T>): Event<void> {
|
||||
return (event as Event<any>) as Event<void>;
|
||||
return event as Event<any> as Event<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -525,9 +525,7 @@ class LeakageMonitor {
|
||||
|
||||
constructor(
|
||||
readonly customThreshold?: number,
|
||||
readonly name: string = Math.random()
|
||||
.toString(18)
|
||||
.slice(2, 5)
|
||||
readonly name: string = Math.random().toString(18).slice(2, 5)
|
||||
) {}
|
||||
|
||||
dispose(): void {
|
||||
@@ -549,10 +547,7 @@ class LeakageMonitor {
|
||||
if (!this._stacks) {
|
||||
this._stacks = new Map();
|
||||
}
|
||||
const stack = new Error()
|
||||
.stack!.split('\n')
|
||||
.slice(3)
|
||||
.join('\n');
|
||||
const stack = new Error().stack!.split('\n').slice(3).join('\n');
|
||||
const count = this._stacks.get(stack) || 0;
|
||||
this._stacks.set(stack, count + 1);
|
||||
this._warnCountdown -= 1;
|
||||
@@ -607,7 +602,7 @@ class LeakageMonitor {
|
||||
}
|
||||
*/
|
||||
export class Emitter<T> {
|
||||
private static readonly _noop = function() {};
|
||||
private static readonly _noop = function () {};
|
||||
|
||||
private readonly _options?: EmitterOptions;
|
||||
private readonly _leakageMon?: LeakageMonitor;
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// taken from https://github.com/microsoft/vscode/tree/master/src/vs/base/common
|
||||
// taken from https://github.com/microsoft/vscode/tree/main/src/vs/base/common
|
||||
|
||||
export function once<T extends Function>(this: unknown, fn: T): T {
|
||||
const _this = this;
|
||||
let didCall = false;
|
||||
let result: unknown;
|
||||
|
||||
return (function() {
|
||||
return function () {
|
||||
if (didCall) {
|
||||
return result;
|
||||
}
|
||||
@@ -19,5 +19,5 @@ export function once<T extends Function>(this: unknown, fn: T): T {
|
||||
result = fn.apply(_this, arguments);
|
||||
|
||||
return result;
|
||||
} as unknown) as T;
|
||||
} as unknown as T;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// taken from https://github.com/microsoft/vscode/tree/master/src/vs/base/common
|
||||
// taken from https://github.com/microsoft/vscode/tree/main/src/vs/base/common
|
||||
|
||||
export namespace Iterable {
|
||||
export function is<T = any>(thing: any): thing is IterableIterator<T> {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// taken from https://github.com/microsoft/vscode/tree/master/src/vs/base/common
|
||||
// taken from https://github.com/microsoft/vscode/tree/main/src/vs/base/common
|
||||
|
||||
import { once } from './functional';
|
||||
import { Iterable } from './iterator';
|
||||
@@ -164,7 +164,7 @@ export class DisposableStore implements IDisposable {
|
||||
if (!t) {
|
||||
return t;
|
||||
}
|
||||
if (((t as unknown) as DisposableStore) === this) {
|
||||
if ((t as unknown as DisposableStore) === this) {
|
||||
throw new Error('Cannot register a disposable on itself!');
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ export abstract class Disposable implements IDisposable {
|
||||
}
|
||||
|
||||
protected _register<T extends IDisposable>(t: T): T {
|
||||
if (((t as unknown) as Disposable) === this) {
|
||||
if ((t as unknown as Disposable) === this) {
|
||||
throw new Error('Cannot register a disposable on itself!');
|
||||
}
|
||||
return this._store.add(t);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// taken from https://github.com/microsoft/vscode/tree/master/src/vs/base/common
|
||||
// taken from https://github.com/microsoft/vscode/tree/main/src/vs/base/common
|
||||
|
||||
class Node<E> {
|
||||
static readonly Undefined = new Node<any>(undefined);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// taken from https://github.com/microsoft/vscode/tree/master/src/vs/base/common
|
||||
// taken from https://github.com/microsoft/vscode/tree/main/src/vs/base/common
|
||||
|
||||
const LANGUAGE_DEFAULT = 'en';
|
||||
|
||||
|
||||
@@ -361,7 +361,7 @@ describe('SnippetParser', () => {
|
||||
assertIdent('this ${1:is ${2:nested with $var}} and repeating $1');
|
||||
});
|
||||
|
||||
test('Parser, choise marker', () => {
|
||||
test('Parser, choice marker', () => {
|
||||
const { placeholders } = new SnippetParser().parse('${1|one,two,three|}');
|
||||
|
||||
assert.strictEqual(placeholders.length, 1);
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import { convertLinkFormat } from '.';
|
||||
import { TEST_DATA_DIR } from '../../test/test-utils';
|
||||
import { MarkdownResourceProvider } from '../services/markdown-provider';
|
||||
import { Resource } from '../model/note';
|
||||
import { FoamWorkspace } from '../model/workspace';
|
||||
import { Logger } from '../utils/log';
|
||||
import fs from 'fs';
|
||||
import { URI } from '../model/uri';
|
||||
import { createMarkdownParser } from '../services/markdown-parser';
|
||||
import { FileDataStore } from '../../test/test-datastore';
|
||||
|
||||
Logger.setLevel('error');
|
||||
|
||||
describe('generateStdMdLink', () => {
|
||||
let _workspace: FoamWorkspace;
|
||||
// TODO slug must be reserved for actual slugs, not file names
|
||||
const findBySlug = (slug: string): Resource => {
|
||||
return _workspace
|
||||
.list()
|
||||
.find(res => res.uri.getName() === slug) as Resource;
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
/** Use fs for reading files in units where vscode.workspace is unavailable */
|
||||
const readFile = async (uri: URI) =>
|
||||
(await fs.promises.readFile(uri.toFsPath())).toString();
|
||||
const dataStore = new FileDataStore(
|
||||
readFile,
|
||||
TEST_DATA_DIR.joinPath('__scaffold__').toFsPath()
|
||||
);
|
||||
const parser = createMarkdownParser();
|
||||
const mdProvider = new MarkdownResourceProvider(dataStore, parser);
|
||||
_workspace = await FoamWorkspace.fromProviders([mdProvider], dataStore);
|
||||
});
|
||||
|
||||
it('initialised test graph correctly', () => {
|
||||
expect(_workspace.list().length).toEqual(11);
|
||||
});
|
||||
|
||||
it('can generate markdown links correctly', async () => {
|
||||
const note = findBySlug('file-with-different-link-formats');
|
||||
const actual = note.links
|
||||
.filter(link => link.type === 'wikilink')
|
||||
.map(link => convertLinkFormat(link, 'link', _workspace, note));
|
||||
const expected: string[] = [
|
||||
'[first-document](first-document.md)',
|
||||
'[second-document](second-document.md)',
|
||||
'[[non-exist-file]]',
|
||||
'[#one section](<file-with-different-link-formats.md#one section>)',
|
||||
'[another name](<file-with-different-link-formats.md#one section>)',
|
||||
'[an alias](first-document.md)',
|
||||
'[first-document](first-document.md)',
|
||||
];
|
||||
expect(actual.length).toEqual(expected.length);
|
||||
actual.forEach((LinkReplace, index) => {
|
||||
expect(LinkReplace.newText).toEqual(expected[index]);
|
||||
});
|
||||
});
|
||||
|
||||
it('can generate wikilinks correctly', async () => {
|
||||
const note = findBySlug('file-with-different-link-formats');
|
||||
const actual = note.links
|
||||
.filter(link => link.type === 'link')
|
||||
.map(link => convertLinkFormat(link, 'wikilink', _workspace, note));
|
||||
const expected: string[] = ['[[first-document|file]]'];
|
||||
expect(actual.length).toEqual(expected.length);
|
||||
actual.forEach((LinkReplace, index) => {
|
||||
expect(LinkReplace.newText).toEqual(expected[index]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,83 @@
|
||||
import { Resource, ResourceLink } from '../model/note';
|
||||
import { URI } from '../model/uri';
|
||||
import { Range } from '../model/range';
|
||||
import { FoamWorkspace } from '../model/workspace';
|
||||
import { isNone } from '../utils';
|
||||
import { MarkdownLink } from '../services/markdown-link';
|
||||
|
||||
export interface LinkReplace {
|
||||
newText: string;
|
||||
range: Range /* old range */;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a link based on its workspace and the note containing it.
|
||||
* According to targetFormat parameter to decide output format. If link.type === targetFormat, then it simply copy
|
||||
* the rawText into LinkReplace. Therefore, it's recommended to filter before conversion.
|
||||
* If targetFormat isn't supported, or the target resource pointed by link cannot be found, the function will throw
|
||||
* exception.
|
||||
* @param link
|
||||
* @param targetFormat 'wikilink' | 'link'
|
||||
* @param workspace
|
||||
* @param note
|
||||
* @returns LinkReplace { newText: string; range: Range; }
|
||||
*/
|
||||
export function convertLinkFormat(
|
||||
link: ResourceLink,
|
||||
targetFormat: 'wikilink' | 'link',
|
||||
workspace: FoamWorkspace,
|
||||
note: Resource | URI
|
||||
): LinkReplace {
|
||||
const resource = note instanceof URI ? workspace.find(note) : note;
|
||||
const targetUri = workspace.resolveLink(resource, link);
|
||||
/* If it's already the target format or a placeholder, no transformation happens */
|
||||
if (link.type === targetFormat || targetUri.scheme === 'placeholder') {
|
||||
return {
|
||||
newText: link.rawText,
|
||||
range: link.range,
|
||||
};
|
||||
}
|
||||
|
||||
let { target, section, alias } = MarkdownLink.analyzeLink(link);
|
||||
let sectionDivider = section ? '#' : '';
|
||||
|
||||
if (isNone(targetUri)) {
|
||||
throw new Error(
|
||||
`Unexpected state: link to: "${link.rawText}" is not resolvable`
|
||||
);
|
||||
}
|
||||
|
||||
const targetRes = workspace.find(targetUri);
|
||||
let relativeUri = targetRes.uri.relativeTo(resource.uri.getDirectory());
|
||||
|
||||
if (targetFormat === 'wikilink') {
|
||||
return MarkdownLink.createUpdateLinkEdit(link, {
|
||||
target: workspace.getIdentifier(relativeUri),
|
||||
type: 'wikilink',
|
||||
});
|
||||
}
|
||||
|
||||
if (targetFormat === 'link') {
|
||||
/* if alias is empty, construct one as target#section */
|
||||
if (alias === '') {
|
||||
/* in page anchor have no filename */
|
||||
if (relativeUri.getBasename() === resource.uri.getBasename()) {
|
||||
target = '';
|
||||
}
|
||||
alias = `${target}${sectionDivider}${section}`;
|
||||
}
|
||||
|
||||
/* if it's originally an embedded note, the markdown link shouldn't be embedded */
|
||||
const isEmbed = targetRes.type === 'image' ? link.isEmbed : false;
|
||||
|
||||
return MarkdownLink.createUpdateLinkEdit(link, {
|
||||
alias: alias,
|
||||
target: relativeUri.path,
|
||||
isEmbed: isEmbed,
|
||||
type: 'link',
|
||||
});
|
||||
}
|
||||
throw new Error(
|
||||
`Unexpected state: targetFormat: ${targetFormat} is not supported`
|
||||
);
|
||||
}
|
||||
@@ -36,7 +36,7 @@ describe('generateLinkReferences', () => {
|
||||
});
|
||||
|
||||
it('initialised test graph correctly', () => {
|
||||
expect(_workspace.list().length).toEqual(10);
|
||||
expect(_workspace.list().length).toEqual(11);
|
||||
});
|
||||
|
||||
it('should add link references to a file that does not have them', async () => {
|
||||
@@ -141,7 +141,7 @@ describe('generateLinkReferences', () => {
|
||||
newText: textForNote(
|
||||
`
|
||||
[//begin]: # "Autogenerated link references for markdown compatibility"
|
||||
[Note being refered as angel]: <Note being refered as angel> "Note being refered as angel"
|
||||
[Note being referred as angel]: <Note being referred as angel> "Note being referred as angel"
|
||||
[//end]: # "Autogenerated link references"`
|
||||
),
|
||||
range: Range.create(3, 0, 3, 0),
|
||||
@@ -183,13 +183,11 @@ describe('generateLinkReferences', () => {
|
||||
const note = findBySlug('file-with-explicit-and-implicit-link-references');
|
||||
const expected = {
|
||||
newText: textForNote(
|
||||
`[^footerlink]: https://foambubble.github.io/
|
||||
[linkrefenrece]: https://foambubble.github.io/
|
||||
[//begin]: # "Autogenerated link references for markdown compatibility"
|
||||
`[//begin]: # "Autogenerated link references for markdown compatibility"
|
||||
[first-document]: first-document "First Document"
|
||||
[//end]: # "Autogenerated link references"`
|
||||
),
|
||||
range: Range.create(5, 0, 10, 42),
|
||||
range: Range.create(8, 0, 10, 42),
|
||||
};
|
||||
|
||||
const noteText = await _workspace.readAsMarkdown(note.uri);
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { Resource } from '../model/note';
|
||||
import { NoteLinkDefinition, Resource } from '../model/note';
|
||||
import { Range } from '../model/range';
|
||||
import {
|
||||
createMarkdownReferences,
|
||||
stringifyMarkdownLinkReferenceDefinition,
|
||||
} from '../services/markdown-provider';
|
||||
import { createMarkdownReferences } from '../services/markdown-provider';
|
||||
import { FoamWorkspace } from '../model/workspace';
|
||||
import { Position } from '../model/position';
|
||||
import { TextEdit } from '../services/text-edit';
|
||||
import { Position } from '../model/position';
|
||||
|
||||
export const LINK_REFERENCE_DEFINITION_HEADER = `[//begin]: # "Autogenerated link references for markdown compatibility"`;
|
||||
export const LINK_REFERENCE_DEFINITION_FOOTER = `[//end]: # "Autogenerated link references"`;
|
||||
@@ -22,112 +19,62 @@ export const generateLinkReferences = async (
|
||||
return null;
|
||||
}
|
||||
|
||||
const markdownReferences = createMarkdownReferences(
|
||||
const newWikilinkDefinitions = createMarkdownReferences(
|
||||
workspace,
|
||||
note.uri,
|
||||
note,
|
||||
includeExtensions
|
||||
);
|
||||
|
||||
const beginDelimiterDef = note.definitions.find(
|
||||
({ label }) => label === '//begin'
|
||||
);
|
||||
const endDelimiterDef = note.definitions.find(
|
||||
({ label }) => label === '//end'
|
||||
);
|
||||
|
||||
const lines = text.split(eol);
|
||||
|
||||
const targetRange =
|
||||
beginDelimiterDef && endDelimiterDef
|
||||
? Range.createFromPosition(
|
||||
beginDelimiterDef.range.start,
|
||||
endDelimiterDef.range.end
|
||||
)
|
||||
: Range.create(
|
||||
lines.length - 1,
|
||||
lines[lines.length - 1].length,
|
||||
lines.length - 1,
|
||||
lines[lines.length - 1].length
|
||||
);
|
||||
|
||||
const newReferences =
|
||||
markdownReferences.length === 0
|
||||
newWikilinkDefinitions.length === 0
|
||||
? ''
|
||||
: [
|
||||
LINK_REFERENCE_DEFINITION_HEADER,
|
||||
...markdownReferences.map(stringifyMarkdownLinkReferenceDefinition),
|
||||
...newWikilinkDefinitions.map(NoteLinkDefinition.format),
|
||||
LINK_REFERENCE_DEFINITION_FOOTER,
|
||||
].join(eol);
|
||||
|
||||
if (note.definitions.length === 0) {
|
||||
if (newReferences.length === 0) {
|
||||
return null;
|
||||
}
|
||||
// check if the new references match the existing references
|
||||
const existingReferences = lines
|
||||
.slice(targetRange.start.line, targetRange.end.line + 1)
|
||||
.join(eol);
|
||||
|
||||
const lines = text.split(eol);
|
||||
const end = Position.create(
|
||||
lines.length - 1,
|
||||
lines[lines.length - 1].length
|
||||
);
|
||||
const padding = end.character === 0 ? eol : `${eol}${eol}`;
|
||||
return {
|
||||
newText: `${padding}${newReferences}`,
|
||||
range: Range.createFromPosition(end, end),
|
||||
};
|
||||
} else {
|
||||
const first = note.definitions[0];
|
||||
const last = note.definitions[note.definitions.length - 1];
|
||||
// adjust padding based on whether there are existing definitions
|
||||
// and, if not, whether we are on an empty line at the end of the file
|
||||
const padding =
|
||||
newWikilinkDefinitions.length === 0 || // no definitions
|
||||
!Position.isEqual(targetRange.start, targetRange.end) // replace existing definitions
|
||||
? ''
|
||||
: targetRange.start.character > 0 // not an empty line
|
||||
? `${eol}${eol}`
|
||||
: eol;
|
||||
|
||||
let 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(eol);
|
||||
|
||||
const oldReferences = note.definitions
|
||||
.map(stringifyMarkdownLinkReferenceDefinition)
|
||||
.join(eol);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
let 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}${eol}${newReferences}`;
|
||||
}
|
||||
|
||||
return {
|
||||
// @todo: do we need to ensure new lines?
|
||||
newText: `${fullReferences}`,
|
||||
range: Range.createFromPosition(first.range!.start, last.range!.end),
|
||||
};
|
||||
}
|
||||
return existingReferences === newReferences
|
||||
? null
|
||||
: {
|
||||
newText: `${padding}${newReferences}`,
|
||||
range: targetRange,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export { generateLinkReferences } from './generate-link-references';
|
||||
export { generateHeading } from './generate-headings';
|
||||
export { convertLinkFormat } from './convert-links-format';
|
||||
|
||||
@@ -5,7 +5,7 @@ import { FoamGraph } from './graph';
|
||||
import { ResourceParser } from './note';
|
||||
import { ResourceProvider } from './provider';
|
||||
import { FoamTags } from './tags';
|
||||
import { Logger } from '../utils/log';
|
||||
import { Logger, withTiming, withTimingAsync } from '../utils/log';
|
||||
|
||||
export interface Services {
|
||||
dataStore: IDataStore;
|
||||
@@ -25,25 +25,28 @@ export const bootstrap = async (
|
||||
watcher: IWatcher | undefined,
|
||||
dataStore: IDataStore,
|
||||
parser: ResourceParser,
|
||||
initialProviders: ResourceProvider[]
|
||||
initialProviders: ResourceProvider[],
|
||||
defaultExtension: string = '.md'
|
||||
) => {
|
||||
const tsStart = Date.now();
|
||||
|
||||
const workspace = await FoamWorkspace.fromProviders(
|
||||
initialProviders,
|
||||
dataStore
|
||||
const workspace = await withTimingAsync(
|
||||
() =>
|
||||
FoamWorkspace.fromProviders(
|
||||
initialProviders,
|
||||
dataStore,
|
||||
defaultExtension
|
||||
),
|
||||
ms => Logger.info(`Workspace loaded in ${ms}ms`)
|
||||
);
|
||||
|
||||
const tsWsDone = Date.now();
|
||||
Logger.info(`Workspace loaded in ${tsWsDone - tsStart}ms`);
|
||||
const graph = withTiming(
|
||||
() => FoamGraph.fromWorkspace(workspace, true),
|
||||
ms => Logger.info(`Graph loaded in ${ms}ms`)
|
||||
);
|
||||
|
||||
const graph = FoamGraph.fromWorkspace(workspace, true);
|
||||
const tsGraphDone = Date.now();
|
||||
Logger.info(`Graph loaded in ${tsGraphDone - tsWsDone}ms`);
|
||||
|
||||
const tags = FoamTags.fromWorkspace(workspace, true);
|
||||
const tsTagsEnd = Date.now();
|
||||
Logger.info(`Tags loaded in ${tsTagsEnd - tsGraphDone}ms`);
|
||||
const tags = withTiming(
|
||||
() => FoamTags.fromWorkspace(workspace, true),
|
||||
ms => Logger.info(`Tags loaded in ${ms}ms`)
|
||||
);
|
||||
|
||||
watcher?.onDidChange(async uri => {
|
||||
if (matcher.isMatch(uri)) {
|
||||
|
||||
@@ -139,6 +139,21 @@ describe('Graph', () => {
|
||||
).toEqual(['/path/another/page-c.md', '/somewhere/page-b.md']);
|
||||
});
|
||||
|
||||
it('should create inbound connections when targeting a section', () => {
|
||||
const noteA = createTestNote({
|
||||
uri: '/path/to/page-a.md',
|
||||
links: [{ slug: 'page-b#section 2' }],
|
||||
});
|
||||
const noteB = createTestNote({
|
||||
uri: '/somewhere/page-b.md',
|
||||
text: '## Section 1\n\n## Section 2',
|
||||
});
|
||||
const ws = createTestWorkspace().set(noteA).set(noteB);
|
||||
const graph = FoamGraph.fromWorkspace(ws);
|
||||
|
||||
expect(graph.getBacklinks(noteB.uri).length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should support attachments', () => {
|
||||
const noteA = createTestNote({
|
||||
uri: '/path/to/page-a.md',
|
||||
|
||||
34
packages/foam-vscode/src/core/model/location.ts
Normal file
34
packages/foam-vscode/src/core/model/location.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Range } from './range';
|
||||
import { URI } from './uri';
|
||||
|
||||
/**
|
||||
* Represents a location inside a resource, such as a line
|
||||
* inside a text file.
|
||||
*/
|
||||
export interface Location<T> {
|
||||
/**
|
||||
* The resource identifier of this location.
|
||||
*/
|
||||
uri: URI;
|
||||
/**
|
||||
* The document range of this locations.
|
||||
*/
|
||||
range: Range;
|
||||
/**
|
||||
* The data associated to this location.
|
||||
*/
|
||||
data: T;
|
||||
}
|
||||
|
||||
export abstract class Location<T> {
|
||||
static create<T>(uri: URI, range: Range, data: T): Location<T> {
|
||||
return { uri, range, data };
|
||||
}
|
||||
|
||||
static forObjectWithRange<T extends { range: Range }>(
|
||||
uri: URI,
|
||||
obj: T
|
||||
): Location<T> {
|
||||
return Location.create(uri, obj.range, obj);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,19 @@ export interface NoteLinkDefinition {
|
||||
range?: Range;
|
||||
}
|
||||
|
||||
export abstract class NoteLinkDefinition {
|
||||
static format(definition: NoteLinkDefinition) {
|
||||
const url =
|
||||
definition.url.indexOf(' ') > 0 ? `<${definition.url}>` : definition.url;
|
||||
let text = `[${definition.label}]: ${url}`;
|
||||
if (definition.title) {
|
||||
text = `${text} "${definition.title}"`;
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
export interface Tag {
|
||||
label: string;
|
||||
range: Range;
|
||||
@@ -53,6 +66,10 @@ export abstract class Resource {
|
||||
return a.title.localeCompare(b.title);
|
||||
}
|
||||
|
||||
public static sortByPath(a: Resource, b: Resource) {
|
||||
return a.uri.path.localeCompare(b.uri.path);
|
||||
}
|
||||
|
||||
public static isResource(thing: any): thing is Resource {
|
||||
if (!thing) {
|
||||
return false;
|
||||
|
||||
@@ -8,9 +8,9 @@ describe('Foam URI', () => {
|
||||
const base = URI.file('/path/to/file.md');
|
||||
test.each([
|
||||
['https://www.google.com', URI.parse('https://www.google.com')],
|
||||
['/path/to/a/file.md', URI.file('/path/to/a/file.md')],
|
||||
['../relative/file.md', URI.file('/path/relative/file.md')],
|
||||
['#section', base.withFragment('section')],
|
||||
['/path/to/a/file.md', URI.parse('file:///path/to/a/file.md')],
|
||||
['../relative/file.md', URI.parse('file:///path/relative/file.md')],
|
||||
['#section', base.with({ fragment: 'section' })],
|
||||
[
|
||||
'../relative/file.md#section',
|
||||
URI.parse('file:/path/relative/file.md#section'),
|
||||
|
||||
@@ -58,6 +58,11 @@ export class URI {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Will not work with web extension. Use only for testing.
|
||||
* @param value the path to turn into a URI
|
||||
* @returns the file URI
|
||||
*/
|
||||
static file(value: string): URI {
|
||||
const [path, authority] = pathUtils.fromFsPath(value);
|
||||
return new URI({ scheme: 'file', authority, path });
|
||||
@@ -71,7 +76,7 @@ export class URI {
|
||||
const uri = value instanceof URI ? value : URI.parse(value);
|
||||
if (!uri.isAbsolute()) {
|
||||
if (uri.scheme === 'file' || uri.scheme === 'placeholder') {
|
||||
let newUri = this.withFragment(uri.fragment);
|
||||
let newUri = this.with({ fragment: uri.fragment });
|
||||
if (uri.path) {
|
||||
newUri = (isDirectory ? newUri : newUri.getDirectory())
|
||||
.joinPath(uri.path)
|
||||
@@ -119,8 +124,20 @@ export class URI {
|
||||
return new URI({ ...this, path });
|
||||
}
|
||||
|
||||
withFragment(fragment: string): URI {
|
||||
return new URI({ ...this, fragment });
|
||||
with(change: {
|
||||
scheme?: string;
|
||||
authority?: string;
|
||||
path?: string;
|
||||
query?: string;
|
||||
fragment?: string;
|
||||
}): URI {
|
||||
return new URI({
|
||||
scheme: change.scheme ?? this.scheme,
|
||||
authority: change.authority ?? this.authority,
|
||||
path: change.path ?? this.path,
|
||||
query: change.query ?? this.query,
|
||||
fragment: change.fragment ?? this.fragment,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,7 +212,6 @@ function encode(uri: URI, skipEncoding: boolean): string {
|
||||
: encodeURIComponentMinimal;
|
||||
|
||||
let res = '';
|
||||
// eslint-disable-next-line prefer-const
|
||||
let { scheme, authority, path, query, fragment } = uri;
|
||||
if (scheme) {
|
||||
res += scheme;
|
||||
@@ -381,11 +397,30 @@ function encodeURIComponentMinimal(path: string): string {
|
||||
*
|
||||
* TODO this probably needs to be moved to the workspace service
|
||||
*/
|
||||
export function asAbsoluteUri(uri: URI, baseFolders: URI[]): URI {
|
||||
return URI.file(
|
||||
pathUtils.asAbsolutePaths(
|
||||
uri.path,
|
||||
baseFolders.map(f => f.path)
|
||||
)[0]
|
||||
);
|
||||
export function asAbsoluteUri(
|
||||
uriOrPath: URI | string,
|
||||
baseFolders: URI[]
|
||||
): URI {
|
||||
if (baseFolders.length === 0) {
|
||||
throw new Error('At least one base folder needed to compute URI');
|
||||
}
|
||||
const path = uriOrPath instanceof URI ? uriOrPath.path : uriOrPath;
|
||||
if (path.startsWith('/')) {
|
||||
return uriOrPath instanceof URI ? uriOrPath : baseFolders[0].with({ path });
|
||||
}
|
||||
let tokens = path.split('/');
|
||||
while (tokens[0].trim() === '') {
|
||||
tokens.shift();
|
||||
}
|
||||
const firstDir = tokens[0];
|
||||
if (baseFolders.length > 1) {
|
||||
for (const folder of baseFolders) {
|
||||
const lastDir = folder.path.split('/').pop();
|
||||
if (lastDir === firstDir) {
|
||||
tokens = tokens.slice(1);
|
||||
return folder.joinPath(...tokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
return baseFolders[0].joinPath(...tokens);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ describe('Identifier computation', () => {
|
||||
const third = createTestNote({
|
||||
uri: '/another/path/for/page-a.md',
|
||||
});
|
||||
const ws = new FoamWorkspace().set(first).set(second).set(third);
|
||||
const ws = new FoamWorkspace('.md').set(first).set(second).set(third);
|
||||
|
||||
expect(ws.getIdentifier(first.uri)).toEqual('to/page-a');
|
||||
expect(ws.getIdentifier(second.uri)).toEqual('way/for/page-a');
|
||||
@@ -124,11 +124,11 @@ describe('Identifier computation', () => {
|
||||
const third = createTestNote({
|
||||
uri: '/another/path/for/page-a.md',
|
||||
});
|
||||
const ws = new FoamWorkspace().set(first).set(second).set(third);
|
||||
const ws = new FoamWorkspace('.md').set(first).set(second).set(third);
|
||||
|
||||
expect(ws.getIdentifier(first.uri.withFragment('section name'))).toEqual(
|
||||
'to/page-a#section name'
|
||||
);
|
||||
expect(
|
||||
ws.getIdentifier(first.uri.with({ fragment: 'section name' }))
|
||||
).toEqual('to/page-a#section name');
|
||||
});
|
||||
|
||||
const needle = '/project/car/todo';
|
||||
@@ -170,7 +170,7 @@ describe('Identifier computation', () => {
|
||||
});
|
||||
|
||||
it('should ignore elements from the exclude list', () => {
|
||||
const workspace = new FoamWorkspace();
|
||||
const workspace = new FoamWorkspace('.md');
|
||||
const noteA = createTestNote({ uri: '/path/to/note-a.md' });
|
||||
const noteB = createTestNote({ uri: '/path/to/note-b.md' });
|
||||
const noteC = createTestNote({ uri: '/path/to/note-c.md' });
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Emitter } from '../common/event';
|
||||
import { ResourceProvider } from './provider';
|
||||
import { IDisposable } from '../common/lifecycle';
|
||||
import { IDataStore } from '../services/datastore';
|
||||
import TrieMap from 'mnemonist/trie-map';
|
||||
|
||||
export class FoamWorkspace implements IDisposable {
|
||||
private onDidAddEmitter = new Emitter<Resource>();
|
||||
@@ -20,7 +21,12 @@ export class FoamWorkspace implements IDisposable {
|
||||
/**
|
||||
* Resources by path
|
||||
*/
|
||||
private _resources: Map<string, Resource> = new Map();
|
||||
private _resources: TrieMap<string, Resource> = new TrieMap();
|
||||
|
||||
/**
|
||||
* @param defaultExtension: The default extension for notes in this workspace (e.g. `.md`)
|
||||
*/
|
||||
constructor(public defaultExtension: string = '.md') {}
|
||||
|
||||
registerProvider(provider: ResourceProvider) {
|
||||
this.providers.push(provider);
|
||||
@@ -28,7 +34,10 @@ export class FoamWorkspace implements IDisposable {
|
||||
|
||||
set(resource: Resource) {
|
||||
const old = this.find(resource.uri);
|
||||
this._resources.set(normalize(resource.uri.path), resource);
|
||||
|
||||
// store resource
|
||||
this._resources.set(this.getTrieIdentifier(resource.uri.path), resource);
|
||||
|
||||
isSome(old)
|
||||
? this.onDidUpdateEmitter.fire({ old: old, new: resource })
|
||||
: this.onDidAddEmitter.fire(resource);
|
||||
@@ -36,8 +45,8 @@ export class FoamWorkspace implements IDisposable {
|
||||
}
|
||||
|
||||
delete(uri: URI) {
|
||||
const deleted = this._resources.get(normalize(uri.path));
|
||||
this._resources.delete(normalize(uri.path));
|
||||
const deleted = this._resources.get(this.getTrieIdentifier(uri));
|
||||
this._resources.delete(this.getTrieIdentifier(uri));
|
||||
|
||||
isSome(deleted) && this.onDidDeleteEmitter.fire(deleted);
|
||||
return deleted ?? null;
|
||||
@@ -52,7 +61,11 @@ export class FoamWorkspace implements IDisposable {
|
||||
}
|
||||
|
||||
public resources(): IterableIterator<Resource> {
|
||||
return this._resources.values();
|
||||
const resources: Array<Resource> = Array.from(
|
||||
this._resources.values()
|
||||
).sort(Resource.sortByPath);
|
||||
|
||||
return resources.values();
|
||||
}
|
||||
|
||||
public get(uri: URI): Resource {
|
||||
@@ -65,16 +78,22 @@ export class FoamWorkspace implements IDisposable {
|
||||
}
|
||||
|
||||
public listByIdentifier(identifier: string): Resource[] {
|
||||
const needle = normalize('/' + identifier);
|
||||
let needle = this.getTrieIdentifier(identifier);
|
||||
|
||||
const mdNeedle =
|
||||
getExtension(needle) !== '.md' ? needle + '.md' : undefined;
|
||||
const resources = [];
|
||||
for (const key of this._resources.keys()) {
|
||||
if ((mdNeedle && key.endsWith(mdNeedle)) || key.endsWith(needle)) {
|
||||
resources.push(this._resources.get(normalize(key)));
|
||||
}
|
||||
getExtension(normalize(identifier)) !== this.defaultExtension
|
||||
? this.getTrieIdentifier(identifier + this.defaultExtension)
|
||||
: undefined;
|
||||
|
||||
const resources: Resource[] = [];
|
||||
|
||||
this._resources.find(needle).forEach(elm => resources.push(elm[1]));
|
||||
|
||||
if (mdNeedle) {
|
||||
this._resources.find(mdNeedle).forEach(elm => resources.push(elm[1]));
|
||||
}
|
||||
return resources.sort((a, b) => a.uri.path.localeCompare(b.uri.path));
|
||||
|
||||
return resources.sort(Resource.sortByPath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,63 +104,86 @@ export class FoamWorkspace implements IDisposable {
|
||||
public getIdentifier(forResource: URI, exclude?: URI[]): string {
|
||||
const amongst = [];
|
||||
const basename = forResource.getBasename();
|
||||
for (const res of this._resources.values()) {
|
||||
// skip elements that cannot possibly match
|
||||
if (!res.uri.path.endsWith(basename)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.listByIdentifier(basename).map(res => {
|
||||
// skip self
|
||||
if (res.uri.isEqual(forResource)) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
// skip exclude list
|
||||
if (exclude && exclude.find(ex => ex.isEqual(res.uri))) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
amongst.push(res.uri);
|
||||
}
|
||||
});
|
||||
|
||||
let identifier = FoamWorkspace.getShortestIdentifier(
|
||||
forResource.path,
|
||||
amongst.map(uri => uri.path)
|
||||
);
|
||||
identifier = changeExtension(identifier, '.md', '');
|
||||
identifier = changeExtension(identifier, this.defaultExtension, '');
|
||||
if (forResource.fragment) {
|
||||
identifier += `#${forResource.fragment}`;
|
||||
}
|
||||
return identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a note identifier in reversed order. Used to optimise the storage of notes in
|
||||
* the workspace to optimise retrieval of notes.
|
||||
*
|
||||
* @param reference the URI path to reverse
|
||||
*/
|
||||
private getTrieIdentifier(reference: URI | string): string {
|
||||
let path: string;
|
||||
if (reference instanceof URI) {
|
||||
path = (reference as URI).path;
|
||||
} else {
|
||||
path = reference as string;
|
||||
}
|
||||
|
||||
let reversedPath = normalize(path).split('/').reverse().join('/');
|
||||
|
||||
if (reversedPath.indexOf('/') < 0) {
|
||||
reversedPath = reversedPath + '/';
|
||||
}
|
||||
|
||||
return reversedPath;
|
||||
}
|
||||
|
||||
public find(reference: URI | string, baseUri?: URI): Resource | null {
|
||||
if (reference instanceof URI) {
|
||||
return this._resources.get(normalize((reference as URI).path)) ?? null;
|
||||
return this._resources.get(this.getTrieIdentifier(reference)) ?? null;
|
||||
}
|
||||
let resource: Resource | null = null;
|
||||
const [path, fragment] = (reference as string).split('#');
|
||||
if (FoamWorkspace.isIdentifier(path)) {
|
||||
resource = this.listByIdentifier(path)[0];
|
||||
} else {
|
||||
const candidates = [path, path + '.md'];
|
||||
const candidates = [path, path + this.defaultExtension];
|
||||
for (const candidate of candidates) {
|
||||
const searchKey = isAbsolute(candidate)
|
||||
? candidate
|
||||
: isSome(baseUri)
|
||||
? baseUri.resolve(candidate).path
|
||||
: null;
|
||||
resource = this._resources.get(normalize(searchKey));
|
||||
resource = this._resources.get(this.getTrieIdentifier(searchKey));
|
||||
if (resource) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resource && fragment) {
|
||||
resource = { ...resource, uri: resource.uri.withFragment(fragment) };
|
||||
resource = {
|
||||
...resource,
|
||||
uri: resource.uri.with({ fragment: fragment }),
|
||||
};
|
||||
}
|
||||
return resource ?? null;
|
||||
}
|
||||
|
||||
public resolveLink(resource: Resource, link: ResourceLink): URI {
|
||||
// TODO add tests
|
||||
for (const provider of this.providers) {
|
||||
if (provider.supports(resource.uri)) {
|
||||
return provider.resolveLink(this, resource, link);
|
||||
@@ -237,9 +279,10 @@ export class FoamWorkspace implements IDisposable {
|
||||
|
||||
static async fromProviders(
|
||||
providers: ResourceProvider[],
|
||||
dataStore: IDataStore
|
||||
dataStore: IDataStore,
|
||||
defaultExtension: string = '.md'
|
||||
): Promise<FoamWorkspace> {
|
||||
const workspace = new FoamWorkspace();
|
||||
const workspace = new FoamWorkspace(defaultExtension);
|
||||
await Promise.all(providers.map(p => workspace.registerProvider(p)));
|
||||
const files = await dataStore.list();
|
||||
await Promise.all(files.map(f => workspace.fetchAndSet(f)));
|
||||
|
||||
@@ -3,17 +3,15 @@ import { URI } from '../model/uri';
|
||||
import { FoamWorkspace } from '../model/workspace';
|
||||
import { IDisposable } from '../common/lifecycle';
|
||||
import { ResourceProvider } from '../model/provider';
|
||||
import { getFoamVsCodeConfig } from '../../services/config';
|
||||
|
||||
const attachmentExtConfig = getFoamVsCodeConfig(
|
||||
'files.attachmentExtensions',
|
||||
''
|
||||
)
|
||||
.split(' ')
|
||||
.map(ext => '.' + ext.trim());
|
||||
|
||||
const imageExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp'];
|
||||
const attachmentExtensions = [...attachmentExtConfig, ...imageExtensions];
|
||||
export const imageExtensions = [
|
||||
'.png',
|
||||
'.jpg',
|
||||
'.jpeg',
|
||||
'.gif',
|
||||
'.svg',
|
||||
'.webp',
|
||||
];
|
||||
|
||||
const asResource = (uri: URI): Resource => {
|
||||
const type = imageExtensions.includes(uri.getExtension())
|
||||
@@ -34,9 +32,14 @@ const asResource = (uri: URI): Resource => {
|
||||
|
||||
export class AttachmentResourceProvider implements ResourceProvider {
|
||||
private disposables: IDisposable[] = [];
|
||||
public readonly attachmentExtensions: string[];
|
||||
|
||||
constructor(attachmentExtensions: string[] = []) {
|
||||
this.attachmentExtensions = [...imageExtensions, ...attachmentExtensions];
|
||||
}
|
||||
|
||||
supports(uri: URI) {
|
||||
return attachmentExtensions.includes(
|
||||
return this.attachmentExtensions.includes(
|
||||
uri.getExtension().toLocaleLowerCase()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ export class GenericDataStore implements IDataStore {
|
||||
/**
|
||||
* A matcher that instead of using globs uses a list of files to
|
||||
* check the matches.
|
||||
* The {@link refresh} function has been added to the interface to accomodate
|
||||
* The {@link refresh} function has been added to the interface to accommodate
|
||||
* this matcher, far from ideal but to be refactored later
|
||||
*/
|
||||
export class FileListBasedMatcher implements IMatcher {
|
||||
|
||||
@@ -254,4 +254,185 @@ describe('MarkdownLink', () => {
|
||||
expect(edit.range).toEqual(link.range);
|
||||
});
|
||||
});
|
||||
|
||||
describe('convert wikilink to link', () => {
|
||||
it('should generate default alias if no one', () => {
|
||||
const wikilink = parser.parse(getRandomURI(), `[[wikilink]]`).links[0];
|
||||
const wikilinkEdit = MarkdownLink.createUpdateLinkEdit(wikilink, {
|
||||
type: 'link',
|
||||
});
|
||||
expect(wikilinkEdit.newText).toEqual(`[wikilink](wikilink)`);
|
||||
expect(wikilinkEdit.range).toEqual(wikilink.range);
|
||||
|
||||
const wikilinkWithSection = parser.parse(
|
||||
getRandomURI(),
|
||||
`[[wikilink#section]]`
|
||||
).links[0];
|
||||
const wikilinkWithSectionEdit = MarkdownLink.createUpdateLinkEdit(
|
||||
wikilinkWithSection,
|
||||
{
|
||||
type: 'link',
|
||||
}
|
||||
);
|
||||
expect(wikilinkWithSectionEdit.newText).toEqual(
|
||||
`[wikilink#section](wikilink#section)`
|
||||
);
|
||||
expect(wikilinkWithSectionEdit.range).toEqual(wikilinkWithSection.range);
|
||||
});
|
||||
|
||||
it('should use alias in the wikilik the if there has one', () => {
|
||||
const wikilink = parser.parse(
|
||||
getRandomURI(),
|
||||
`[[wikilink#section|alias]]`
|
||||
).links[0];
|
||||
const wikilinkEdit = MarkdownLink.createUpdateLinkEdit(wikilink, {
|
||||
type: 'link',
|
||||
});
|
||||
expect(wikilinkEdit.newText).toEqual(`[alias](wikilink#section)`);
|
||||
expect(wikilinkEdit.range).toEqual(wikilink.range);
|
||||
});
|
||||
});
|
||||
|
||||
describe('convert link to wikilink', () => {
|
||||
it('should reorganize target, section, and alias in wikilink manner', () => {
|
||||
const link = parser.parse(getRandomURI(), `[link](to/path.md)`).links[0];
|
||||
const linkEdit = MarkdownLink.createUpdateLinkEdit(link, {
|
||||
type: 'wikilink',
|
||||
});
|
||||
expect(linkEdit.newText).toEqual(`[[to/path.md|link]]`);
|
||||
expect(linkEdit.range).toEqual(link.range);
|
||||
|
||||
const linkWithSection = parser.parse(
|
||||
getRandomURI(),
|
||||
`[link](to/path.md#section)`
|
||||
).links[0];
|
||||
const linkWithSectionEdit = MarkdownLink.createUpdateLinkEdit(
|
||||
linkWithSection,
|
||||
{
|
||||
type: 'wikilink',
|
||||
}
|
||||
);
|
||||
expect(linkWithSectionEdit.newText).toEqual(
|
||||
`[[to/path.md#section|link]]`
|
||||
);
|
||||
expect(linkWithSectionEdit.range).toEqual(linkWithSection.range);
|
||||
});
|
||||
|
||||
it('should use alias in the wikilik the if there has one', () => {
|
||||
const wikilink = parser.parse(
|
||||
getRandomURI(),
|
||||
`[[wikilink#section|alias]]`
|
||||
).links[0];
|
||||
const wikilinkEdit = MarkdownLink.createUpdateLinkEdit(wikilink, {
|
||||
type: 'link',
|
||||
});
|
||||
expect(wikilinkEdit.newText).toEqual(`[alias](wikilink#section)`);
|
||||
expect(wikilinkEdit.range).toEqual(wikilink.range);
|
||||
});
|
||||
});
|
||||
|
||||
describe('convert to its original type', () => {
|
||||
it('should remain unchanged', () => {
|
||||
const link = parser.parse(getRandomURI(), `[link](to/path.md#section)`)
|
||||
.links[0];
|
||||
const linkEdit = MarkdownLink.createUpdateLinkEdit(link, {
|
||||
type: 'link',
|
||||
});
|
||||
expect(linkEdit.newText).toEqual(`[link](to/path.md#section)`);
|
||||
expect(linkEdit.range).toEqual(link.range);
|
||||
|
||||
const wikilink = parser.parse(
|
||||
getRandomURI(),
|
||||
`[[wikilink#section|alias]]`
|
||||
).links[0];
|
||||
const wikilinkEdit = MarkdownLink.createUpdateLinkEdit(wikilink, {
|
||||
type: 'wikilink',
|
||||
});
|
||||
expect(wikilinkEdit.newText).toEqual(`[[wikilink#section|alias]]`);
|
||||
expect(wikilinkEdit.range).toEqual(wikilink.range);
|
||||
});
|
||||
});
|
||||
|
||||
describe('change isEmbed property', () => {
|
||||
it('should change isEmbed only', () => {
|
||||
const wikilink = parser.parse(getRandomURI(), `[[wikilink]]`).links[0];
|
||||
const wikilinkEdit = MarkdownLink.createUpdateLinkEdit(wikilink, {
|
||||
isEmbed: true,
|
||||
});
|
||||
expect(wikilinkEdit.newText).toEqual(`![[wikilink]]`);
|
||||
expect(wikilinkEdit.range).toEqual(wikilink.range);
|
||||
|
||||
const link = parser.parse(getRandomURI(), ``).links[0];
|
||||
const linkEdit = MarkdownLink.createUpdateLinkEdit(link, {
|
||||
isEmbed: false,
|
||||
});
|
||||
expect(linkEdit.newText).toEqual(`[link](to/path.md)`);
|
||||
expect(linkEdit.range).toEqual(link.range);
|
||||
});
|
||||
|
||||
it('should be unchanged if the update value is the same as the original one', () => {
|
||||
const embeddedWikilink = parser.parse(getRandomURI(), `![[wikilink]]`)
|
||||
.links[0];
|
||||
const embeddedWikilinkEdit = MarkdownLink.createUpdateLinkEdit(
|
||||
embeddedWikilink,
|
||||
{
|
||||
isEmbed: true,
|
||||
}
|
||||
);
|
||||
expect(embeddedWikilinkEdit.newText).toEqual(`![[wikilink]]`);
|
||||
expect(embeddedWikilinkEdit.range).toEqual(embeddedWikilink.range);
|
||||
|
||||
const link = parser.parse(getRandomURI(), `[link](to/path.md)`).links[0];
|
||||
const linkEdit = MarkdownLink.createUpdateLinkEdit(link, {
|
||||
isEmbed: false,
|
||||
});
|
||||
expect(linkEdit.newText).toEqual(`[link](to/path.md)`);
|
||||
expect(linkEdit.range).toEqual(link.range);
|
||||
});
|
||||
});
|
||||
|
||||
describe('insert angles', () => {
|
||||
it('should insert angles when meeting space in links', () => {
|
||||
const link = parser.parse(getRandomURI(), ``).links[0];
|
||||
const linkAddSection = MarkdownLink.createUpdateLinkEdit(link, {
|
||||
section: 'one section',
|
||||
});
|
||||
expect(linkAddSection.newText).toEqual(
|
||||
``
|
||||
);
|
||||
expect(linkAddSection.range).toEqual(link.range);
|
||||
|
||||
const linkChangingTarget = parser.parse(
|
||||
getRandomURI(),
|
||||
`[link](to/path.md#one-section)`
|
||||
).links[0];
|
||||
const linkEdit = MarkdownLink.createUpdateLinkEdit(linkChangingTarget, {
|
||||
target: 'to/another path.md',
|
||||
});
|
||||
expect(linkEdit.newText).toEqual(
|
||||
`[link](<to/another path.md#one-section>)`
|
||||
);
|
||||
expect(linkEdit.range).toEqual(linkChangingTarget.range);
|
||||
|
||||
const wikilink = parser.parse(getRandomURI(), `[[wikilink#one section]]`)
|
||||
.links[0];
|
||||
const wikilinkEdit = MarkdownLink.createUpdateLinkEdit(wikilink, {
|
||||
type: 'link',
|
||||
});
|
||||
expect(wikilinkEdit.newText).toEqual(
|
||||
`[wikilink#one section](<wikilink#one section>)`
|
||||
);
|
||||
expect(wikilinkEdit.range).toEqual(wikilink.range);
|
||||
});
|
||||
|
||||
it('should not insert angles in wikilink', () => {
|
||||
const wikilink = parser.parse(getRandomURI(), `[[wikilink#one section]]`)
|
||||
.links[0];
|
||||
const wikilinkEdit = MarkdownLink.createUpdateLinkEdit(wikilink, {
|
||||
target: 'another wikilink',
|
||||
});
|
||||
expect(wikilinkEdit.newText).toEqual(`[[another wikilink#one section]]`);
|
||||
expect(wikilinkEdit.range).toEqual(wikilink.range);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ResourceLink } from '../model/note';
|
||||
import { TextEdit } from './text-edit';
|
||||
|
||||
export abstract class MarkdownLink {
|
||||
private static wikilinkRegex = new RegExp(
|
||||
@@ -38,29 +39,41 @@ export abstract class MarkdownLink {
|
||||
|
||||
public static createUpdateLinkEdit(
|
||||
link: ResourceLink,
|
||||
delta: { target?: string; section?: string; alias?: string }
|
||||
) {
|
||||
delta: {
|
||||
target?: string;
|
||||
section?: string;
|
||||
alias?: string;
|
||||
type?: 'wikilink' | 'link';
|
||||
isEmbed?: boolean;
|
||||
}
|
||||
): TextEdit {
|
||||
const { target, section, alias } = MarkdownLink.analyzeLink(link);
|
||||
const newTarget = delta.target ?? target;
|
||||
const newSection = delta.section ?? section ?? '';
|
||||
const newAlias = delta.alias ?? alias ?? '';
|
||||
const sectionDivider = newSection ? '#' : '';
|
||||
const aliasDivider = newAlias ? '|' : '';
|
||||
const embed = link.isEmbed ? '!' : '';
|
||||
if (link.type === 'wikilink') {
|
||||
const embed = delta.isEmbed ?? link.isEmbed ? '!' : '';
|
||||
const type = delta.type ?? link.type;
|
||||
if (type === 'wikilink') {
|
||||
return {
|
||||
newText: `${embed}[[${newTarget}${sectionDivider}${newSection}${aliasDivider}${newAlias}]]`,
|
||||
range: link.range,
|
||||
};
|
||||
}
|
||||
if (link.type === 'link') {
|
||||
if (type === 'link') {
|
||||
const defaultAlias = () => {
|
||||
return `${newTarget}${sectionDivider}${newSection}`;
|
||||
};
|
||||
const useAngles =
|
||||
newTarget.indexOf(' ') > 0 || newSection.indexOf(' ') > 0;
|
||||
return {
|
||||
newText: `${embed}[${newAlias}](${newTarget}${sectionDivider}${newSection})`,
|
||||
newText: `${embed}[${newAlias ? newAlias : defaultAlias()}](${
|
||||
useAngles ? '<' : ''
|
||||
}${newTarget}${sectionDivider}${newSection}${useAngles ? '>' : ''})`,
|
||||
range: link.range,
|
||||
};
|
||||
}
|
||||
throw new Error(
|
||||
`Unexpected state: link of type ${link.type} is not supported`
|
||||
);
|
||||
throw new Error(`Unexpected state: link of type ${type} is not supported`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Logger } from '../utils/log';
|
||||
import { URI } from '../model/uri';
|
||||
import { Range } from '../model/range';
|
||||
import { getRandomURI } from '../../test/test-utils';
|
||||
import { Position } from '../model/position';
|
||||
|
||||
Logger.setLevel('error');
|
||||
|
||||
@@ -241,6 +242,18 @@ title: - one
|
||||
|
||||
expect(note.properties).toEqual({});
|
||||
});
|
||||
|
||||
it('#1467 - should parse yaml frontmatter with colon in value', () => {
|
||||
const note = createNoteFromMarkdown(`
|
||||
---
|
||||
tags: test
|
||||
source: https://example.com/page:123
|
||||
---
|
||||
|
||||
# Note with colon in meta value\n`);
|
||||
expect(note.properties.source).toBe('https://example.com/page:123');
|
||||
expect(note.tags[0].label).toEqual('test');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Tags', () => {
|
||||
@@ -319,20 +332,55 @@ this is some #text that includes #tags we #care-about.
|
||||
]);
|
||||
});
|
||||
|
||||
it('provides rough range for tags in yaml', () => {
|
||||
it('provides a specific 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(`
|
||||
---
|
||||
prop: hello world
|
||||
tags: [hello, world, this_is_good]
|
||||
another: i love the world
|
||||
---
|
||||
# this is a heading
|
||||
this is some text
|
||||
`);
|
||||
expect(noteA.tags[0]).toEqual({
|
||||
label: 'hello',
|
||||
range: Range.create(1, 0, 3, 3),
|
||||
range: Range.create(3, 7, 3, 12),
|
||||
});
|
||||
expect(noteA.tags[1]).toEqual({
|
||||
label: 'world',
|
||||
range: Range.create(3, 14, 3, 19),
|
||||
});
|
||||
expect(noteA.tags[2]).toEqual({
|
||||
label: 'this_is_good',
|
||||
range: Range.create(3, 21, 3, 33),
|
||||
});
|
||||
|
||||
const noteB = createNoteFromMarkdown(`
|
||||
---
|
||||
prop: hello world
|
||||
tags:
|
||||
- hello
|
||||
- world
|
||||
- this_is_good
|
||||
another: i love the world
|
||||
---
|
||||
# this is a heading
|
||||
this is some text
|
||||
`);
|
||||
expect(noteB.tags[0]).toEqual({
|
||||
label: 'hello',
|
||||
range: Range.create(4, 2, 4, 7),
|
||||
});
|
||||
expect(noteB.tags[1]).toEqual({
|
||||
label: 'world',
|
||||
range: Range.create(5, 2, 5, 7),
|
||||
});
|
||||
expect(noteB.tags[2]).toEqual({
|
||||
label: 'this_is_good',
|
||||
range: Range.create(6, 2, 6, 14),
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -464,7 +512,7 @@ But with some content.
|
||||
});
|
||||
});
|
||||
|
||||
describe('Block detection', () => {
|
||||
describe('Block detection for lists', () => {
|
||||
const md = `
|
||||
- this is block 1
|
||||
- this is [[block]] 2
|
||||
@@ -508,3 +556,76 @@ this is another simple line
|
||||
- this is block 2.1`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('block detection for sections', () => {
|
||||
const markdown = `
|
||||
# Section 1
|
||||
- this is block 1
|
||||
- this is [[block]] 2
|
||||
- this is block 2.1
|
||||
|
||||
# Section 2
|
||||
this is a simple line
|
||||
this is another simple line
|
||||
|
||||
## Section 2.1
|
||||
- this is block 3.1
|
||||
- this is block 3.1.1
|
||||
- this is block 3.2
|
||||
|
||||
# Section 3
|
||||
# Section 4
|
||||
some text
|
||||
some text
|
||||
`;
|
||||
|
||||
it('should return correct block for valid markdown string with line number', () => {
|
||||
const { block, nLines } = getBlockFor(markdown, 1);
|
||||
expect(block).toEqual(`# Section 1
|
||||
- this is block 1
|
||||
- this is [[block]] 2
|
||||
- this is block 2.1
|
||||
`);
|
||||
expect(nLines).toEqual(5);
|
||||
});
|
||||
|
||||
it('should return correct block for valid markdown string with position', () => {
|
||||
const { block, nLines } = getBlockFor(markdown, 6);
|
||||
expect(block).toEqual(`# Section 2
|
||||
this is a simple line
|
||||
this is another simple line
|
||||
|
||||
## Section 2.1
|
||||
- this is block 3.1
|
||||
- this is block 3.1.1
|
||||
- this is block 3.2
|
||||
`);
|
||||
expect(nLines).toEqual(9);
|
||||
});
|
||||
|
||||
it('should return single line for section with no content', () => {
|
||||
const { block, nLines } = getBlockFor(markdown, 15);
|
||||
expect(block).toEqual('# Section 3');
|
||||
expect(nLines).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return till end of file for last section', () => {
|
||||
const { block, nLines } = getBlockFor(markdown, 16);
|
||||
expect(block).toEqual(`# Section 4
|
||||
some text
|
||||
some text`);
|
||||
expect(nLines).toEqual(3);
|
||||
});
|
||||
|
||||
it('should return single line for non-existing line number', () => {
|
||||
const { block, nLines } = getBlockFor(markdown, 100);
|
||||
expect(block).toEqual('');
|
||||
expect(nLines).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return single line for non-existing position', () => {
|
||||
const { block, nLines } = getBlockFor(markdown, Position.create(100, 2));
|
||||
expect(block).toEqual('');
|
||||
expect(nLines).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -173,15 +173,51 @@ const getTextFromChildren = (root: Node): string => {
|
||||
return text;
|
||||
};
|
||||
|
||||
function getPropertiesInfoFromYAML(yamlText: string): {
|
||||
[key: string]: { key: string; value: string; text: string; line: number };
|
||||
} {
|
||||
const yamlProps = `\n${yamlText}`
|
||||
.split(/[\n](\w+:)/g)
|
||||
.filter(item => item.trim() !== '');
|
||||
const lines = yamlText.split('\n');
|
||||
let result: { line: number; key: string; text: string; value: string }[] = [];
|
||||
for (let i = 0; i < yamlProps.length / 2; i++) {
|
||||
const key = yamlProps[i * 2].replace(':', '');
|
||||
const value = yamlProps[i * 2 + 1].trim();
|
||||
const text = yamlProps[i * 2] + yamlProps[i * 2 + 1];
|
||||
result.push({ key, value, text, line: -1 });
|
||||
}
|
||||
result = result.map(p => {
|
||||
const line = lines.findIndex(l => l.startsWith(p.key + ':'));
|
||||
return { ...p, line };
|
||||
});
|
||||
return result.reduce((acc, curr) => {
|
||||
acc[curr.key] = curr;
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
const tagsPlugin: ParserPlugin = {
|
||||
name: 'tags',
|
||||
onDidFindProperties: (props, note, node) => {
|
||||
if (isSome(props.tags)) {
|
||||
const tagPropertyInfo = getPropertiesInfoFromYAML((node as any).value)[
|
||||
'tags'
|
||||
];
|
||||
const tagPropertyStartLine =
|
||||
node.position!.start.line + tagPropertyInfo.line;
|
||||
const tagPropertyLines = tagPropertyInfo.text.split('\n');
|
||||
const yamlTags = extractTagsFromProp(props.tags);
|
||||
for (const tag of yamlTags) {
|
||||
const tagLine = tagPropertyLines.findIndex(l => l.includes(tag));
|
||||
const line = tagPropertyStartLine + tagLine;
|
||||
const charStart = tagPropertyLines[tagLine].indexOf(tag);
|
||||
note.tags.push({
|
||||
label: tag,
|
||||
range: astPositionToFoamRange(node.position!),
|
||||
range: Range.createFromPosition(
|
||||
Position.create(line, charStart),
|
||||
Position.create(line, charStart + tag.length)
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -241,7 +277,7 @@ const sectionsPlugin: ParserPlugin = {
|
||||
astPointToFoamPosition(tree.position.end).line + 1,
|
||||
0
|
||||
);
|
||||
// Close all the remainig sections
|
||||
// Close all the remaining sections
|
||||
while (sectionStack.length > 0) {
|
||||
const section = sectionStack.pop();
|
||||
note.sections.push({
|
||||
@@ -268,7 +304,7 @@ const titlePlugin: ParserPlugin = {
|
||||
}
|
||||
},
|
||||
onDidFindProperties: (props, note) => {
|
||||
// Give precendence to the title from the frontmatter if it exists
|
||||
// Give precedence to the title from the frontmatter if it exists
|
||||
note.title = props.title?.toString() ?? note.title;
|
||||
},
|
||||
onDidVisitTree: (tree, note) => {
|
||||
@@ -433,19 +469,37 @@ export const getBlockFor = (
|
||||
const searchLine = typeof line === 'number' ? line : line.line;
|
||||
const tree = blockParser.parse(markdown);
|
||||
const lines = markdown.split('\n');
|
||||
let block = null;
|
||||
let nLines = 0;
|
||||
let startLine = -1;
|
||||
let endLine = -1;
|
||||
|
||||
// For list items, we also include the sub-lists
|
||||
visit(tree, ['listItem'], (node: any) => {
|
||||
if (node.position.start.line === searchLine + 1) {
|
||||
block = lines
|
||||
.slice(node.position.start.line - 1, node.position.end.line)
|
||||
.join('\n');
|
||||
nLines = node.position.end.line - node.position.start.line;
|
||||
startLine = node.position.start.line - 1;
|
||||
endLine = node.position.end.line;
|
||||
return visit.EXIT;
|
||||
}
|
||||
});
|
||||
if (block == null) {
|
||||
block = lines[searchLine];
|
||||
}
|
||||
|
||||
// For headings, we also include the sub-sections
|
||||
let headingLevel = -1;
|
||||
visit(tree, ['heading'], (node: any) => {
|
||||
if (startLine > -1 && node.depth <= headingLevel) {
|
||||
endLine = node.position.start.line - 1;
|
||||
return visit.EXIT;
|
||||
}
|
||||
if (node.position.start.line === searchLine + 1) {
|
||||
headingLevel = node.depth;
|
||||
startLine = node.position.start.line - 1;
|
||||
endLine = lines.length - 1; // in case it's the last section
|
||||
}
|
||||
});
|
||||
|
||||
let nLines = startLine === -1 ? 1 : endLine - startLine;
|
||||
let block =
|
||||
startLine === -1
|
||||
? lines[searchLine] ?? ''
|
||||
: lines.slice(startLine, endLine).join('\n');
|
||||
|
||||
return { block, nLines };
|
||||
};
|
||||
|
||||
@@ -148,7 +148,7 @@ describe('Link resolution', () => {
|
||||
const ws = createTestWorkspace().set(noteA).set(noteB);
|
||||
|
||||
expect(ws.resolveLink(noteA, noteA.links[0])).toEqual(
|
||||
noteB.uri.withFragment('section')
|
||||
noteB.uri.with({ fragment: 'section' })
|
||||
);
|
||||
});
|
||||
|
||||
@@ -163,9 +163,68 @@ describe('Link resolution', () => {
|
||||
const ws = createTestWorkspace().set(noteA);
|
||||
|
||||
expect(ws.resolveLink(noteA, noteA.links[0])).toEqual(
|
||||
noteA.uri.withFragment('section')
|
||||
noteA.uri.with({ fragment: 'section' })
|
||||
);
|
||||
});
|
||||
|
||||
it('should resolve wikilinks with special characters', () => {
|
||||
const ws = createTestWorkspace();
|
||||
const noteA = createNoteFromMarkdown(
|
||||
`Link to [[page: a]] and [[page %b%]] and [[page? c]] and [[[page] d]] and
|
||||
[[page ^e^]] and [[page \`f\`]] and [[page {g}]] and [[page ~i]] and
|
||||
[[page /j]]`
|
||||
);
|
||||
const noteB = createNoteFromMarkdown(
|
||||
'Note containing :',
|
||||
'/dir1/page: a.md'
|
||||
);
|
||||
const noteC = createNoteFromMarkdown(
|
||||
'Note containing %',
|
||||
'/dir1/page %b%.md'
|
||||
);
|
||||
const noteD = createNoteFromMarkdown(
|
||||
'Note containing ?',
|
||||
'/dir1/page? c.md'
|
||||
);
|
||||
const noteE = createNoteFromMarkdown(
|
||||
'Note containing ]',
|
||||
'/dir1/[page] d.md'
|
||||
);
|
||||
const noteF = createNoteFromMarkdown(
|
||||
'Note containing ^',
|
||||
'/dir1/page ^e^.md'
|
||||
);
|
||||
const noteG = createNoteFromMarkdown(
|
||||
'Note containing `',
|
||||
'/dir1/page `f`.md'
|
||||
);
|
||||
const noteH = createNoteFromMarkdown(
|
||||
'Note containing { and }',
|
||||
'/dir1/page {g}.md'
|
||||
);
|
||||
const noteI = createNoteFromMarkdown(
|
||||
'Note containing ~',
|
||||
'/dir1/page ~i.md'
|
||||
);
|
||||
ws.set(noteA)
|
||||
.set(noteB)
|
||||
.set(noteC)
|
||||
.set(noteD)
|
||||
.set(noteE)
|
||||
.set(noteF)
|
||||
.set(noteG)
|
||||
.set(noteH)
|
||||
.set(noteI);
|
||||
|
||||
expect(ws.resolveLink(noteA, noteA.links[0])).toEqual(noteB.uri);
|
||||
expect(ws.resolveLink(noteA, noteA.links[1])).toEqual(noteC.uri);
|
||||
expect(ws.resolveLink(noteA, noteA.links[2])).toEqual(noteD.uri);
|
||||
expect(ws.resolveLink(noteA, noteA.links[3])).toEqual(noteE.uri);
|
||||
expect(ws.resolveLink(noteA, noteA.links[4])).toEqual(noteF.uri);
|
||||
expect(ws.resolveLink(noteA, noteA.links[5])).toEqual(noteG.uri);
|
||||
expect(ws.resolveLink(noteA, noteA.links[6])).toEqual(noteH.uri);
|
||||
expect(ws.resolveLink(noteA, noteA.links[7])).toEqual(noteI.uri);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Markdown direct links', () => {
|
||||
@@ -311,9 +370,78 @@ describe('Generation of markdown references', () => {
|
||||
.set(createNoteFromMarkdown('Content of note C', '/dir3/page-c.md'));
|
||||
|
||||
const references = createMarkdownReferences(workspace, noteA.uri, true);
|
||||
expect(references.map(r => r.url)).toEqual([
|
||||
expect(references.map(r => decodeURIComponent(r.url))).toEqual([
|
||||
'../dir2/page-b.md',
|
||||
'../dir3/page-c.md',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should generate links for embedded notes that are formatted properly', () => {
|
||||
const workspace = createTestWorkspace();
|
||||
const noteA = createNoteFromMarkdown(
|
||||
'Link to ![[page-b]] and [[page-c]]',
|
||||
'/dir1/page-a.md'
|
||||
);
|
||||
workspace
|
||||
.set(noteA)
|
||||
.set(createNoteFromMarkdown('Content of note B', '/dir2/page-b.md'))
|
||||
.set(createNoteFromMarkdown('Content of note C', '/dir3/page-c.md'));
|
||||
|
||||
const references = createMarkdownReferences(workspace, noteA.uri, true);
|
||||
expect(references.map(r => [decodeURIComponent(r.url), r.label])).toEqual([
|
||||
['../dir2/page-b.md', 'page-b'],
|
||||
['../dir3/page-c.md', 'page-c'],
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not generate links for placeholders', () => {
|
||||
const workspace = createTestWorkspace();
|
||||
const noteA = createNoteFromMarkdown(
|
||||
'Link to ![[page-b]] and [[page-c]] and [[does-not-exist]] and ![[does-not-exist-either]]',
|
||||
'/dir1/page-a.md'
|
||||
);
|
||||
workspace
|
||||
.set(noteA)
|
||||
.set(createNoteFromMarkdown('Content of note B', '/dir2/page-b.md'))
|
||||
.set(createNoteFromMarkdown('Content of note C', '/dir3/page-c.md'));
|
||||
|
||||
const references = createMarkdownReferences(workspace, noteA.uri, true);
|
||||
expect(references.map(r => decodeURIComponent(r.url))).toEqual([
|
||||
'../dir2/page-b.md',
|
||||
'../dir3/page-c.md',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should encode special characters in links', () => {
|
||||
const workspace = createTestWorkspace();
|
||||
const noteA = createNoteFromMarkdown(
|
||||
`Link to [[page: a]] and [[page %b%]] and [[page? c]] and [[[page] d]] and
|
||||
[[page ^e^]] and [[page \`f\`]] and [[page {g}]] and [[page ~i]] and
|
||||
[[page /j]]`
|
||||
);
|
||||
workspace
|
||||
.set(noteA)
|
||||
.set(createNoteFromMarkdown('Note containing :', '/dir1/page: a.md'))
|
||||
.set(createNoteFromMarkdown('Note containing %', '/dir1/page %b%.md'))
|
||||
.set(createNoteFromMarkdown('Note containing ?', '/dir1/page? c.md'))
|
||||
.set(createNoteFromMarkdown('Note containing ]', '/dir1/[page] d.md'))
|
||||
.set(createNoteFromMarkdown('Note containing ^', '/dir1/page ^e^.md'))
|
||||
.set(createNoteFromMarkdown('Note containing `', '/dir1/page `f`.md'))
|
||||
.set(
|
||||
createNoteFromMarkdown('Note containing { and }', '/dir1/page {g}.md')
|
||||
)
|
||||
.set(createNoteFromMarkdown('Note containing ~', '/dir1/page ~i.md'));
|
||||
|
||||
const references = createMarkdownReferences(workspace, noteA.uri, true);
|
||||
expect(references.map(r => decodeURIComponent(r.url))).toEqual([
|
||||
'../dir1/page: a.md',
|
||||
'../dir1/page %b%.md',
|
||||
'../dir1/page? c.md',
|
||||
'../dir1/[page] d.md',
|
||||
'../dir1/page ^e^.md',
|
||||
'../dir1/page `f`.md',
|
||||
'../dir1/page {g}.md',
|
||||
'../dir1/page ~i.md',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,17 +12,19 @@ import { IDisposable } from '../common/lifecycle';
|
||||
import { ResourceProvider } from '../model/provider';
|
||||
import { MarkdownLink } from './markdown-link';
|
||||
import { IDataStore } from './datastore';
|
||||
import { uniqBy } from 'lodash';
|
||||
|
||||
export class MarkdownResourceProvider implements ResourceProvider {
|
||||
private disposables: IDisposable[] = [];
|
||||
|
||||
constructor(
|
||||
private readonly dataStore: IDataStore,
|
||||
private readonly parser: ResourceParser
|
||||
private readonly parser: ResourceParser,
|
||||
public readonly noteExtensions: string[] = ['.md']
|
||||
) {}
|
||||
|
||||
supports(uri: URI) {
|
||||
return uri.isMarkdown();
|
||||
return this.noteExtensions.includes(uri.getExtension());
|
||||
}
|
||||
|
||||
async readAsMarkdown(uri: URI): Promise<string | null> {
|
||||
@@ -74,7 +76,7 @@ export class MarkdownResourceProvider implements ResourceProvider {
|
||||
URI.placeholder(target);
|
||||
|
||||
if (section) {
|
||||
targetUri = targetUri.withFragment(section);
|
||||
targetUri = targetUri.with({ fragment: section });
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -91,7 +93,7 @@ export class MarkdownResourceProvider implements ResourceProvider {
|
||||
workspace.find(path, resource.uri)?.uri ??
|
||||
URI.placeholder(resource.uri.resolve(path).path);
|
||||
if (section && !targetUri.isPlaceholder()) {
|
||||
targetUri = targetUri.withFragment(section);
|
||||
targetUri = targetUri.with({ fragment: section });
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -106,27 +108,19 @@ export class MarkdownResourceProvider implements ResourceProvider {
|
||||
|
||||
export function createMarkdownReferences(
|
||||
workspace: FoamWorkspace,
|
||||
noteUri: URI,
|
||||
source: Resource | URI,
|
||||
includeExtension: boolean
|
||||
): NoteLinkDefinition[] {
|
||||
const source = workspace.find(noteUri);
|
||||
// Should never occur since we're already in a file,
|
||||
if (source?.type !== 'note') {
|
||||
console.warn(
|
||||
`Note ${noteUri.toString()} note found in workspace when attempting \
|
||||
to generate markdown reference list`
|
||||
);
|
||||
return [];
|
||||
}
|
||||
const resource = source instanceof URI ? workspace.find(source) : source;
|
||||
|
||||
return source.links
|
||||
const definitions = resource.links
|
||||
.filter(link => link.type === 'wikilink')
|
||||
.map(link => {
|
||||
const targetUri = workspace.resolveLink(source, link);
|
||||
const targetUri = workspace.resolveLink(resource, link);
|
||||
const target = workspace.find(targetUri);
|
||||
if (isNone(target)) {
|
||||
Logger.warn(
|
||||
`Link ${targetUri.toString()} in ${noteUri.toString()} is not valid.`
|
||||
`Link ${targetUri.toString()} in ${resource.uri.toString()} is not valid.`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
@@ -135,34 +129,33 @@ to generate markdown reference list`
|
||||
return null;
|
||||
}
|
||||
|
||||
let relativeUri = target.uri.relativeTo(noteUri.getDirectory());
|
||||
if (!includeExtension && relativeUri.path.endsWith('.md')) {
|
||||
let relativeUri = target.uri.relativeTo(resource.uri.getDirectory());
|
||||
if (
|
||||
!includeExtension &&
|
||||
relativeUri.path.endsWith(workspace.defaultExtension)
|
||||
) {
|
||||
relativeUri = relativeUri.changeExtension('*', '');
|
||||
}
|
||||
|
||||
// Extract base path and link name separately.
|
||||
const basePath = relativeUri.path.split('/').slice(0, -1).join('/');
|
||||
const linkName = relativeUri.path.split('/').pop();
|
||||
|
||||
const encodedURL = encodeURIComponent(linkName).replace(/%20/g, ' ');
|
||||
|
||||
// [wikilink-text]: path/to/file.md "Page title"
|
||||
return {
|
||||
label:
|
||||
link.rawText.indexOf('[[') > -1
|
||||
? link.rawText.substring(2, link.rawText.length - 2)
|
||||
: link.rawText,
|
||||
url: relativeUri.path,
|
||||
// embedded looks like ![[note-a]]
|
||||
// regular note looks like [[note-a]]
|
||||
label: link.rawText.substring(
|
||||
link.isEmbed ? 3 : 2,
|
||||
link.rawText.length - 2
|
||||
),
|
||||
url: `${basePath ? basePath + '/' : ''}${encodedURL}`,
|
||||
title: target.title,
|
||||
};
|
||||
})
|
||||
.filter(isSome)
|
||||
.sort();
|
||||
}
|
||||
|
||||
export function stringifyMarkdownLinkReferenceDefinition(
|
||||
definition: NoteLinkDefinition
|
||||
) {
|
||||
const url =
|
||||
definition.url.indexOf(' ') > 0 ? `<${definition.url}>` : definition.url;
|
||||
let text = `[${definition.label}]: ${url}`;
|
||||
if (definition.title) {
|
||||
text = `${text} "${definition.title}"`;
|
||||
}
|
||||
|
||||
return text;
|
||||
return uniqBy(definitions, def => NoteLinkDefinition.format(def));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,22 @@ Logger.setLevel('error');
|
||||
|
||||
describe('Resource Filter', () => {
|
||||
describe('Filter parameters', () => {
|
||||
it('should support the path regex', () => {
|
||||
const noteA = createTestNote({
|
||||
uri: '/path/to/foo.md',
|
||||
type: 'type-1',
|
||||
});
|
||||
const noteB = createTestNote({
|
||||
uri: 'note-b.md',
|
||||
type: '/path/to/bar.md',
|
||||
});
|
||||
|
||||
const filter = createFilter({ path: 'foo' }, false);
|
||||
|
||||
expect(filter(noteA)).toBeTruthy();
|
||||
expect(filter(noteB)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should support expressions when code execution is enabled', () => {
|
||||
const noteA = createTestNote({
|
||||
uri: 'note-a.md',
|
||||
|
||||
@@ -53,6 +53,9 @@ export function createFilter(
|
||||
if (expressionFn && !expressionFn(resource)) {
|
||||
return false;
|
||||
}
|
||||
if (filter.path && !resource.uri.path.match(filter.path)) {
|
||||
return false;
|
||||
}
|
||||
if (filter.type && resource.type !== filter.type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,24 +1,85 @@
|
||||
import crypto from 'crypto';
|
||||
import sha1 from 'js-sha1';
|
||||
|
||||
/**
|
||||
* Checks if a value is not null.
|
||||
*
|
||||
* @param value - The value to check.
|
||||
* @returns True if the value is not null, otherwise false.
|
||||
*/
|
||||
export function isNotNull<T>(value: T | null): value is T {
|
||||
return value != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a value is not null, undefined, or void.
|
||||
*
|
||||
* @param value - The value to check.
|
||||
* @returns True if the value is not null, undefined, or void, otherwise false.
|
||||
*/
|
||||
export function isSome<T>(
|
||||
value: T | null | undefined | void
|
||||
): value is NonNullable<T> {
|
||||
return value != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a value is null, undefined, or void.
|
||||
*
|
||||
* @param value - The value to check.
|
||||
* @returns True if the value is null, undefined, or void, otherwise false.
|
||||
*/
|
||||
export function isNone<T>(
|
||||
value: T | null | undefined | void
|
||||
): value is null | undefined | void {
|
||||
return value == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a string is numeric.
|
||||
*
|
||||
* @param value - The string to check.
|
||||
* @returns True if the string is numeric, otherwise false.
|
||||
*/
|
||||
export function isNumeric(value: string): boolean {
|
||||
return /-?\d+$/.test(value);
|
||||
}
|
||||
|
||||
export const hash = (text: string) =>
|
||||
crypto.createHash('sha1').update(text).digest('hex');
|
||||
/**
|
||||
* Generates a SHA-1 hash of the given text.
|
||||
*
|
||||
* @param text - The text to hash.
|
||||
* @returns The SHA-1 hash of the text.
|
||||
*/
|
||||
export const hash = (text: string) => sha1.sha1(text);
|
||||
|
||||
/**
|
||||
* Executes an array of functions and returns the first result that satisfies the predicate.
|
||||
*
|
||||
* @param functions - The array of functions to execute.
|
||||
* @param predicate - The predicate to test the results. Defaults to checking if the result is not null.
|
||||
* @returns The first result that satisfies the predicate, or undefined if no result satisfies the predicate.
|
||||
*/
|
||||
export async function firstFrom<T>(
|
||||
functions: Array<() => T | Promise<T>>,
|
||||
predicate: (result: T) => boolean = result => result != null
|
||||
): Promise<T | undefined> {
|
||||
for (const fn of functions) {
|
||||
const result = await fn();
|
||||
if (predicate(result)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazily executes an array of functions and yields their results.
|
||||
*
|
||||
* @param functions - The array of functions to execute.
|
||||
* @returns A generator yielding the results of the functions.
|
||||
*/
|
||||
function* lazyExecutor<T>(functions: Array<() => T>): Generator<T> {
|
||||
for (const fn of functions) {
|
||||
yield fn();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,3 +89,25 @@ export class Logger {
|
||||
Logger.defaultLogger = logger;
|
||||
}
|
||||
}
|
||||
|
||||
export const withTiming = <T>(
|
||||
fn: () => T,
|
||||
onDidComplete: (elapsed: number) => void
|
||||
): T => {
|
||||
const tsStart = Date.now();
|
||||
const res = fn();
|
||||
const tsEnd = Date.now();
|
||||
onDidComplete(tsEnd - tsStart);
|
||||
return res;
|
||||
};
|
||||
|
||||
export const withTimingAsync = async <T>(
|
||||
fn: () => Promise<T>,
|
||||
onDidComplete: (elapsed: number) => void
|
||||
): Promise<T> => {
|
||||
const tsStart = Date.now();
|
||||
const res = await fn();
|
||||
const tsEnd = Date.now();
|
||||
onDidComplete(tsEnd - tsStart);
|
||||
return res;
|
||||
};
|
||||
|
||||
70
packages/foam-vscode/src/core/utils/md.test.ts
Normal file
70
packages/foam-vscode/src/core/utils/md.test.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import { isInFrontMatter, isOnYAMLKeywordLine } from './md';
|
||||
|
||||
describe('isInFrontMatter', () => {
|
||||
it('is true for started front matter', () => {
|
||||
const content = `---
|
||||
|
||||
`;
|
||||
const actual = isInFrontMatter(content, 1);
|
||||
expect(actual).toBeTruthy();
|
||||
});
|
||||
it('is true for inside completed front matter', () => {
|
||||
const content = '---\ntitle: A title\n---\n';
|
||||
const actual = isInFrontMatter(content, 1);
|
||||
expect(actual).toBeTruthy();
|
||||
});
|
||||
it('is true for inside completed front matter with "..." end delimiter', () => {
|
||||
const content = '---\ntitle: A title\n...\n';
|
||||
const actual = isInFrontMatter(content, 1);
|
||||
expect(actual).toBeTruthy();
|
||||
});
|
||||
it('is false for non valid front matter delimiter #1347', () => {
|
||||
const content = '---\ntitle: A title\n-..\n\n\n---\ntest\n';
|
||||
expect(isInFrontMatter(content, 1)).toBeTruthy();
|
||||
expect(isInFrontMatter(content, 4)).toBeTruthy();
|
||||
expect(isInFrontMatter(content, 6)).toBeFalsy();
|
||||
});
|
||||
it('is false for outside completed front matter', () => {
|
||||
const content = '---\ntitle: A title\n---\ncontent\nmore content\n';
|
||||
const actual = isInFrontMatter(content, 3);
|
||||
expect(actual).toBeFalsy();
|
||||
});
|
||||
it('is false for outside completed front matter with "..." end delimiter', () => {
|
||||
const content = '---\ntitle: A title\n...\ncontent\nmore content\n';
|
||||
const actual = isInFrontMatter(content, 3);
|
||||
expect(actual).toBeFalsy();
|
||||
});
|
||||
it('is false for position on initial front matter delimiter', () => {
|
||||
const content = '---\ntitle: A title\n---\ncontent\nmore content\n';
|
||||
const actual = isInFrontMatter(content, 0);
|
||||
expect(actual).toBeFalsy();
|
||||
});
|
||||
it('is false for position on final front matter delimiter', () => {
|
||||
const content = '---\ntitle: A title\n---\ncontent\nmore content\n';
|
||||
const actual = isInFrontMatter(content, 2);
|
||||
expect(actual).toBeFalsy();
|
||||
});
|
||||
|
||||
describe('isOnYAMLKeywordLine', () => {
|
||||
it('is true if line starts with keyword', () => {
|
||||
const content = 'tags: foo, bar\n';
|
||||
const actual = isOnYAMLKeywordLine(content, 'tags');
|
||||
expect(actual).toBeTruthy();
|
||||
});
|
||||
it('is true if previous line starts with keyword', () => {
|
||||
const content = 'tags: foo\n - bar\n';
|
||||
const actual = isOnYAMLKeywordLine(content, 'tags');
|
||||
expect(actual).toBeTruthy();
|
||||
});
|
||||
it('is false if line starts with wrong keyword', () => {
|
||||
const content = 'tags: foo, bar\n';
|
||||
const actual = isOnYAMLKeywordLine(content, 'title');
|
||||
expect(actual).toBeFalsy();
|
||||
});
|
||||
it('is false if previous line starts with wrong keyword', () => {
|
||||
const content = 'dates:\n - 2023-01-1\n - 2023-01-02\n';
|
||||
const actual = isOnYAMLKeywordLine(content, 'tags');
|
||||
expect(actual).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
70
packages/foam-vscode/src/core/utils/md.ts
Normal file
70
packages/foam-vscode/src/core/utils/md.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import matter from 'gray-matter';
|
||||
|
||||
export function getExcerpt(
|
||||
markdown: string,
|
||||
maxLines: number
|
||||
): { excerpt: string; lines: number } {
|
||||
const OFFSET_LINES_LIMIT = 5;
|
||||
const paragraphs = markdown.replace(/\r\n/g, '\n').split('\n\n');
|
||||
const excerpt: string[] = [];
|
||||
let lines = 0;
|
||||
for (const paragraph of paragraphs) {
|
||||
const n = paragraph.split('\n').length;
|
||||
if (lines > maxLines || lines + n - maxLines > OFFSET_LINES_LIMIT) {
|
||||
break;
|
||||
}
|
||||
excerpt.push(paragraph);
|
||||
lines = lines + n + 1;
|
||||
}
|
||||
return { excerpt: excerpt.join('\n\n'), lines };
|
||||
}
|
||||
|
||||
export function stripFrontMatter(markdown: string): string {
|
||||
return matter(markdown).content.trim();
|
||||
}
|
||||
|
||||
export function stripImages(markdown: string): string {
|
||||
return markdown.replace(
|
||||
/!\[(.*)\]\([-/\\.A-Za-z]*\)/gi,
|
||||
'$1'.length ? '[Image: $1]' : ''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the given line is inside a front matter block
|
||||
* @param content the string to check
|
||||
* @param lineNumber the line number within the string, 0-based
|
||||
* @returns true if the line is inside a frontmatter block in content
|
||||
*/
|
||||
export function isInFrontMatter(content: string, lineNumber: number): boolean {
|
||||
const FIRST_DELIMITER_MATCH = /^---\s*?$/m;
|
||||
const LAST_DELIMITER_MATCH = /^(-{3}|\.{3})/;
|
||||
|
||||
// if we're on the first line, we're not _yet_ in the front matter
|
||||
if (lineNumber === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// look for --- at start, and a second --- or ... to end
|
||||
if (content.match(FIRST_DELIMITER_MATCH) === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const lines = content.split('\n');
|
||||
lines.shift();
|
||||
const endLineNumber = lines.findIndex(l => l.match(LAST_DELIMITER_MATCH));
|
||||
|
||||
return endLineNumber === -1 || endLineNumber >= lineNumber;
|
||||
}
|
||||
|
||||
export function isOnYAMLKeywordLine(content: string, keyword: string): boolean {
|
||||
const keywordMatch = /^\s*(\w+):/gm;
|
||||
|
||||
if (content.match(keywordMatch) === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const matches = Array.from(content.matchAll(keywordMatch));
|
||||
const lastMatch = matches[matches.length - 1];
|
||||
return lastMatch[1] === keyword;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { workspace } from 'vscode';
|
||||
import { createDailyNoteIfNotExists, getDailyNotePath } from './dated-notes';
|
||||
import { createDailyNoteIfNotExists, getDailyNoteUri } from './dated-notes';
|
||||
import { isWindows } from './core/common/platform';
|
||||
import {
|
||||
cleanWorkspace,
|
||||
@@ -10,8 +10,9 @@ import {
|
||||
withModifiedFoamConfiguration,
|
||||
} from './test/test-utils-vscode';
|
||||
import { fromVsCodeUri } from './utils/vsc-utils';
|
||||
import { URI } from './core/model/uri';
|
||||
|
||||
describe('getDailyNotePath', () => {
|
||||
describe('getDailyNoteUri', () => {
|
||||
const date = new Date('2021-02-07T00:00:00Z');
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth() + 1;
|
||||
@@ -21,12 +22,12 @@ describe('getDailyNotePath', () => {
|
||||
test('Adds the root directory to relative directories', async () => {
|
||||
const config = 'journal';
|
||||
|
||||
const expectedPath = fromVsCodeUri(
|
||||
const expectedUri = fromVsCodeUri(
|
||||
workspace.workspaceFolders[0].uri
|
||||
).joinPath(config, `${isoDate}.md`);
|
||||
|
||||
await withModifiedFoamConfiguration('openDailyNote.directory', config, () =>
|
||||
expect(getDailyNotePath(date).toFsPath()).toEqual(expectedPath.toFsPath())
|
||||
expect(getDailyNoteUri(date)).toEqual(expectedUri)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -39,7 +40,7 @@ describe('getDailyNotePath', () => {
|
||||
: `${config}/${isoDate}.md`;
|
||||
|
||||
await withModifiedFoamConfiguration('openDailyNote.directory', config, () =>
|
||||
expect(getDailyNotePath(date).toFsPath()).toMatch(expectedPath)
|
||||
expect(getDailyNoteUri(date).toFsPath()).toMatch(expectedPath)
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -54,7 +55,7 @@ describe('Daily note template', () => {
|
||||
['.foam', 'templates', 'daily-note.md']
|
||||
);
|
||||
|
||||
const uri = getDailyNotePath(targetDate);
|
||||
const uri = getDailyNoteUri(targetDate);
|
||||
|
||||
await createDailyNoteIfNotExists(targetDate);
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { workspace } from 'vscode';
|
||||
import { joinPath } from './core/utils/path';
|
||||
import dateFormat from 'dateformat';
|
||||
import { focusNote } from './utils';
|
||||
import { URI } from './core/model/uri';
|
||||
import { toVsCodeUri } from './utils/vsc-utils';
|
||||
import { NoteFactory } from './services/templates';
|
||||
import { getFoamVsCodeConfig } from './services/config';
|
||||
import { asAbsoluteWorkspaceUri } from './services/editor';
|
||||
import { asAbsoluteWorkspaceUri, focusNote } from './services/editor';
|
||||
|
||||
/**
|
||||
* Open the daily note file.
|
||||
@@ -35,17 +33,13 @@ export async function openDailyNoteFor(date?: Date) {
|
||||
* 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 date A given date to be formatted as filename.
|
||||
* @returns The path to the daily note file.
|
||||
* @returns The URI to the daily note file.
|
||||
*/
|
||||
export function getDailyNotePath(date: Date): URI {
|
||||
export function getDailyNoteUri(date: Date): URI {
|
||||
const folder = getFoamVsCodeConfig<string>('openDailyNote.directory') ?? '.';
|
||||
const dailyNoteDirectory = asAbsoluteWorkspaceUri(URI.file(folder));
|
||||
const dailyNoteFilename = getDailyNoteFileName(date);
|
||||
return dailyNoteDirectory.joinPath(dailyNoteFilename);
|
||||
return asAbsoluteWorkspaceUri(joinPath(folder, dailyNoteFilename));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,23 +70,23 @@ export function getDailyNoteFileName(date: Date): string {
|
||||
* this function will create all folders in the path.
|
||||
*
|
||||
* @param currentDate The current date, to be used as a title.
|
||||
* @returns Wether the file was created.
|
||||
* @returns Whether the file was created.
|
||||
*/
|
||||
export async function createDailyNoteIfNotExists(targetDate: Date) {
|
||||
const pathFromLegacyConfiguration = getDailyNotePath(targetDate);
|
||||
const uriFromLegacyConfiguration = getDailyNoteUri(targetDate);
|
||||
const pathFromLegacyConfiguration = uriFromLegacyConfiguration.toFsPath();
|
||||
const titleFormat: string =
|
||||
getFoamVsCodeConfig('openDailyNote.titleFormat') ??
|
||||
getFoamVsCodeConfig('openDailyNote.filenameFormat');
|
||||
|
||||
const templateFallbackText = `---
|
||||
foam_template:
|
||||
filepath: "${pathFromLegacyConfiguration.toFsPath().replace(/\\/g, '\\\\')}"
|
||||
---
|
||||
# ${dateFormat(targetDate, titleFormat, false)}
|
||||
`;
|
||||
const templateFallbackText = `# ${dateFormat(
|
||||
targetDate,
|
||||
titleFormat,
|
||||
false
|
||||
)}\n`;
|
||||
|
||||
return await NoteFactory.createFromDailyNoteTemplate(
|
||||
pathFromLegacyConfiguration,
|
||||
uriFromLegacyConfiguration,
|
||||
templateFallbackText,
|
||||
targetDate
|
||||
);
|
||||
|
||||
@@ -7,7 +7,11 @@ import { Logger } from './core/utils/log';
|
||||
|
||||
import { features } from './features';
|
||||
import { VsCodeOutputLogger, exposeLogger } from './services/logging';
|
||||
import { getIgnoredFilesSetting } from './settings';
|
||||
import {
|
||||
getAttachmentsExtensions,
|
||||
getIgnoredFilesSetting,
|
||||
getNotesExtensions,
|
||||
} from './settings';
|
||||
import { AttachmentResourceProvider } from './core/services/attachment-provider';
|
||||
import { VsCodeWatcher } from './services/watcher';
|
||||
import { createMarkdownParser } from './core/services/markdown-parser';
|
||||
@@ -45,16 +49,32 @@ export async function activate(context: ExtensionContext) {
|
||||
const parserCache = new VsCodeBasedParserCache(context);
|
||||
const parser = createMarkdownParser([], parserCache);
|
||||
|
||||
const markdownProvider = new MarkdownResourceProvider(dataStore, parser);
|
||||
const attachmentProvider = new AttachmentResourceProvider();
|
||||
const { notesExtensions, defaultExtension } = getNotesExtensions();
|
||||
|
||||
const foamPromise = bootstrap(matcher, watcher, dataStore, parser, [
|
||||
markdownProvider,
|
||||
attachmentProvider,
|
||||
]);
|
||||
const markdownProvider = new MarkdownResourceProvider(
|
||||
dataStore,
|
||||
parser,
|
||||
notesExtensions
|
||||
);
|
||||
|
||||
const attachmentExtConfig = getAttachmentsExtensions();
|
||||
const attachmentProvider = new AttachmentResourceProvider(
|
||||
attachmentExtConfig
|
||||
);
|
||||
|
||||
const foamPromise = bootstrap(
|
||||
matcher,
|
||||
watcher,
|
||||
dataStore,
|
||||
parser,
|
||||
[markdownProvider, attachmentProvider],
|
||||
defaultExtension
|
||||
);
|
||||
|
||||
// Load the features
|
||||
const resPromises = features.map(f => f.activate(context, foamPromise));
|
||||
const featuresPromises = features.map(feature =>
|
||||
feature(context, foamPromise)
|
||||
);
|
||||
|
||||
const foam = await foamPromise;
|
||||
Logger.info(`Loaded ${foam.workspace.list().length} resources`);
|
||||
@@ -66,17 +86,32 @@ export async function activate(context: ExtensionContext) {
|
||||
attachmentProvider,
|
||||
commands.registerCommand('foam-vscode.clear-cache', () =>
|
||||
parserCache.clear()
|
||||
)
|
||||
),
|
||||
workspace.onDidChangeConfiguration(e => {
|
||||
if (
|
||||
[
|
||||
'foam.files.ignore',
|
||||
'foam.files.attachmentExtensions',
|
||||
'foam.files.noteExtensions',
|
||||
'foam.files.defaultNoteExtension',
|
||||
].some(setting => e.affectsConfiguration(setting))
|
||||
) {
|
||||
window.showInformationMessage(
|
||||
'Foam: Reload the window to use the updated settings'
|
||||
);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
const res = (await Promise.all(resPromises)).filter(r => r != null);
|
||||
const feats = (await Promise.all(featuresPromises)).filter(r => r != null);
|
||||
|
||||
return {
|
||||
extendMarkdownIt: (md: markdownit) => {
|
||||
return res.reduce((acc: markdownit, r: any) => {
|
||||
return feats.reduce((acc: markdownit, r: any) => {
|
||||
return r.extendMarkdownIt ? r.extendMarkdownIt(acc) : acc;
|
||||
}, md);
|
||||
},
|
||||
foam,
|
||||
};
|
||||
} catch (e) {
|
||||
Logger.error('An error occurred while bootstrapping Foam', e);
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
import { commands, ExtensionContext, window, workspace, Uri } from 'vscode';
|
||||
import { Foam } from '../../core/model/foam';
|
||||
import { FoamWorkspace } from '../../core/model/workspace';
|
||||
import { fromVsCodeUri, toVsCodeRange } from '../../utils/vsc-utils';
|
||||
import { ResourceParser } from '../../core/model/note';
|
||||
import { IMatcher } from '../../core/services/datastore';
|
||||
import { convertLinkFormat } from '../../core/janitor';
|
||||
import { isMdEditor } from '../../services/editor';
|
||||
|
||||
type LinkFormat = 'wikilink' | 'link';
|
||||
|
||||
enum ConvertOption {
|
||||
Wikilink2MDlink,
|
||||
MDlink2Wikilink,
|
||||
}
|
||||
|
||||
interface IConfig {
|
||||
from: string;
|
||||
to: string;
|
||||
}
|
||||
|
||||
const Config: { [key in ConvertOption]: IConfig } = {
|
||||
[ConvertOption.Wikilink2MDlink]: {
|
||||
from: 'wikilink',
|
||||
to: 'link',
|
||||
},
|
||||
[ConvertOption.MDlink2Wikilink]: {
|
||||
from: 'link',
|
||||
to: 'wikilink',
|
||||
},
|
||||
};
|
||||
|
||||
export default async function activate(
|
||||
context: ExtensionContext,
|
||||
foamPromise: Promise<Foam>
|
||||
) {
|
||||
const foam = await foamPromise;
|
||||
|
||||
/*
|
||||
commands:
|
||||
foam-vscode.convert-link-style-inplace
|
||||
foam-vscode.convert-link-style-incopy
|
||||
*/
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand('foam-vscode.convert-link-style-inplace', () => {
|
||||
return convertLinkAdapter(
|
||||
foam.workspace,
|
||||
foam.services.parser,
|
||||
foam.services.matcher,
|
||||
true
|
||||
);
|
||||
}),
|
||||
commands.registerCommand('foam-vscode.convert-link-style-incopy', () => {
|
||||
return convertLinkAdapter(
|
||||
foam.workspace,
|
||||
foam.services.parser,
|
||||
foam.services.matcher,
|
||||
false
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
async function convertLinkAdapter(
|
||||
fWorkspace: FoamWorkspace,
|
||||
fParser: ResourceParser,
|
||||
fMatcher: IMatcher,
|
||||
isInPlace: boolean
|
||||
) {
|
||||
const convertOption = await pickConvertStrategy();
|
||||
if (!convertOption) {
|
||||
window.showInformationMessage('Convert canceled');
|
||||
return;
|
||||
}
|
||||
|
||||
if (isInPlace) {
|
||||
await convertLinkInPlace(fWorkspace, fParser, fMatcher, convertOption);
|
||||
} else {
|
||||
await convertLinkInCopy(fWorkspace, fParser, fMatcher, convertOption);
|
||||
}
|
||||
}
|
||||
|
||||
async function pickConvertStrategy(): Promise<IConfig | undefined> {
|
||||
const options = {
|
||||
'to wikilink': ConvertOption.MDlink2Wikilink,
|
||||
'to markdown link': ConvertOption.Wikilink2MDlink,
|
||||
};
|
||||
return window.showQuickPick(Object.keys(options)).then(name => {
|
||||
if (name) {
|
||||
return Config[options[name]];
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* convert links based on its workspace and the note containing it.
|
||||
* Changes happen in-place
|
||||
* @param fWorkspace
|
||||
* @param fParser
|
||||
* @param fMatcher
|
||||
* @param convertOption
|
||||
* @returns void
|
||||
*/
|
||||
async function convertLinkInPlace(
|
||||
fWorkspace: FoamWorkspace,
|
||||
fParser: ResourceParser,
|
||||
fMatcher: IMatcher,
|
||||
convertOption: IConfig
|
||||
) {
|
||||
const editor = window.activeTextEditor;
|
||||
const doc = editor.document;
|
||||
|
||||
if (!isMdEditor(editor) || !fMatcher.isMatch(fromVsCodeUri(doc.uri))) {
|
||||
return;
|
||||
}
|
||||
// const eol = getEditorEOL();
|
||||
let text = doc.getText();
|
||||
|
||||
const resource = fParser.parse(fromVsCodeUri(doc.uri), text);
|
||||
|
||||
const textReplaceArr = resource.links
|
||||
.filter(link => link.type === convertOption.from)
|
||||
.map(link =>
|
||||
convertLinkFormat(
|
||||
link,
|
||||
convertOption.to as LinkFormat,
|
||||
fWorkspace,
|
||||
resource
|
||||
)
|
||||
)
|
||||
/* transform .range property into vscode range */
|
||||
.map(linkReplace => ({
|
||||
...linkReplace,
|
||||
range: toVsCodeRange(linkReplace.range),
|
||||
}));
|
||||
|
||||
/* reorder the array such that the later range comes first */
|
||||
textReplaceArr.sort((a, b) => b.range.start.compareTo(a.range.start));
|
||||
|
||||
await editor.edit(editorBuilder => {
|
||||
textReplaceArr.forEach(edit => {
|
||||
editorBuilder.replace(edit.range, edit.newText);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* convert links based on its workspace and the note containing it.
|
||||
* Changes happen in a copy
|
||||
* 1. prepare a copy file, and makt it the activeTextEditor
|
||||
* 2. call to convertLinkInPlace
|
||||
* @param fWorkspace
|
||||
* @param fParser
|
||||
* @param fMatcher
|
||||
* @param convertOption
|
||||
* @returns void
|
||||
*/
|
||||
async function convertLinkInCopy(
|
||||
fWorkspace: FoamWorkspace,
|
||||
fParser: ResourceParser,
|
||||
fMatcher: IMatcher,
|
||||
convertOption: IConfig
|
||||
) {
|
||||
const editor = window.activeTextEditor;
|
||||
const doc = editor.document;
|
||||
|
||||
if (!isMdEditor(editor) || !fMatcher.isMatch(fromVsCodeUri(doc.uri))) {
|
||||
return;
|
||||
}
|
||||
// const eol = getEditorEOL();
|
||||
let text = doc.getText();
|
||||
|
||||
const resource = fParser.parse(fromVsCodeUri(doc.uri), text);
|
||||
const basePath = doc.uri.path.split('/').slice(0, -1).join('/');
|
||||
|
||||
const fileUri = doc.uri.with({
|
||||
path: `${
|
||||
basePath ? basePath + '/' : ''
|
||||
}${resource.uri.getName()}.copy${resource.uri.getExtension()}`,
|
||||
});
|
||||
const encoder = new TextEncoder();
|
||||
await workspace.fs.writeFile(fileUri, encoder.encode(text));
|
||||
await window.showTextDocument(fileUri);
|
||||
|
||||
await convertLinkInPlace(fWorkspace, fParser, fMatcher, convertOption);
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
import { env, Position, Selection, commands } from 'vscode';
|
||||
import { createFile, showInEditor } from '../../test/test-utils-vscode';
|
||||
import { removeBrackets, toTitleCase } from './copy-without-brackets';
|
||||
|
||||
describe('copy-without-brackets command', () => {
|
||||
it('should get the input from the active editor selection', async () => {
|
||||
const { uri } = await createFile('This is my [[test-content]].');
|
||||
const { uri } = await createFile('This is my [[test-content]].', [
|
||||
'copy-without-brackets',
|
||||
'file.md',
|
||||
]);
|
||||
const { editor } = await showInEditor(uri);
|
||||
editor.selection = new Selection(new Position(0, 0), new Position(1, 0));
|
||||
await commands.executeCommand('foam-vscode.copy-without-brackets');
|
||||
@@ -11,3 +15,61 @@ describe('copy-without-brackets command', () => {
|
||||
expect(value).toEqual('This is my Test Content.');
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeBrackets', () => {
|
||||
it('removes the brackets', () => {
|
||||
const input = 'hello world [[this-is-it]]';
|
||||
const actual = removeBrackets(input);
|
||||
const expected = 'hello world This Is It';
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
it('removes the brackets and the md file extension', () => {
|
||||
const input = 'hello world [[this-is-it.md]]';
|
||||
const actual = removeBrackets(input);
|
||||
const expected = 'hello world This Is It';
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
it('removes the brackets and the mdx file extension', () => {
|
||||
const input = 'hello world [[this-is-it.mdx]]';
|
||||
const actual = removeBrackets(input);
|
||||
const expected = 'hello world This Is It';
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
it('removes the brackets and the markdown file extension', () => {
|
||||
const input = 'hello world [[this-is-it.markdown]]';
|
||||
const actual = removeBrackets(input);
|
||||
const expected = 'hello world This Is It';
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
it('removes the brackets even with numbers', () => {
|
||||
const input = 'hello world [[2020-07-21.markdown]]';
|
||||
const actual = removeBrackets(input);
|
||||
const expected = 'hello world 2020 07 21';
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
it('removes brackets for more than one word', () => {
|
||||
const input =
|
||||
'I am reading this as part of the [[book-club]] put on by [[egghead]] folks (Lauro).';
|
||||
const actual = removeBrackets(input);
|
||||
const expected =
|
||||
'I am reading this as part of the Book Club put on by Egghead folks (Lauro).';
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toTitleCase', () => {
|
||||
it('title cases a word', () => {
|
||||
const input =
|
||||
'look at this really long sentence but I am calling it a word';
|
||||
const actual = toTitleCase(input);
|
||||
const expected =
|
||||
'Look At This Really Long Sentence But I Am Calling It A Word';
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
it('works on one word', () => {
|
||||
const input = 'word';
|
||||
const actual = toTitleCase(input);
|
||||
const expected = 'Word';
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
import { window, env, ExtensionContext, commands } from 'vscode';
|
||||
import { FoamFeature } from '../../types';
|
||||
import { removeBrackets } from '../../utils';
|
||||
|
||||
const feature: FoamFeature = {
|
||||
activate: (context: ExtensionContext) => {
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand(
|
||||
'foam-vscode.copy-without-brackets',
|
||||
copyWithoutBrackets
|
||||
)
|
||||
);
|
||||
},
|
||||
};
|
||||
export default async function activate(context: ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand(
|
||||
'foam-vscode.copy-without-brackets',
|
||||
copyWithoutBrackets
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
async function copyWithoutBrackets() {
|
||||
// Get the active text editor
|
||||
@@ -35,4 +31,45 @@ async function copyWithoutBrackets() {
|
||||
}
|
||||
}
|
||||
|
||||
export default feature;
|
||||
/**
|
||||
* Used for the "Copy to Clipboard Without Brackets" command
|
||||
*
|
||||
*/
|
||||
export function removeBrackets(s: string): string {
|
||||
// take in the string, split on space
|
||||
const stringSplitBySpace = s.split(' ');
|
||||
|
||||
// loop through words
|
||||
const modifiedWords = stringSplitBySpace.map(currentWord => {
|
||||
if (currentWord.includes('[[')) {
|
||||
// all of these transformations will turn this "[[you-are-awesome]]"
|
||||
// to this "you are awesome"
|
||||
let word = currentWord.replace(/(\[\[)/g, '');
|
||||
word = word.replace(/(\]\])/g, '');
|
||||
word = word.replace(/(.mdx|.md|.markdown)/g, '');
|
||||
word = word.replace(/[-]/g, ' ');
|
||||
|
||||
// then we titlecase the word so "you are awesome"
|
||||
// becomes "You Are Awesome"
|
||||
const titleCasedWord = toTitleCase(word);
|
||||
|
||||
return titleCasedWord;
|
||||
}
|
||||
|
||||
return currentWord;
|
||||
});
|
||||
|
||||
return modifiedWords.join(' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes in a string and returns it titlecased
|
||||
*
|
||||
* @example toTitleCase("hello world") -> "Hello World"
|
||||
*/
|
||||
export function toTitleCase(word: string): string {
|
||||
return word
|
||||
.split(' ')
|
||||
.map(word => word[0].toUpperCase() + word.substring(1))
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import { commands, window } from 'vscode';
|
||||
import * as editor from '../../services/editor';
|
||||
|
||||
describe('create-note-from-default-template command', () => {
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('can be cancelled while resolving FOAM_TITLE', async () => {
|
||||
const spy = jest
|
||||
.spyOn(window, 'showInputBox')
|
||||
.mockImplementation(jest.fn(() => Promise.resolve(undefined)));
|
||||
|
||||
const docCreatorSpy = jest.spyOn(editor, 'createDocAndFocus');
|
||||
|
||||
await commands.executeCommand(
|
||||
'foam-vscode.create-note-from-default-template'
|
||||
);
|
||||
|
||||
expect(spy).toHaveBeenCalledWith({
|
||||
prompt: `Enter a title for the new note`,
|
||||
value: 'Title of my New Note',
|
||||
validateInput: expect.anything(),
|
||||
});
|
||||
|
||||
expect(docCreatorSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
@@ -1,16 +1,8 @@
|
||||
import { commands, ExtensionContext } from 'vscode';
|
||||
import { FoamFeature } from '../../types';
|
||||
import { createTemplate } from '../../services/templates';
|
||||
|
||||
const feature: FoamFeature = {
|
||||
activate: (context: ExtensionContext) => {
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand(
|
||||
'foam-vscode.create-new-template',
|
||||
createTemplate
|
||||
)
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export default feature;
|
||||
export default async function activate(context: ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand('foam-vscode.create-new-template', createTemplate)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import { commands, window } from 'vscode';
|
||||
import * as editor from '../../services/editor';
|
||||
|
||||
describe('create-note-from-default-template command', () => {
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('can be cancelled while resolving FOAM_TITLE', async () => {
|
||||
const spy = jest
|
||||
.spyOn(window, 'showInputBox')
|
||||
.mockImplementation(jest.fn(() => Promise.resolve(undefined)));
|
||||
|
||||
const docCreatorSpy = jest.spyOn(editor, 'createDocAndFocus');
|
||||
|
||||
await commands.executeCommand(
|
||||
'foam-vscode.create-note-from-default-template'
|
||||
);
|
||||
|
||||
expect(spy).toHaveBeenCalledWith({
|
||||
prompt: `Enter a title for the new note`,
|
||||
value: 'Title of my New Note',
|
||||
validateInput: expect.anything(),
|
||||
});
|
||||
|
||||
expect(docCreatorSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
@@ -1,42 +0,0 @@
|
||||
import { commands, window, ExtensionContext } from 'vscode';
|
||||
import { FoamFeature } from '../../types';
|
||||
import { getDefaultTemplateUri, NoteFactory } from '../../services/templates';
|
||||
import { Resolver } from '../../services/variable-resolver';
|
||||
|
||||
/**
|
||||
* Create a new note from the default template.
|
||||
*
|
||||
* @deprecated use 'foam-vscode.create-note' instead
|
||||
*/
|
||||
const feature: FoamFeature = {
|
||||
activate: (context: ExtensionContext) => {
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand(
|
||||
'foam-vscode.create-note-from-default-template',
|
||||
() => {
|
||||
window.showWarningMessage(
|
||||
"This command is deprecated, use 'Foam: Create Note' (foam-vscode.create-note) instead"
|
||||
);
|
||||
const resolver = new Resolver(new Map(), new Date());
|
||||
|
||||
return NoteFactory.createFromTemplate(
|
||||
getDefaultTemplateUri(),
|
||||
resolver,
|
||||
undefined,
|
||||
`---
|
||||
foam_template:
|
||||
name: New Note
|
||||
description: Foam's default new note template
|
||||
---
|
||||
# \${FOAM_TITLE}
|
||||
|
||||
\${FOAM_SELECTED_TEXT}
|
||||
`
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export default feature;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user