Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weirongxu/coc-webview
Using an external browser to support the webview in coc.nvim.
https://github.com/weirongxu/coc-webview
coc coc-nvim neovim vim webview
Last synced: 3 months ago
JSON representation
Using an external browser to support the webview in coc.nvim.
- Host: GitHub
- URL: https://github.com/weirongxu/coc-webview
- Owner: weirongxu
- License: mit
- Created: 2021-08-29T16:24:53.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-06T04:42:28.000Z (almost 2 years ago)
- Last Synced: 2024-09-25T07:32:23.722Z (3 months ago)
- Topics: coc, coc-nvim, neovim, vim, webview
- Language: TypeScript
- Homepage:
- Size: 106 KB
- Stars: 29
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# coc-webview
Webview panel ported to coc.nvim
## Install
`:CocInstall coc-webview`
## Lists
`:CocList webview`
## Webview as API
Install the coc-webview to `devDependencies`
```typescript
// import only type
import type { WebviewAPI, WebviewPanel } from 'coc-webview';// fetch API
let webviewExt: Extension | undefined;const getWebviewAPI = () => {
if (!webviewExt) {
webviewExt = extensions.all.find((ext) => ext.id === 'coc-webview') as Extension | undefined;
}
if (!webviewExt) {
const hint = 'Please install the coc-webview extension';
void window.showErrorMessage(hint);
throw new Error(hint);
}
return webviewExt.exports;
};// create webview panel
export async function example(): Promise {
const panel = await getWebviewAPI().createWebviewPanel(
// viewType
'markdown-preview-enhanced',
// title
`Preview markdown`,
{
// open in browser
openURL: true,
// route name
routeName: 'markdown-preview-enhanced',
},
{
localResourceRoots: [...],
enableScripts: true,
}
);// update title
panel.title = 'Preview markdown-2'// update html
panel.webview.html = '...'// postMessage
panel.webview.postMessage({type: 'command', 'token': 'xxx'})this.onDidReceiveMessage((msg: {type: string, token: string}) => {
// msg.type
});cosnt util = getWebviewAPI().util;
util.openUri('https://domain.com/');
}
```## Configurations
Usage: https://github.com/neoclide/coc.nvim/wiki/Using-the-configuration-file
- `webview.debug`: Enable debug mode
- `webview.colorStrategy`: Color strategy for webview
- `webview.primaryColors`: Primary colors for webview
- `webview.minPort`: Mix port for webview service
- `webview.maxPort`: Max port for webview service
- `webview.openCommand`: Command template for open webview, arguments(%u webview url), example: `chrome "%u"`## TODO
- [x] dark mode
- [x] webview reveal
- [x] display iconPath
- [ ] vim keybinding
- [ ] cspSource## License
MIT
---
> This extension is built with [create-coc-extension](https://github.com/fannheyward/create-coc-extension)