generated from typora-community-plugin/typora-plugin-example
-
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.
feat: suport fold code in codemirror
- Loading branch information
Showing
13 changed files
with
130 additions
and
25 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 |
---|---|---|
@@ -1,3 +1,20 @@ | ||
# Typora Plugin Example | ||
# Typora Plugin Code Folding | ||
|
||
This a plugin based on [typora-community-plugin](https://github.com/typora-community-plugin/typora-community-plugin) for [Typora](https://typora.io). | ||
English | [简体中文](./README.zh-CN.md) | ||
|
||
This a plugin based on [typora-community-plugin][core] for [Typora](https://typora.io). | ||
|
||
Make your codes foldable. | ||
|
||
## Preview | ||
|
||
![](./docs/assets/base.gif) | ||
|
||
## Install | ||
|
||
1. Install [typora-community-plugin][core] | ||
2. Open "Settings -> Plugin Marketplace" search "Code Folding" then install it. | ||
|
||
|
||
|
||
[core]: https://github.com/typora-community-plugin/typora-community-plugin |
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 @@ | ||
# Typora Plugin Code Folding | ||
|
||
[English](./README.md) | 简体中文 | ||
|
||
这是一个基于 [typora-community-plugin][core] 开发的,适用于 [Typora](https://typora.io) 的插件。 | ||
|
||
令代码块中的代码可折叠。 | ||
|
||
## 预览 | ||
|
||
![](./docs/assets/base.gif) | ||
|
||
## 安装 | ||
|
||
1. 安装 [typora-community-plugin][core] | ||
2. 在 “设置 -> 插件市场” 中搜索 “Code Folding” 并安装 | ||
|
||
|
||
|
||
[core]: https://github.com/typora-community-plugin/typora-community-plugin |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,14 +1,38 @@ | ||
import './style.scss' | ||
import { Plugin } from '@typora-community-plugin/core' | ||
import 'codemirror/addon/fold/foldgutter.css' | ||
import { Plugin, decorate, path } from '@typora-community-plugin/core' | ||
import { editor } from 'typora' | ||
|
||
|
||
export default class extends Plugin { | ||
|
||
onload() { | ||
alert('hello, typora') | ||
this.registerScript('./addon/fold/foldcode.js') | ||
this.registerScript('./addon/fold/foldgutter.js') | ||
this.registerScript('./addon/fold/brace-fold.js') | ||
this.registerScript('./addon/fold/xml-fold.js') | ||
this.registerScript('./addon/fold/markdown-fold.js') | ||
this.registerScript('./addon/fold/comment-fold.js') | ||
this.registerScript('./addon/fold/indent-fold.js') | ||
|
||
this.register( | ||
decorate.returnValue(editor.fences, 'addCodeBlock', (_, cm) => { | ||
const gutters = cm.getOption('gutters') ?? [] | ||
// @ts-ignore | ||
cm.setOption('foldGutter', true) | ||
cm.setOption('gutters', [...gutters, 'CodeMirror-foldgutter']) | ||
return cm | ||
})) | ||
} | ||
|
||
registerScript(url: string) { | ||
this.register(this.importScript(url)) | ||
} | ||
|
||
onunload() { | ||
// dispose resources, like events, processes... | ||
importScript(url: string) { | ||
const script = document.createElement('script') | ||
script.dataset.by = this.manifest.id | ||
script.src = path.join(this.manifest.dir!, url) | ||
document.head.appendChild(script) | ||
return () => script.remove() | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"typora-community-plugin.example": true | ||
"typora-community-plugin.code-folding": 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 |
---|---|---|
@@ -1,4 +1,11 @@ | ||
# Title | ||
# Code fold | ||
|
||
```javascript | ||
function add(a, b) { | ||
if (typeof a !== 'number' || typeof b !== 'number') { | ||
throw new TypeError() | ||
} | ||
return a + b | ||
} | ||
``` | ||
|
||
Lorem, ipsum dolor sit amet consectetur adipisicing elit. | ||
Adipisci nesciunt dolorem, blanditiis ea facilis, omnis dignissimos, eligendi architecto ducimus veniam necessitatibus illum assumenda id culpa officiis explicabo delectus sequi! Quas. |
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,10 @@ | ||
# doc2 | ||
|
||
```javascript | ||
function add(a, b) { | ||
if (typeof a !== 'number' || typeof b !== 'number') { | ||
throw new TypeError() | ||
} | ||
return a + b | ||
} | ||
``` |