@@ -7,6 +7,7 @@ import App from './pages/App'
7
7
import parseMarkdownTable from './utils/parseRawInputByMarkdownIt'
8
8
// import { multipleTables, empty, longTables, onlyText, tableWithTextBeforeAndAfter } from './utils/testExample'
9
9
import { longTables } from './utils/testExample'
10
+ import i18n from './locales/i18n'
10
11
import './index.css'
11
12
12
13
const logseq = window . logseq
@@ -24,53 +25,56 @@ if (isInBrowser) {
24
25
bootEditor ( longTables , 111 )
25
26
} else {
26
27
logseq . ready ( ) . then ( ( ) => {
27
- // padding-left: var(--ls-left-sidebar-width);
28
- logseq . provideStyle ( `
29
- iframe#logseq-markdown-table.lsp-iframe-sandbox {
30
- z-index: 10;
31
- }
32
- ` )
33
- console . log ( '[faiz:] === markdown-table-editor-plugin loaded' )
34
- const commandCallback = ( e ) => {
35
- console . log ( '[faiz:] === woz- markdown-table-editor' , e )
36
- logseqEditor . getBlock ( e . uuid ) . then ( block => {
37
- console . log ( '[faiz:] === block ' , block )
38
- const { format , content } = block
39
- // only support markdown
40
- if ( format !== 'markdown' ) return logseqApp . showMsg ( 'woz-markdown-table-editor only support markdown' , 'warning' )
41
-
42
- bootEditor ( content , e . uuid )
28
+ logseq . App . getUserConfigs ( ) . then ( configs => {
29
+ i18n . changeLanguage ( configs . preferredLanguage || 'en' )
30
+ // padding-left: var(--ls-left-sidebar-width);
31
+ logseq . provideStyle ( `
32
+ iframe#logseq-markdown-table.lsp-iframe-sandbox {
33
+ z-index: 10;
34
+ }
35
+ ` )
36
+ console . log ( '[faiz:] === markdown-table-editor-plugin loaded' )
37
+ const commandCallback = ( e ) => {
38
+ console . log ( '[faiz:] === woz-markdown-table-editor ' , e )
39
+ logseqEditor . getBlock ( e . uuid ) . then ( block => {
40
+ console . log ( '[faiz:] === block' , block )
41
+ const { format , content } = block
42
+ // only support markdown
43
+ if ( format !== 'markdown' ) return logseqApp . UI . showMsg ( i18n . t ( 'Markdown table editor only support markdown' ) , 'warning' )
43
44
44
- // for empty block
45
- // todo: fix
46
- // if (content === '') return renderApp(DEFAULT_TABLE, [], e.uuid)
45
+ bootEditor ( content , e . uuid )
47
46
48
- // const tables = parseMarkdownTable(content)
49
- // if (tables?.length > 0) {
50
- // // const [startLine, endLine] = tables[0]
51
- // // const firstTable = content.split('\n').slice(startLine, endLine).join('\n')
52
- // // console.log('[faiz:] === firstTable', content, firstTable, startLine, endLine)
53
- // // return renderApp(firstTable, e.uuid)
54
- // return renderApp(content, tables, e.uuid)
55
- // }
47
+ // for empty block
48
+ // todo: fix
49
+ // if (content === '') return renderApp(DEFAULT_TABLE, [], e.uuid)
56
50
57
- // const renderHtml = md.render(content)
58
- // if (renderHtml.startsWith('<table>') && (renderHtml.endsWith('</table>') || renderHtml.endsWith('</table>\n'))) {
59
- // return renderApp(content || DEFAULT_TABLE, e.uuid)
60
- // }
61
- // format to table error
62
- // window.logseq.App.showMsg('Sorry, block content format to markdown table error', 'warning')
63
- // console.log('[faiz:] === block content format to markdown table error')
64
- } )
65
- }
66
- logseqEditor . registerBlockContextMenuItem ( 'markdown-table-editor' , commandCallback )
67
- logseqEditor . registerSlashCommand ( 'markdown-table-editor' , commandCallback )
51
+ // const tables = parseMarkdownTable(content)
52
+ // if (tables?.length > 0) {
53
+ // // const [startLine, endLine] = tables[0]
54
+ // // const firstTable = content.split('\n').slice(startLine, endLine).join('\n')
55
+ // // console.log('[faiz:] === firstTable', content, firstTable, startLine, endLine)
56
+ // // return renderApp(firstTable, e.uuid)
57
+ // return renderApp(content, tables, e.uuid)
58
+ // }
68
59
69
- logseq . on ( 'ui:visible:changed' , ( e ) => {
70
- if ( ! e . visible ) {
71
- ReactDOM . unmountComponentAtNode ( document . getElementById ( 'root' ) ) ;
60
+ // const renderHtml = md.render(content)
61
+ // if (renderHtml.startsWith('<table>') && (renderHtml.endsWith('</table>') || renderHtml.endsWith('</table>\n'))) {
62
+ // return renderApp(content || DEFAULT_TABLE, e.uuid)
63
+ // }
64
+ // format to table error
65
+ // window.logseq.App.showMsg('Sorry, block content format to markdown table error', 'warning')
66
+ // console.log('[faiz:] === block content format to markdown table error')
67
+ } )
72
68
}
73
- } ) ;
69
+ logseqEditor . registerBlockContextMenuItem ( i18n . t ( 'Markdown Table Editor' ) , commandCallback )
70
+ logseqEditor . registerSlashCommand ( 'Markdown Table Editor' , commandCallback )
71
+
72
+ logseq . on ( 'ui:visible:changed' , ( e ) => {
73
+ if ( ! e . visible ) {
74
+ ReactDOM . unmountComponentAtNode ( document . getElementById ( 'root' ) ) ;
75
+ }
76
+ } ) ;
77
+ } )
74
78
} )
75
79
}
76
80
0 commit comments