Skip to content

Commit

Permalink
Merge pull request #10 from JonasSchatz/quick-inserts
Browse files Browse the repository at this point in the history
Quick Inserts
  • Loading branch information
JonasSchatz authored Jan 17, 2021
2 parents 4536e7e + ae225c2 commit 40c67e8
Show file tree
Hide file tree
Showing 25 changed files with 140 additions and 75 deletions.
44 changes: 36 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Codekasten: Advanced Zettelkasten for VS Code

Codekasten provides tools and shortcuts to manage a _Zettelkasten_ in VS Code.
If you don't know what a Zettelkasten is, there are many resources on the web, but maybe start [here](http://evantravers.com/articles/2020/03/13/simple-markdown-zettelkasten/).
The Codekasten extensions provides tools and shortcuts to manage a _Zettelkasten_ in VS Code.
If you don't know what a Zettelkasten is, there are many resources on the web. [Here](http://evantravers.com/articles/2020/03/13/simple-markdown-zettelkasten/) is a good place to start.

> ⚠️ Warning: This extension is made to suite my personal workflow.
> ⚠️ Use at your own risk and always make sure to backup your notes.
## Recommended Extensions
To harness the full power of markdown documents in VS Code, [Markdown Preview Enhanced](https://marketplace.visualstudio.com/items?itemName=shd101wyy.markdown-preview-enhanced) is recommended.
For easy insertion of images, use [Paste Image](https://marketplace.visualstudio.com/items?itemName=mushan.vscode-paste-image). Note that this is not maintained anymore, but forks do exists.
For easy insertion of images, use [Paste Image](https://marketplace.visualstudio.com/items?itemName=mushan.vscode-paste-image). Note that this extension is not maintained anymore, but forks do exists.



## Features
Currently supported:
Expand All @@ -20,29 +22,55 @@ Currently supported:
- See the notes that link to the currently open node in the left sidebar
- See the notes that share tags with the currently open node, also in the left sidebar
- Graph visualization
- HTML snippets for features that are not supported in markdown (e.g. more control over tables)
- Consistency Checks: Find stubs and unlinked images

![](./docs/codekasten_overview.PNG)
![](./docs/codekasten_graphviz.PNG)

## Setup and Extension Settings
There are no changeable settings in VS Code.
When creating a new note, the extension expects a folder `.codekasten/templates`, containing templates as `.md` files.
When creating a new note, the extension expects a folder `.codekasten/templates`, containing templates as `.md` files.

#### Customizing Recommended Extensions
Unfortunately, basic markdown does not allow to apply styling to images. However, you can attach CSS Selectors to images URIs ([source](https://www.xaprb.com/blog/how-to-style-images-with-markdown/)). Markdown Preview Enhanced provides a custom CSS file that is applied to all your files. It can be edited by using `Ctrl + Shift + P` to run `Markdown Preview Enhanced: Customize CSS`.

For my personal workflow, I sometimes want to resize images. This can be done by writing the following markdown:
`![](path/to/image?width300`

And having the following CSS:
```
img[src*="?width300"] {
width:300px;
}
```

## Roadmap

Short-term:
- Clean up duplicate/messy code, write more docstrings and tests
- Cleanup Scripts: Find Stubs and unlinked images. Maybe find unlinked notes and make it a challenge to connect them to the bulk of knowledge.
- Add more information to the Graphviz
- Add more information to the Graphviz: Invisible connections based on tags

Mid-term:
- Make the extension more customizable, e.g. let the user provide glob-patterns for which files should be included in the graph visualization.
- Include a Template with the neccessary folder structure and some smart initial values for the settings into the Repo.
- Handle images: Right-click to change to HTML image tags with size.

Long-term:
- Implement or find a more robust Markdown Parser. Do own syntax highlighting (e.g. detected links), which might be cool and also help with debugging.

## Release Notes

## 0.1.1
Date: 2021-01-17
New Features:
- Scripts for consistency checks
- Quick insertion of HTML snippets and often used symbols
- Support for styling images and markdown-compatible HTML tables

Bugfixes:
- No more triple-hyphens when suggesting a filename (e.g. the suggested filename for `Author - Title` would have been `author---title.md`)
- Searching for tags is now case-insensitive
- When automatically replacing text in files, all occurences are replaced

## 0.1.0
Date: 2020-12-18
New Features:
Expand Down
Binary file added docs/codekasten_graphviz.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/codekasten_overview.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,9 @@
}, {
"command": "codekasten.perform-consistency-check",
"title": "Codekasten: Perform Consistency Check"
}
],
"snippets": [
{
"language": "markdown",
"path": "./static/snippets.json"
}, {
"command": "codekasten.insert-snippet",
"title": "Codekasten: Insert code/text snippets"
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions src/core/Parser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as path from 'path';

import { loadFileAsString } from "../vscode/NoteActions";
import { loadFileAsString } from "../vscode/note-actions";

import { MarkdownLink, Note } from "../core";
import { MarkdownLink, Note } from ".";


export interface Parser {
Expand Down
10 changes: 5 additions & 5 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Config } from "./Config";
import { Config } from "./config";
import { Logger } from "./Logger";
import { NoteGraph } from "./NoteGraph";
import { Link, MarkdownLink } from "./Link";
import { Note} from "./Note";
import { CodekastenParser } from "./Parser";
import { NoteGraph } from "./note-graph";
import { Link, MarkdownLink } from "./link";
import { Note} from "./note";
import { CodekastenParser } from "./parser";

export {
CodekastenParser,
Expand Down
4 changes: 2 additions & 2 deletions src/core/NoteGraph.ts → src/core/note-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as md5 from 'md5';
import { Uri } from 'vscode';

import { Event, Emitter } from './common/event';
import { Note, GraphNote } from './Note';
import { Parser } from './Parser';
import { Note, GraphNote } from './note';
import { Parser } from './parser';

export class NoteGraph {

Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as vscode from 'vscode';
import { CodekastenParser, NoteGraph, Logger } from "./core";
import { features } from "./features";
import { VscodeConfig, VscodeLogger } from "./vscode";
import { FilesystemSyncher } from './vscode/FilesystemSyncher';
import { FilesystemSyncher } from './vscode/filesystem-syncher';


export async function activate(context: vscode.ExtensionContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as md5 from 'md5';
import * as vscode from 'vscode';

import { NoteGraph } from "../core";
import { Note } from '../core/Note';
import { openNoteInWorkspace } from "../vscode/NoteActions";
import { Note } from '../core/note';
import { openNoteInWorkspace } from "../vscode/note-actions";

import { Feature } from "./feature";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as vscode from 'vscode';

import { Note, NoteGraph, Logger } from "../core";
import { VscodeConfig } from "../vscode";
import { appendTag } from '../vscode/NoteActions';
import { appendTag } from '../vscode/note-actions';

import { Feature } from "./feature";

Expand Down
2 changes: 1 addition & 1 deletion src/features/create-note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';

import { NoteGraph, MarkdownLink } from "../core";
import { letUserChooseFolder, letUserChooseTemplate, letUserChooseText } from "../vscode/Inputs";
import { createNote, openNoteInWorkspace } from "../vscode/NoteActions";
import { createNote, openNoteInWorkspace } from "../vscode/note-actions";

import { Feature } from "./feature";

Expand Down
4 changes: 2 additions & 2 deletions src/features/graphviz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as path from 'path';
import * as vscode from "vscode";

import { NoteGraph, Logger } from "../core";
import { Note, WebviewNote } from "../core/Note";
import { openNoteInWorkspace } from "../vscode/NoteActions";
import { Note, WebviewNote } from "../core/note";
import { openNoteInWorkspace } from "../vscode/note-actions";

import { Feature } from "./feature";

Expand Down
9 changes: 5 additions & 4 deletions src/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Feature } from "./feature";
import createNote from "./create-note";
import graphviz from "./graphviz";
import searchNote from "./search-note";
import backlinkTreedataView from "./backlinkTreedataView";
import tagTreeTreedataView from "./tagsTreedataView";
import consistencyCheck from "./consitencycheck";
import backlinkTreedataView from "./backlink-treedata-view";
import tagTreeTreedataView from "./tags-treedata-views";
import consistencyCheck from "./consitency-check";
import insertSnippets from "./insert-snippets";

export const features: Feature[] = [consistencyCheck, createNote, graphviz, searchNote, backlinkTreedataView, tagTreeTreedataView];
export const features: Feature[] = [consistencyCheck, createNote, graphviz, searchNote, backlinkTreedataView, tagTreeTreedataView, insertSnippets];
70 changes: 70 additions & 0 deletions src/features/insert-snippets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as vscode from 'vscode';

import { NoteGraph } from "../core";
import { insertTextInCurrentNote } from '../vscode/note-actions';

import { Feature } from "./feature";


const snippets = [
{
label: 'HTML Snippets',
content: [
{
label: 'Two-column HTML table',
content: "<table><tr><td>\n\n\n</td><td>\n\n\n</td></tr></table>"
}, {
label: 'Two-column HTML row',
content: "</td></tr><tr><td>\n\n\n</td><td>\n\n"
}
]
}, {
label: 'Emojis',
content: [
{
label: 'Rejection',
content: '❌'
}, {
label: 'Waiting',
content: '🕒'
}, {
label: 'Checkmark',
content: '✔️'
}
]
}
];

const feature: Feature = {
activate: (context: vscode.ExtensionContext, graph: NoteGraph) => {
context.subscriptions.push(
vscode.commands.registerCommand(
'codekasten.insert-snippet',
async () => {

let options = snippets;
while (true) {
const quickPickItems: vscode.QuickPickItem[] = options.map( optionElement => {
if (typeof optionElement.content === 'string') {
return {label: optionElement.label, description: optionElement.content};
} else {
return {label: optionElement.label};
}
});
const selectedItem: vscode.QuickPickItem = await vscode.window.showQuickPick(quickPickItems, {placeHolder: "Choose Snippet/Category..."});
const selectedItemContent: string | any[] = options.filter(x => x.label === selectedItem.label)[0].content;

if (typeof selectedItemContent === 'string') {
insertTextInCurrentNote(selectedItemContent);
break;
} else {
options = selectedItemContent;
}
}
}
)
);
}
};

export default feature;
2 changes: 1 addition & 1 deletion src/features/search-note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';

import { Note, NoteGraph } from "../core";
import { letUserSearchNoteByTitle, letUserChooseNoteAction } from '../vscode/Inputs';
import * as noteActions from "../vscode/NoteActions";
import * as noteActions from "../vscode/note-actions";

import { Feature } from "./feature";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as md5 from 'md5';
import * as vscode from 'vscode';

import { NoteGraph } from "../core";
import { Note } from '../core/Note';
import { openNoteInWorkspace } from "../vscode/NoteActions";
import { Note } from '../core/note';
import { openNoteInWorkspace } from "../vscode/note-actions";

import { Feature } from "./feature";

Expand Down
4 changes: 2 additions & 2 deletions src/test/suite/CodekastenParser.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as assert from 'assert';
import * as path from 'path';

import { MarkdownLink } from '../../core/Link';
import { loadFileAsString } from '../../vscode/NoteActions';
import { MarkdownLink } from '../../core/link';
import { loadFileAsString } from '../../vscode/note-actions';
import { CodekastenParser } from "./../../core";

suite('CodekastenParser', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/NoteActions.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from 'assert';
import * as vscode from 'vscode';
import * as path from 'path';
import { findUniqueFileName } from '../../vscode/NoteActions';
import { findUniqueFileName } from '../../vscode/note-actions';

suite('NoteActions', () => {

Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/NoteGraph.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from 'assert';
import * as vscode from 'vscode';

import { NoteGraph } from './../../core/NoteGraph';
import { NoteGraph } from '../../core/note-graph';
import { CodekastenParser } from "./../../core";

suite('NoteGraph', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as md5 from 'md5';
import * as vscode from 'vscode';

import { Logger, MarkdownLink, NoteGraph } from '../core';
import { replaceTextInFile } from './NoteActions';
import { replaceTextInFile } from './note-actions';


export class FilesystemSyncher{
Expand Down
4 changes: 2 additions & 2 deletions src/vscode/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { VscodeConfig } from "./VscodeConfig";
import { VscodeLogger } from "./VscodeLogger";
import { VscodeConfig } from "./vscode-config";
import { VscodeLogger } from "./vscode-logger";

export {
VscodeConfig,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 0 additions & 31 deletions static/snippets.json

This file was deleted.

0 comments on commit 40c67e8

Please sign in to comment.