File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import 'codemirror/addon/fold/foldgutter.css'
22import { Plugin , decorate , path } from '@typora-community-plugin/core'
33import { editor } from 'typora'
4+ import type * as CodeMirror from 'codemirror'
45
56
7+ const FOLD_BY_INDENT = [ 'ruby' , 'sql' ]
8+
69export default class extends Plugin {
710
11+ private _isModeFixed = false
12+
813 onload ( ) {
14+
915 this . registerScript ( './addon/fold/foldcode.js' )
1016 this . registerScript ( './addon/fold/foldgutter.js' )
1117 this . registerScript ( './addon/fold/brace-fold.js' )
@@ -16,6 +22,19 @@ export default class extends Plugin {
1622
1723 this . register (
1824 decorate . returnValue ( editor . fences , 'addCodeBlock' , ( _ , cm ) => {
25+ if ( ! this . _isModeFixed ) {
26+ for ( const lang of FOLD_BY_INDENT ) {
27+ this . register (
28+ // @ts -ignore
29+ decorate . returnValue ( CodeMirror . modes , lang , ( _ , results ) => {
30+ // @ts -ignore
31+ results . fold = 'indent'
32+ return results
33+ } ) )
34+ }
35+ this . _isModeFixed = true
36+ }
37+
1938 const gutters = cm . getOption ( 'gutters' ) ?? [ ]
2039 // @ts -ignore
2140 cm . setOption ( 'foldGutter' , true )
Original file line number Diff line number Diff line change 55 "author" : " plylrnsdy" ,
66 "authorUrl" : " https://github.com/plylrnsdy" ,
77 "repo" : " typora-community-plugin/typora-plugin-code-folding" ,
8- "version" : " 1.0.0 " ,
8+ "version" : " 1.0.2 " ,
99 "minAppVersion" : " 1.5.0" ,
1010 "minCoreVersion" : " 2.0.0-beta.36" ,
1111 "platforms" : [" win32" , " linux" , " darwin" ]
Original file line number Diff line number Diff line change 11# doc2
22
33``` javascript
4+ // JavaScript
45function add (a , b ) {
56 if (typeof a !== ' number' || typeof b !== ' number' ) {
67 throw new TypeError ()
78 }
89 return a + b
910}
1011```
12+
13+ ``` sql
14+ -- SQL
15+ SELECT a, b, c
16+ FROM table1
17+ WHERE id = 1
18+ ```
19+
20+ ``` ruby
21+ # Ruby
22+ class ImportMap ::Commands < Thor
23+ include Thor .Actions
24+
25+ def pin (* )
26+ package.download(package, url)
27+ end
28+
29+ private
30+
31+ def packager
32+ @package ||= Importer .Packager .new
33+ end
34+ end
35+ ```
36+
37+ ``` python
38+ # Python
39+ def add (a , b ):
40+ return a + b
41+ ```
42+
You can’t perform that action at this time.
0 commit comments