Skip to content

Commit 265819e

Browse files
author
Yu
committed
init (formatting, toc)
0 parents  commit 265819e

17 files changed

+526
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
out
2+
node_modules

.vscode/launch.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// A launch configuration that compiles the extension and then opens it inside a new window
2+
{
3+
"version": "0.1.0",
4+
"configurations": [
5+
{
6+
"name": "Launch Extension",
7+
"type": "extensionHost",
8+
"request": "launch",
9+
"runtimeExecutable": "${execPath}",
10+
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
11+
"stopOnEntry": false,
12+
"sourceMaps": true,
13+
"outDir": "${workspaceRoot}/out/src",
14+
"preLaunchTask": "npm"
15+
},
16+
{
17+
"name": "Launch Tests",
18+
"type": "extensionHost",
19+
"request": "launch",
20+
"runtimeExecutable": "${execPath}",
21+
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
22+
"stopOnEntry": false,
23+
"sourceMaps": true,
24+
"outDir": "${workspaceRoot}/out/test",
25+
"preLaunchTask": "npm"
26+
}
27+
]
28+
}

.vscode/settings.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"files.exclude": {
4+
"out": false // set this to true to hide the "out" folder with the compiled JS files
5+
},
6+
"search.exclude": {
7+
"out": true // set this to false to include "out" folder in search results
8+
},
9+
"typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version
10+
}

.vscode/tasks.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Available variables which can be used inside of strings.
2+
// ${workspaceRoot}: the root folder of the team
3+
// ${file}: the current opened file
4+
// ${fileBasename}: the current opened file's basename
5+
// ${fileDirname}: the current opened file's dirname
6+
// ${fileExtname}: the current opened file's extension
7+
// ${cwd}: the current working directory of the spawned process
8+
9+
// A task runner that calls a custom npm script that compiles the extension.
10+
{
11+
"version": "0.1.0",
12+
13+
// we want to run npm
14+
"command": "npm",
15+
16+
// the command is a shell script
17+
"isShellCommand": true,
18+
19+
// show the output window only if unrecognized errors occur.
20+
"showOutput": "silent",
21+
22+
// we run the custom script "compile" as defined in package.json
23+
"args": ["run", "compile", "--loglevel", "silent"],
24+
25+
// The tsc compiler is started in watching mode
26+
"isWatching": true,
27+
28+
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
29+
"problemMatcher": "$tsc-watch"
30+
}

.vscodeignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.vscode/**
2+
.vscode-test/**
3+
out/test/**
4+
test/**
5+
src/**
6+
**/*.map
7+
.gitignore
8+
tsconfig.json
9+
vsc-extension-quickstart.md

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Release Notes
2+
3+
## 0.1.0
4+
5+
Preview

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# markdown-all-in-one README
2+
3+
All you need for markdown.
4+
5+
## Features
6+
7+
- Keyboard shortcuts (toggle bold, italic)
8+
9+
### Shortcuts
10+
11+
### Table of Contents
12+
13+
## Requirements
14+
15+
If you have any requirements or dependencies, add a section describing those and how to install and configure them.
16+
17+
## Extension Settings
18+
19+
Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
20+
21+
For example:
22+
23+
This extension contributes the following settings:
24+
25+
* `myExtension.enable`: enable/disable this extension
26+
* `myExtension.thing`: set to `blah` to do something
27+
28+
## Known Issues
29+
30+
Calling out known issues can help limit users opening duplicate issues against your extension.

markdown-all-in-one-0.0.1.vsix

14.2 KB
Binary file not shown.

package.json

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
{
2+
"name": "markdown-all-in-one",
3+
"displayName": "Markdown All in One",
4+
"description": "All you need to write markdown",
5+
"version": "0.0.1",
6+
"publisher": "yzhang",
7+
"engines": {
8+
"vscode": "^1.5.0"
9+
},
10+
"categories": [
11+
"Other"
12+
],
13+
"activationEvents": [
14+
"onLanguage:markdown"
15+
],
16+
"main": "./out/src/extension",
17+
"contributes": {
18+
"commands": [
19+
{
20+
"command": "extension.markdown.editing.toggleBold",
21+
"title": "Markdown: Toggle Bold"
22+
},
23+
{
24+
"command": "extension.markdown.editing.toggleItalic",
25+
"title": "Markdown: Toggle Italic"
26+
},
27+
{
28+
"command": "extension.markdown.editing.toggleCodeSpan",
29+
"title": "Markdown: Toggle Code Span"
30+
},
31+
{
32+
"command": "extension.markdown.toc.create",
33+
"title": "Markdown: Create Table of Contents"
34+
}
35+
],
36+
"keybindings": [
37+
{
38+
"command": "extension.markdown.editing.toggleBold",
39+
"key": "ctrl+b",
40+
"mac": "cmd+b",
41+
"when": "editorTextFocus && editorLangId == markdown"
42+
},
43+
{
44+
"command": "extension.markdown.editing.toggleItalic",
45+
"key": "ctrl+i",
46+
"mac": "cmd+i",
47+
"when": "editorTextFocus && editorLangId == markdown"
48+
},
49+
{
50+
"command": "extension.markdown.editing.toggleCodeSpan",
51+
"key": "ctrl+m ctrl+c",
52+
"mac": "cmd+m cmd+c",
53+
"when": "editorTextFocus && editorLangId == markdown"
54+
}
55+
]
56+
},
57+
"configuration": {
58+
"type": "object",
59+
"title": "Markdown All in One",
60+
"properties": {
61+
"markdown.toc.depthFrom": {
62+
"type": "number",
63+
"default": 1,
64+
"description": "Depth control [1-6]."
65+
},
66+
"markdown.toc.depthTo": {
67+
"type": "number",
68+
"default": 6,
69+
"description": "Depth control [1-6]."
70+
},
71+
"markdown.toc.insertAnchor": {
72+
"type": "boolean",
73+
"default": false,
74+
"description": "Auto insert anchor for link."
75+
},
76+
"markdown.toc.withLinks": {
77+
"type": "boolean",
78+
"default": true,
79+
"description": "Auto insert link."
80+
},
81+
"markdown.toc.orderedList": {
82+
"type": "boolean",
83+
"default": false,
84+
"description": "Use ordered list (1. ..., 2. ...)."
85+
},
86+
"markdown.toc.updateOnSave": {
87+
"type": "boolean",
88+
"default": true,
89+
"description": "Auto update on save."
90+
},
91+
"markdown.toc.anchorMode": {
92+
"type": "string",
93+
"default": "github.com",
94+
"description": "anchor mode.",
95+
"enum": [
96+
"github.com",
97+
"nodejs.org",
98+
"bitbucket.org",
99+
"ghost.org",
100+
"gitlab.com"
101+
]
102+
}
103+
}
104+
},
105+
"scripts": {
106+
"vscode:prepublish": "tsc -p ./",
107+
"compile": "tsc -watch -p ./",
108+
"postinstall": "node ./node_modules/vscode/bin/install"
109+
},
110+
"dependencies": {
111+
},
112+
"devDependencies": {
113+
"typescript": "^2.0.3",
114+
"vscode": "^1.0.0",
115+
"mocha": "^2.3.3",
116+
"@types/node": "^6.0.40",
117+
"@types/mocha": "^2.2.32"
118+
}
119+
}

src/extension.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
import { commands, workspace, ExtensionContext, TextDocument } from 'vscode';
4+
import * as mdCommands from './formatting';
5+
import * as toc from './toc';
6+
7+
export function activate(context: ExtensionContext) {
8+
mdCommands.activate(context);
9+
toc.activate(context);
10+
}
11+
12+
export function deactivate() {
13+
}

src/formatting.ts

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
'use strict';
2+
3+
/**
4+
* Modified from <https://github.com/mdickin/vscode-markdown-shortcuts>
5+
*/
6+
7+
import { commands, window, ExtensionContext, Selection } from 'vscode';
8+
9+
const prefix = 'extension.markdown.editing.';
10+
11+
export function activate(context: ExtensionContext) {
12+
const cmds: Command[] = [
13+
{ command: 'toggleBold', callback: toggleBold },
14+
{ command: 'toggleItalic', callback: toggleItalic },
15+
{ command: 'toggleCodeSpan', callback: toggleCodeSpan }
16+
].map(cmd => {
17+
cmd.command = prefix + cmd.command;
18+
return cmd;
19+
});
20+
21+
cmds.forEach(cmd => {
22+
context.subscriptions.push(commands.registerCommand(cmd.command, cmd.callback));
23+
});
24+
}
25+
26+
function toggleBold() {
27+
wrapSelection('**');
28+
}
29+
30+
function toggleItalic() {
31+
wrapSelection('*');
32+
}
33+
34+
function toggleCodeSpan() {
35+
wrapSelection('`');
36+
}
37+
38+
function wrapSelection(startPattern, endPattern?) {
39+
if (endPattern == undefined || endPattern == null) {
40+
endPattern = startPattern;
41+
}
42+
43+
let editor = window.activeTextEditor;
44+
let selection = editor.selection;
45+
46+
if (selection.isEmpty) { // No selected text
47+
let position = selection.active;
48+
let newPosition = position.with(position.line, position.character + startPattern.length);
49+
editor.edit((edit) => {
50+
edit.insert(selection.start, startPattern + endPattern);
51+
}).then(() => {
52+
editor.selection = new Selection(newPosition, newPosition);
53+
});
54+
}
55+
else { // Text selected
56+
let text = editor.document.getText(selection);
57+
if (isMatch(text, startPattern, endPattern)) {
58+
replaceWith(selection, text.substr(startPattern.length, text.length - startPattern.length - endPattern.length));
59+
}
60+
else {
61+
replaceWith(selection, startPattern + text + endPattern);
62+
}
63+
}
64+
}
65+
66+
function isMatch(text, startPattern, endPattern?) {
67+
// if (startPattern.constructor === RegExp) {
68+
// return startPattern.test(text);
69+
// }
70+
return text.startsWith(startPattern) && text.endsWith(endPattern);
71+
}
72+
73+
function replaceWith(selection, newText) {
74+
let editor = window.activeTextEditor;
75+
editor.edit((edit) => {
76+
edit.replace(selection, newText);
77+
});
78+
}

src/global.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare interface Command {
2+
command: string;
3+
callback: (...args: any[]) => any;
4+
}
5+
6+
declare interface Heading {
7+
level: number;
8+
title: string;
9+
}

0 commit comments

Comments
 (0)