Skip to content

Commit

Permalink
Merge pull request #44 from posthtml/use-biomejs
Browse files Browse the repository at this point in the history
  • Loading branch information
cossssmin authored Jun 28, 2024
2 parents 8d18ad8 + 42775ad commit 19a9aad
Show file tree
Hide file tree
Showing 6 changed files with 2,232 additions and 2,838 deletions.
12 changes: 12 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
}
}
27 changes: 0 additions & 27 deletions eslint.config.js

This file was deleted.

12 changes: 7 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getHighlighter } from 'shiki'
import { createHighlighter } from 'shiki'
import { render } from 'posthtml-render'
import parseAttrs from 'posthtml-attrs-parser'

Expand All @@ -18,7 +18,7 @@ const plugin = (options = {}) => tree => {

if (node.tag === options.tag && node.content) {
const attrs = parseAttrs(node.attrs)
let highlighterOptions = {}
const highlighterOptions = {}

// Use `theme` attr if present
if (attrs.theme) {
Expand All @@ -37,18 +37,18 @@ const plugin = (options = {}) => tree => {
// Construct `themes` object for highlighter
highlighterOptions.themes = {}

themes.forEach(([key, value]) => {
for (const [key, value] of themes) {
options.themes.push(value)
highlighterOptions.themes[key.replace('theme-', '')] = value
})
}
} else {
// If no values remain after filtering, use first theme in the list
// Needs to be done only for highlighter
highlighterOptions.theme = options.themes[0]
}
}

promise = getHighlighter({
promise = createHighlighter({
langs: options.langs,
themes: options.themes,
})
Expand Down Expand Up @@ -76,6 +76,8 @@ const plugin = (options = {}) => tree => {
node.attrs = {}
node.tag = wrapTag
node.content = highlighter.codeToHtml(source, highlighterOptions)

highlighter.dispose()
})

promises.push(promise)
Expand Down
Loading

0 comments on commit 19a9aad

Please sign in to comment.