mirror of
https://github.com/ershisan99/md-preview-desktop.git
synced 2026-01-27 05:12:11 +00:00
chore: use lib instead of copy-pasting bundling module
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
import { bundleMDX } from 'mdx-bundler'
|
||||
import rehypePrettyCode from 'rehype-pretty-code'
|
||||
import rehypeSlug from 'rehype-slug'
|
||||
|
||||
import { CODE_BLOCK_FILENAME_REGEX } from './constants'
|
||||
import { attachMeta, parseMeta } from './rehype'
|
||||
import theme from './theme.json'
|
||||
import { BundledMdx } from './types'
|
||||
|
||||
export const bundleMdx = async (source: string): Promise<BundledMdx> => {
|
||||
return await bundleMDX({
|
||||
globals: {
|
||||
components: '@it-incubator/mdx-components',
|
||||
},
|
||||
mdxOptions(options) {
|
||||
options.rehypePlugins = [
|
||||
...(options.rehypePlugins ?? []),
|
||||
rehypeSlug,
|
||||
[parseMeta, { defaultShowCopyCode: true }],
|
||||
[
|
||||
rehypePrettyCode,
|
||||
{
|
||||
filterMetaString: (meta: string) => meta.replace(CODE_BLOCK_FILENAME_REGEX, ''),
|
||||
onVisitHighlightedChars(node: any) {
|
||||
node.properties.className = ['highlighted']
|
||||
},
|
||||
onVisitHighlightedLine(node: any) {
|
||||
node.properties.className.push('highlighted')
|
||||
},
|
||||
onVisitLine(node: any) {
|
||||
// Prevent lines from collapsing in `display: grid` mode, and
|
||||
// allow empty lines to be copy/pasted
|
||||
if (node.children.length === 0) {
|
||||
node.children = [{ type: 'text', value: ' ' }]
|
||||
}
|
||||
},
|
||||
theme,
|
||||
},
|
||||
],
|
||||
attachMeta,
|
||||
]
|
||||
|
||||
return options
|
||||
},
|
||||
source,
|
||||
})
|
||||
}
|
||||
@@ -3,10 +3,10 @@ import path from 'node:path'
|
||||
import { join } from 'path'
|
||||
|
||||
import { electronApp, is, optimizer } from '@electron-toolkit/utils'
|
||||
import { bundleMdx } from '@it-incubator/md-bundler'
|
||||
import { BrowserWindow, app, ipcMain, shell } from 'electron'
|
||||
|
||||
import icon from '../../resources/icon.png?asset'
|
||||
import { bundleMdx } from './bundle-mdx'
|
||||
const chokidar = require('chokidar')
|
||||
|
||||
let mainWindow: BrowserWindow | null = null
|
||||
|
||||
@@ -180,10 +180,6 @@
|
||||
padding-inline: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
&:not([data-theme]) {
|
||||
@apply px-4;
|
||||
}
|
||||
}
|
||||
|
||||
& img {
|
||||
|
||||
Reference in New Issue
Block a user