Skip to content

Commit

Permalink
feat: support line highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
oxwazz committed Apr 28, 2024
1 parent 584776d commit a9aa96d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
9 changes: 6 additions & 3 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import tailwind from "@astrojs/tailwind";
import sitemap from "@astrojs/sitemap";
import prefetch from "@astrojs/prefetch";
import remarkUnwrapImages from "remark-unwrap-images";
// @ts-ignore:next-line
import { remarkReadingTime } from "./src/utils/remark-reading-time.mjs";
import { transformerTwoslash, rendererRich } from "@shikijs/twoslash";
import { transformerNotationDiff, transformerNotationHighlight } from "@shikijs/transformers";

// https://astro.build/config
export default defineConfig({
// ! Please remember to replace the following site property with your own domain
site: "https://oxwazz.com/",
markdown: {
syntaxHighlight: "shiki",
// @ts-expect-error
remarkPlugins: [remarkUnwrapImages, remarkReadingTime],
remarkRehype: { footnoteLabelProperties: { className: [""] } },
shikiConfig: {
Expand All @@ -23,9 +23,12 @@ export default defineConfig({
dark: "vitesse-dark",
},
transformers: [
// @ts-expect-error
transformerTwoslash({
renderer: rendererRich(),
}),
transformerNotationDiff(),
transformerNotationHighlight(),
],
},
},
Expand All @@ -48,7 +51,7 @@ export default defineConfig({
function rawFonts(ext: Array<string>) {
return {
name: "vite-plugin-raw-fonts",
// @ts-ignore:next-line
// @ts-expect-error
transform(_, id) {
if (ext.some((e) => id.endsWith(e))) {
const buffer = fs.readFileSync(id);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"devDependencies": {
"@pagefind/default-ui": "^0.12.0",
"@resvg/resvg-js": "^2.6.2",
"@shikijs/transformers": "^1.3.0",
"@shikijs/twoslash": "^1.2.2",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/typography": "^0.5.12",
Expand Down
11 changes: 9 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion src/content/post/create-export-import-ssh-and-gpg-key/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,25 @@ tags: ["create ssh gpg", "export ssh gpg", "import ssh gpg", "backup ssh gpg"]
- [ ] https://github.com/octo-org/octo-repo/issues/740
- [ ] Add delight to the experience when all tasks are complete :tada:

```ts
console.log('Highlighted') // [!code highlight]
console.log('Highlighted') // [!code highlight]
console.log('Not highlighted')
```

```ts
console.log('hewwo') // [!code --]
console.log('hello') // [!code ++]
console.log('goodbye')
```

### Create SSH Key
1. Generate SSH Key with **ed25519** algorithm.
```bash
ssh-keygen -t ed25519 -C "[email protected]"
```
2. See the generated key.
```bash
```bash {1}
cat ~/.ssh/id_ed25519.pub
# ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIB8J6 "[email protected]"
```
Expand Down
28 changes: 27 additions & 1 deletion src/styles/twoslash.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
margin-right: 0;
}

/** override background-color */
html.dark pre.astro-code,
html.dark pre.astro-code *:not(.twoslash-error-line):not(.twoslash-completions-unmatched) {
color: var(--shiki-dark) !important;
Expand All @@ -44,7 +45,6 @@ html.dark pre.astro-code *:not(.twoslash-error-line):not(.twoslash-completions-u
text-decoration: var(--shiki-dark-text-decoration) !important;
}

/** override background-color */
html pre.astro-code,
html pre.astro-code *:not(.twoslash-error-line):not(.twoslash-completions-unmatched)
{
Expand All @@ -65,3 +65,29 @@ html pre.astro-code {
html pre.astro-code {
@apply mt-2.5 mb-3.5;
}

/** add highlight style */
html pre.astro-code {
@apply block px-0 py-5;
}
html pre.astro-code span.line:has(> *) {
@apply px-5;
display: inline-block;
}

html pre.astro-code span.line.highlighted {
@apply px-5;
display: inline-block;
width: 100%;
}
html pre.astro-code span.line.highlighted,
html pre.astro-code code span.line.highlighted span,
html pre.astro-code code span.line.highlighted span.twoslash-popup-container * {
background: #eaeaea !important;
}

html.dark pre.astro-code span.line.highlighted,
html.dark pre.astro-code code span.line.highlighted span,
html.dark pre.astro-code code span.line.highlighted span.twoslash-popup-container * {
background: #1f1f1f !important;
}

0 comments on commit a9aa96d

Please sign in to comment.