-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f4c0978
Showing
16 changed files
with
1,676 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 6, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
"@typescript-eslint/naming-convention": "warn", | ||
"@typescript-eslint/semi": "warn", | ||
"curly": "warn", | ||
"eqeqeq": "warn", | ||
"no-throw-literal": "warn", | ||
"semi": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
out | ||
node_modules | ||
.vscode-test/ | ||
*.vsix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
// See http://go.microsoft.com/fwlink/?LinkId=827846 | ||
// for the documentation about the extensions.json format | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// A launch configuration that compiles the extension and then opens it inside a new window | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Run Extension", | ||
"type": "extensionHost", | ||
"request": "launch", | ||
"runtimeExecutable": "${execPath}", | ||
"args": [ | ||
"--extensionDevelopmentPath=${workspaceFolder}" | ||
], | ||
"outFiles": [ | ||
"${workspaceFolder}/out/**/*.js" | ||
], | ||
"preLaunchTask": "${defaultBuildTask}" | ||
}, | ||
{ | ||
"name": "Extension Tests", | ||
"type": "extensionHost", | ||
"request": "launch", | ||
"runtimeExecutable": "${execPath}", | ||
"args": [ | ||
"--extensionDevelopmentPath=${workspaceFolder}", | ||
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index" | ||
], | ||
"outFiles": [ | ||
"${workspaceFolder}/out/test/**/*.js" | ||
], | ||
"preLaunchTask": "${defaultBuildTask}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Place your settings in this file to overwrite default and user settings. | ||
{ | ||
"files.exclude": { | ||
"out": false // set this to true to hide the "out" folder with the compiled JS files | ||
}, | ||
"search.exclude": { | ||
"out": true // set this to false to include "out" folder in search results | ||
}, | ||
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts | ||
"typescript.tsc.autoDetect": "off" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "npm", | ||
"script": "watch", | ||
"problemMatcher": "$tsc-watch", | ||
"isBackground": true, | ||
"presentation": { | ||
"reveal": "never" | ||
}, | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.vscode/** | ||
.vscode-test/** | ||
out/test/** | ||
src/** | ||
.gitignore | ||
.yarnrc | ||
vsc-extension-quickstart.md | ||
**/tsconfig.json | ||
**/.eslintrc.json | ||
**/*.map | ||
**/*.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--ignore-engines true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# 由来 | ||
|
||
主要有整理笔记时, 有些内容需要注意引用的需求, 在给[^2]提交`PR`后很可惜作者一直没有上线, 就去提交给了`markdown all in one`, 在大佬们的讨论中, 发现这样一个场景, `markdown` | ||
|
||
# Reference | ||
1. [leidichen/markdown\-add\-quote](https://github.com/leidichen/markdown-add-quote) | ||
2. [Shortcut to toggle block quotes? · Issue \#704 · yzhang\-gh/vscode\-markdown](https://github.com/yzhang-gh/vscode-markdown/issues/704) | ||
3. [✨ Add "toggle block quote" by Sean10 · Pull Request \#811 · yzhang\-gh/vscode\-markdown](https://github.com/yzhang-gh/vscode-markdown/pull/811) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "vscode-markdown-quote", | ||
"displayName": "vscode-markdown-quote", | ||
"description": "vscode markdown block quote.", | ||
"version": "0.0.1", | ||
"engines": { | ||
"vscode": "^1.49.0" | ||
}, | ||
"categories": [ | ||
"Other" | ||
], | ||
"activationEvents": [ | ||
"onLanguage:markdown" | ||
], | ||
"main": "./out/extension.js", | ||
"contributes": { | ||
"commands": [ | ||
{ | ||
"command": "extension.markdownToggleQuote", | ||
"title": "vscode toggle quote" | ||
} | ||
], | ||
"keybindings":[ | ||
{ | ||
"command": "extension.markdownToggleQuote", | ||
"key": "alt+.", | ||
"mac": "cmd+.", | ||
"when": "editorTextFocus && editorLangId == markdown" | ||
} | ||
] | ||
}, | ||
"scripts": { | ||
"vscode:prepublish": "yarn run compile", | ||
"compile": "tsc -p ./", | ||
"lint": "eslint src --ext ts", | ||
"watch": "tsc -watch -p ./", | ||
"pretest": "yarn run compile && yarn run lint", | ||
"test": "node ./out/test/runTest.js" | ||
}, | ||
"devDependencies": { | ||
"@types/vscode": "^1.49.0", | ||
"@types/glob": "^7.1.3", | ||
"@types/mocha": "^8.0.0", | ||
"@types/node": "^14.0.27", | ||
"eslint": "^7.6.0", | ||
"@typescript-eslint/eslint-plugin": "^3.8.0", | ||
"@typescript-eslint/parser": "^3.8.0", | ||
"glob": "^7.1.6", | ||
"mocha": "^8.1.3", | ||
"typescript": "^4.0.2", | ||
"vscode-test": "^1.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// The module 'vscode' contains the VS Code extensibility API | ||
// Import the module and reference it with the alias vscode in your code below | ||
'use strict'; | ||
// import * as vscode from 'vscode'; | ||
import { commands, env, EndOfLine, ExtensionContext, Position, Range, Selection, SnippetString, TextDocument, TextEditor, window, workspace, WorkspaceEdit } from 'vscode'; | ||
|
||
|
||
enum QuoteState { | ||
// State 1: part of lines has been quoted, need to be quoted | ||
PARTIALQUOTED, | ||
// State 2: all of lines has been quoted, need to be unquoted | ||
FULLQUOTED, | ||
} | ||
|
||
function getQuoteState(lineArray: Array<string>): QuoteState { | ||
return lineArray.every(line => line.startsWith('>')) ? QuoteState.FULLQUOTED : QuoteState.PARTIALQUOTED; | ||
} | ||
|
||
function quoteLine(line: string): string { | ||
if(!line.startsWith(">")){ | ||
return "> " + line; | ||
} else { | ||
return line; | ||
} | ||
} | ||
|
||
function unquoteLine(line: string): string { | ||
if (!line.startsWith("> ") && line.startsWith(">")) { | ||
return line.slice(1); | ||
} | ||
else if (line.startsWith("> ")) { | ||
return line.slice(2); | ||
} else { | ||
return line; | ||
} | ||
} | ||
|
||
function setQuote(lineArray: Array<string>, state: QuoteState, eol: string): string { | ||
let resultArray; | ||
switch(state) { | ||
case QuoteState.PARTIALQUOTED: | ||
resultArray = lineArray.map(quoteLine); | ||
break; | ||
case QuoteState.FULLQUOTED: | ||
resultArray = lineArray.map(unquoteLine); | ||
break; | ||
default: | ||
resultArray = lineArray; | ||
} | ||
return resultArray.join(eol); | ||
} | ||
|
||
function toggleQuote() { | ||
let editor = window.activeTextEditor; | ||
if (editor == undefined) { | ||
return ; | ||
} | ||
let start = editor.selection.start; | ||
let end = editor.selection.end; | ||
start = editor.document.lineAt(start.line).range.start; | ||
end = editor.document.lineAt(end.line).range.end; | ||
let linesText = editor.document.getText(new Range(start, end));; | ||
let eol = editor.document.eol === EndOfLine.CRLF ? '\r\n' : '\n'; | ||
|
||
let line_array = linesText.split(eol); | ||
let state = getQuoteState(line_array); | ||
console.log("state", state); | ||
let resultText = setQuote(line_array, state, eol); | ||
|
||
return editor.edit(editBuilder => { | ||
editBuilder.replace(new Range(start, end), resultText); | ||
}); | ||
} | ||
|
||
export function activate(context: ExtensionContext) { | ||
context.subscriptions.push( | ||
commands.registerCommand('extension.markdownToggleQuote', toggleQuote) | ||
); | ||
} | ||
|
||
// this method is called when your extension is deactivated | ||
export function deactivate() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as path from 'path'; | ||
|
||
import { runTests } from 'vscode-test'; | ||
|
||
async function main() { | ||
try { | ||
// The folder containing the Extension Manifest package.json | ||
// Passed to `--extensionDevelopmentPath` | ||
const extensionDevelopmentPath = path.resolve(__dirname, '../../'); | ||
|
||
// The path to test runner | ||
// Passed to --extensionTestsPath | ||
const extensionTestsPath = path.resolve(__dirname, './suite/index'); | ||
|
||
// Download VS Code, unzip it and run the integration test | ||
await runTests({ extensionDevelopmentPath, extensionTestsPath }); | ||
} catch (err) { | ||
console.error('Failed to run tests'); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as assert from 'assert'; | ||
|
||
// You can import and use all API from the 'vscode' module | ||
// as well as import your extension to test it | ||
import * as vscode from 'vscode'; | ||
// import * as myExtension from '../../extension'; | ||
|
||
suite('Extension Test Suite', () => { | ||
vscode.window.showInformationMessage('Start all tests.'); | ||
|
||
test('Sample test', () => { | ||
assert.equal(-1, [1, 2, 3].indexOf(5)); | ||
assert.equal(-1, [1, 2, 3].indexOf(0)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as path from 'path'; | ||
import * as Mocha from 'mocha'; | ||
import * as glob from 'glob'; | ||
|
||
export function run(): Promise<void> { | ||
// Create the mocha test | ||
const mocha = new Mocha({ | ||
ui: 'tdd', | ||
color: true | ||
}); | ||
|
||
const testsRoot = path.resolve(__dirname, '..'); | ||
|
||
return new Promise((c, e) => { | ||
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { | ||
if (err) { | ||
return e(err); | ||
} | ||
|
||
// Add files to the test suite | ||
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); | ||
|
||
try { | ||
// Run the mocha test | ||
mocha.run(failures => { | ||
if (failures > 0) { | ||
e(new Error(`${failures} tests failed.`)); | ||
} else { | ||
c(); | ||
} | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
e(err); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es6", | ||
"outDir": "out", | ||
"lib": [ | ||
"es6" | ||
], | ||
"sourceMap": true, | ||
"rootDir": "src", | ||
"strict": true /* enable all strict type-checking options */ | ||
/* Additional Checks */ | ||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ | ||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ | ||
// "noUnusedParameters": true, /* Report errors on unused parameters. */ | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
".vscode-test" | ||
] | ||
} |
Oops, something went wrong.