Skip to content

Commit

Permalink
Crossnote integration (#1739)
Browse files Browse the repository at this point in the history
* feat: Started migrating to crossnote

* feat: Basically finished the integration

* feat: Added commands to open local crossnote config files

* fix: Fixed some webview bugs

* fix: Fixed less in vscode web extension

* refactor: Removed all unnecessary console.log

* feat: Updated to crossnote 0.8.3

* fix: Removed some commands

* feat: Updated crossnote to 0.8.6

* ci: Fixed check:all
  • Loading branch information
shd101wyy authored Sep 5, 2023
1 parent df9364a commit dc8a098
Show file tree
Hide file tree
Showing 29 changed files with 6,207 additions and 1,665 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ out


## special cases
mume
mume
crossnote
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules
out
.direnv
mume
crossnote
crossnote
.vscode-test-web
6 changes: 3 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
!*.md
!*.ts


## same as in .gitignore
.vscode-test
*.vsix
node_modules
out

tsconfig.json

## special cases
mume
mume
crossnote
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
</p>

<p align="center">
<a href="https://atom.io/packages/markdown-preview-enhanced">atom</a>
<a href="https://atom.io/packages/markdown-preview-enhanced">Atom</a>
&
<a href="https://marketplace.visualstudio.com/items?itemName=shd101wyy.markdown-preview-enhanced">vscode</a>
<a href="https://marketplace.visualstudio.com/items?itemName=shd101wyy.markdown-preview-enhanced">VSCode</a>
&
<a href="https://vscode.dev">VSCode for the Web</a>
<br>
<br>
<a href="https://a.paddle.com/v2/click/16413/111548?link=1227"><img src="https://img.shields.io/badge/LEARN-VSCODE%20POWER%20USER%20COURSE%20%E2%86%92-gray.svg?colorB=4D2AFF" alt="Become VSCode Power User"></a>
</p>

If you are interested, please try out our new prototype web app: [0xGG/crossnote](https://github.com/0xGG/crossnote)

## Supporting this project

Markdown Preview Enhanced is an open source project released under the [University of Illinois/NCSA Open Source License](LICENSE.md). Its ongoing development is made possible thanks to the support by these awesome [backers](https://shd101wyy.github.io/markdown-preview-enhanced/#/backers). You can help make this project better by [supporting us on GitHub Sponsors](https://github.com/sponsors/shd101wyy), [PayPal](https://shd101wyy.github.io/markdown-preview-enhanced/#/paypal), or [微信支付 Wechat Pay](https://shd101wyy.github.io/markdown-preview-enhanced/#/wechat). Thank you!
Expand Down
83 changes: 71 additions & 12 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,102 @@
const { context, build } = require('esbuild');
const { polyfillNode } = require('esbuild-plugin-polyfill-node');

/**
* @type {import('esbuild').BuildOptions}
*/
const sharedConfig = {
const nativeConfig = {
entryPoints: ['./src/extension.ts'],
bundle: true,
minify: true,
platform: 'node', // For CJS
outfile: './out/native/extension.js',
target: 'node16',
format: 'cjs',
external: ['vscode'],
};

// FIX:
const defaultDocument = {
readyState: 'ready',
};
const defaultWindow = {
document: {
currentScript: {
dataset: {},
},
},
location: {
protocol: 'https:',
},
less: {
onReady: false,
async: false,
},
};

/**
* @type {import('esbuild').BuildOptions}
*/
const cjsConfig = {
...sharedConfig,
platform: 'node', // For CJS
outfile: './out/native/extension.js',
target: 'node16',
const webConfig = {
entryPoints: ['./src/extension-web.ts'],
bundle: true,
minify: true,
platform: 'browser', // For ESM
outfile: './out/web/extension.js',
target: 'es2020',
format: 'cjs',
external: ['vscode'],
plugins: [
polyfillNode({
polyfills: {
fs: true,
},
globals: {
// global: true,
},
}),
],
define: {
// eslint-disable-next-line @typescript-eslint/naming-convention
// window: 'globalThis',
// global: 'globalThis',
// window: "globalThis",
window: JSON.stringify(defaultWindow),
// document: JSON.stringify(defaultDocument),
'process.env.IS_VSCODE_WEB_EXTENSION': '"true"',
},
};

async function main() {
try {
// Watch mode
if (process.argv.includes('--watch')) {
// CommonJS
const cjsContext = await context({
...cjsConfig,
// Native
const nativeContext = await context({
...nativeConfig,
sourcemap: true,
minify: false,
// bundle: false,
// external: undefined,
});
await cjsContext.watch();

// Web
const webContext = await context({
...webConfig,
sourcemap: true,
minify: false,
define: {
...(webConfig.define ?? {}),
...{
'process.env.IS_VSCODE_WEB_EXTENSION_DEV_MODE': '"true"',
},
},
});

await Promise.all([nativeContext.watch(), webContext.watch()]);
} else {
// Build mode
// CommonJS
await build(cjsConfig);
await Promise.all([build(nativeConfig), build(webConfig)]);
}
} catch (error) {
console.error(error);
Expand Down
39 changes: 0 additions & 39 deletions copy-files.js

This file was deleted.

31 changes: 31 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Delete ./crossnote directory
* Then copy files from
* - ./node_modules/crossnote/out/dependencies/. to ./crossnote/dependencies/
* - ./node_modules/crossnote/out/styles/. to ./crossnote/styles/
* - ./node_modules/crossnote/out/webview/. to ./crossnote/webview/
*/
const gulp = require('gulp');
const fs = require('fs');

gulp.task('copy-files', cb => {
// Delete ./crossnote directory
if (fs.existsSync('./crossnote')) {
fs.rmSync('./crossnote', { recursive: true });
}

// Copy files
gulp
.src('./node_modules/crossnote/out/dependencies/**/*')
.pipe(gulp.dest('./crossnote/dependencies/'));
gulp
.src('./node_modules/crossnote/out/styles/**/*')
.pipe(gulp.dest('./crossnote/styles/'));
gulp
.src('./node_modules/crossnote/out/webview/**/*')
.pipe(gulp.dest('./crossnote/webview/'));

console.log('Copy files done.');

cb();
});
59 changes: 35 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@
],
"publisher": "shd101wyy",
"main": "./out/native/extension.js",
"browser": "./out/web/extension.js",
"scripts": {
"build": "yarn copy:files && rm -rf ./out && node build.js",
"check:all": "yarn check:eslint && yarn check:prettier && yarn check:tsc",
"check:all": "yarn check:eslint && yarn check:prettier",
"check:eslint": "eslint \"**/*\"",
"check:prettier": "prettier --check \"**/*.*\"",
"check:tsc": "tsc --project . --noEmit",
"copy:files": "node copy-files.js",
"copy:files": "gulp copy-files",
"fix:all": "yarn fix:eslint && yarn fix:eslint && yarn fix:prettier",
"fix:eslint": "eslint --fix \"**/*\"",
"fix:prettier": "prettier --write \"**/*.*\"",
"run-in-browser": "concurrently \"vscode-test-web --browserType=chromium --extensionDevelopmentPath=. .\" \"npx http-server ./crossnote -p 6789 --cors\"",
"run-in-vscode-dev": "npx serve --cors -l 5000 --ssl-cert $HOME/certs/localhost.pem --ssl-key $HOME/certs/localhost-key.pem",
"test": "yarn build && node ./node_modules/vscode/bin/test",
"vscode:prepublish": "yarn build",
"vscode:prepublish": "yarn install && yarn build",
"watch": "yarn copy:files && rm -rf ./out && node build.js --watch"
},
"contributes": {
Expand Down Expand Up @@ -85,7 +87,12 @@
},
{
"command": "markdown-preview-enhanced.customizeCss",
"title": "%markdown-preview-enhanced.customizeCss.title%"
"title": "%markdown-preview-enhanced.customizeCss.title%",
"enablement": "!isWeb"
},
{
"command": "markdown-preview-enhanced.customizeCssInWorkspace",
"title": "%markdown-preview-enhanced.customizeCssInWorkspace.title%"
},
{
"command": "markdown-preview-enhanced.insertNewSlide",
Expand All @@ -101,35 +108,39 @@
},
{
"command": "markdown-preview-enhanced.createTOC",
"title": "%markdown-preview-enhanced.createTOC.title%"
"title": "%markdown-preview-enhanced.createTOC.title%",
"enablement": "!isWeb"
},
{
"command": "markdown-preview-enhanced.openMermaidConfig",
"title": "%markdown-preview-enhanced.openMermaidConfig.title%"
"command": "markdown-preview-enhanced.openConfigScript",
"title": "%markdown-preview-enhanced.openConfigScript.title%",
"enablement": "!isWeb"
},
{
"command": "markdown-preview-enhanced.openMathJaxConfig",
"title": "%markdown-preview-enhanced.openMathJaxConfig.title%"
"command": "markdown-preview-enhanced.extendParser",
"title": "%markdown-preview-enhanced.extendParser.title%",
"enablement": "!isWeb"
},
{
"command": "markdown-preview-enhanced.openKaTeXConfig",
"title": "%markdown-preview-enhanced.openKaTeXConfig.title%"
"command": "markdown-preview-enhanced.openConfigScriptInWorkspace",
"title": "%markdown-preview-enhanced.openConfigScriptInWorkspace.title%"
},
{
"command": "markdown-preview-enhanced.extendParser",
"title": "%markdown-preview-enhanced.extendParser.title%"
"command": "markdown-preview-enhanced.extendParserInWorkspace",
"title": "%markdown-preview-enhanced.extendParserInWorkspace.title%"
},
{
"command": "markdown-preview-enhanced.showUploadedImages",
"title": "%markdown-preview-enhanced.showUploadedImages.title%"
"title": "%markdown-preview-enhanced.showUploadedImages.title%",
"enablement": "!isWeb"
}
],
"configuration": {
"type": "object",
"title": "Markdown Preview Enhanced",
"properties": {
"markdown-preview-enhanced.configPath": {
"description": "The configuration directory path. Leave it empty to use '~/.mume' as the config path. Please reload vscode to take effect.",
"markdownDescription": "Restart is required after changes. The configuration directory path. Leave it empty to use `$HOME/.crossnote` for Windows or `$XDG_CONFIG_HOME/.crossnote` or `$HOME/.local/state/crossnote` as the config path.",
"default": "",
"type": "string"
},
Expand Down Expand Up @@ -247,14 +258,9 @@
},
"markdown-preview-enhanced.useGitHubStylePipedLink": {
"description": "If checked, we use GitHub style piped wiki links, i.e. [[linkText|wikiLink]]. Otherwise, we use [[wikiLink|linkText]] as the original Wikipedia style.",
"default": true,
"default": false,
"type": "boolean"
},
"markdown-preview-enhanced.wikiLinkFileExtension": {
"description": "By default, the extension for wikilink is `.md`. For example: [[test]] will direct to file path `test.md`.",
"default": ".md",
"type": "string"
},
"markdown-preview-enhanced.enableEmojiSyntax": {
"description": "Enable emoji & font-awesome plugin. This only works for markdown-it parser, but not pandoc parser.",
"default": true,
Expand Down Expand Up @@ -591,8 +597,8 @@
]
},
"dependencies": {
"@shd101wyy/mume": "0.7.9",
"@types/vfile": "^3.0.2"
"@types/vfile": "^3.0.2",
"crossnote": "^0.8.6"
},
"devDependencies": {
"@types/cheerio": "0.22.11",
Expand All @@ -601,8 +607,13 @@
"@types/vscode": "1.80.0",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"@vscode/test-web": "^0.0.45",
"concurrently": "^8.2.1",
"esbuild": "^0.19.2",
"esbuild-plugin-polyfill-node": "^0.3.0",
"eslint": "^8.48.0",
"gulp": "^4.0.2",
"http-server": "^14.1.1",
"husky": "^3.0.9",
"lint-staged": "^9.4.2",
"mocha": "^6.1.4",
Expand Down
11 changes: 6 additions & 5 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
"markdown-preview-enhanced.runAllCodeChunks.title": "Markdown Preview Enhanced: Run All Code Chunks",
"markdown-preview-enhanced.runCodeChunk.title": "Markdown Preview Enhanced: Run Code Chunk",
"markdown-preview-enhanced.syncPreview.title": "Markdown Preview Enhanced: Sync Preview",
"markdown-preview-enhanced.customizeCss.title": "Markdown Preview Enhanced: Customize CSS",
"markdown-preview-enhanced.customizeCss.title": "Markdown Preview Enhanced: Customize CSS (Global)",
"markdown-preview-enhanced.customizeCssInWorkspace.title": "Markdown Preview Enhanced: Customize CSS (Workspace)",
"markdown-preview-enhanced.insertNewSlide.title": "Markdown Preview Enhanced: Insert New Slide",
"markdown-preview-enhanced.insertTable.title": "Markdown Preview Enhanced: Insert Table",
"markdown-preview-enhanced.insertPagebreak.title": "Markdown Preview Enhanced: Insert Page Break",
"markdown-preview-enhanced.createTOC.title": "Markdown Preview Enhanced: Create TOC",
"markdown-preview-enhanced.openMermaidConfig.title": "Markdown Preview Enhanced: Open Mermaid Config",
"markdown-preview-enhanced.openMathJaxConfig.title": "Markdown Preview Enhanced: Open MathJax Config",
"markdown-preview-enhanced.openKaTeXConfig.title": "Markdown Preview Enhanced: Open KaTeX Config",
"markdown-preview-enhanced.extendParser.title": "Markdown Preview Enhanced: Extend Parser",
"markdown-preview-enhanced.openConfigScript.title": "Markdown Preview Enhanced: Open Config Script (Global)",
"markdown-preview-enhanced.openConfigScriptInWorkspace.title": "Markdown Preview Enhanced: Open Config Script (Workspace)",
"markdown-preview-enhanced.extendParser.title": "Markdown Preview Enhanced: Extend Parser (Global)",
"markdown-preview-enhanced.extendParserInWorkspace.title": "Markdown Preview Enhanced: Extend Parser (Workspace)",
"markdown-preview-enhanced.showUploadedImages.title": "Markdown Preview Enhanced: Show Uploaded Images"
}
Loading

0 comments on commit dc8a098

Please sign in to comment.