Skip to content

Commit

Permalink
feat: codeblock highlight mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
plylrnsdy committed Jul 26, 2023
1 parent cfd0312 commit 20232c2
Show file tree
Hide file tree
Showing 14 changed files with 896 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 plylrnsdy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Typora Plugin Codeblock Hightlight Mapper

English | [简体中文](https://github.com/typora-community-plugin/typora-plugin-codeblock-highlight-mapper/blob/main/README.zh-CN.md)

This a plugin example based on [typora-community-plugin](https://github.com/typora-community-plugin/typora-community-plugin) for [Typora](https://typora.io).

Map language A to language B for highlighting it.

## Preview

![](https://fastly.jsdelivr.net/gh/typora-community-plugin/typora-plugin-codeblock-highlight-mapper@main/docs/assets/base.jpg)
11 changes: 11 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Typora Plugin Codeblock Hightlight Mapper

[English](https://github.com/typora-community-plugin/typora-plugin-codeblock-highlight-mapper#README.md) | 简体中文

这是一个基于 [typora-community-plugin](https://github.com/typora-community-plugin/typora-community-plugin) 开发的,适用于 [Typora](https://typora.io) 的插件。

为了高亮不支持的语言,可以根据配置将语言 A 映射为语言 B,以使用语言 B 的语法高亮。

## Preview

![](https://fastly.jsdelivr.net/gh/typora-community-plugin/typora-plugin-codeblock-highlight-mapper@main/docs/assets/base.jpg)
41 changes: 41 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as child_process from 'node:child_process'
import * as fs from 'node:fs/promises'
import * as path from 'node:path'
import * as esbuild from 'esbuild'
import typoraPlugin from 'esbuild-plugin-typora'


const args = process.argv.slice(2)
const IS_PROD = args.includes('--prod')
const IS_DEV = !IS_PROD

await fs.rm('./dist', { recursive: true, force: true })

await esbuild.build({
entryPoints: ['src/main.ts'],
outdir: 'dist',
format: 'esm',
bundle: true,
minify: IS_PROD,
sourcemap: IS_DEV,
plugins: [
typoraPlugin({
mode: IS_PROD ? 'production' : 'development'
}),
],
})

if (IS_DEV) {

const manifestPath = './src/manifest.json'
const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'))

await fs.copyFile(manifestPath, './dist/manifest.json')
await fs.cp('./dist', './test/vault/.typora/plugins/dist', { recursive: true })
await fs.writeFile('./test/vault/.typora/plugins.json', JSON.stringify({ [manifest.id]: true }))

await fs.rm(path.join(process.env.USERPROFILE, '.typora/community-plugins/.lock/win-test'))
.catch(() => { })

child_process.exec('Typora ./test/vault/doc.md')
}
16 changes: 16 additions & 0 deletions pack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as fs from 'node:fs'
import archiver from 'archiver'


const output = fs.createWriteStream('plugin.zip')

const archive = archiver('zip', { zlib: { level: 9 } })
.on('error', (err) => { throw err })

archive.pipe(output)

archive
.directory('dist', false)
.file('src/manifest.json', { name: 'manifest.json' })

archive.finalize()
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"private": true,
"name": "typora-plugin-codeblock-highlight-mapper",
"version": "",
"description": "",
"type": "module",
"main": "",
"scripts": {
"build:dev": "node build.js",
"build": "node build.js --prod",
"pack": "pnpm run build && node pack.js"
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"@types/extract-zip": "1.6.2",
"@types/glob": "7.2.0",
"@types/jquery": "3.3.1",
"@types/lodash": "~4.14.196",
"@types/node": "16.18.0",
"@types/yauzl": "2.10.0",
"@typora-community-plugin/core": "^2.0.0-beta.4",
"archiver": "^5.3.1",
"esbuild": "^0.18.17",
"esbuild-plugin-typora": "npm:@typora-community-plugin/esbuild-plugin-typora@^1.0.2",
"iconv-lite": "0.6.3"
}
}
Loading

0 comments on commit 20232c2

Please sign in to comment.