Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can take the code snapshot in two steps:
- [x] Syntax highlighting
- [x] Adjustable image dimensions
- [ ] Customizable theme
- [ ] Customizable fonts
- [x] Customizable fonts

## Contributing

Expand Down Expand Up @@ -47,4 +47,4 @@ Join our community on [Discord](http://discord.devsdope.com/)
Give a ⭐️ if this project helped you!

### License
This project is [MIT](https://github.com/khattakdev/capture/blob/main/LICENSE.md) licensed.
This project is [MIT](https://github.com/khattakdev/capture/blob/main/LICENSE.md) licensed.
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@
"default": "one-dark-pro",
"description": "Select a theme for the screenshot. This theme will be used to style the code in the screenshot, making it look like it does in the VS Code editor with that theme applied.",
"enum": ["dark-plus","dracula-soft","dracula","github-dark-dimmed","github-dark","github-light","hc_light","light-plus","material-theme-darker","material-theme-lighter","material-theme-ocean","material-theme","material-theme-palenight","min-dark","min-light","monokai","nord","one-dark-pro","poimandres","rose-pine-dane","rose-pine","slack-dark","slack-ochin","solarized-dark","solarized-light","vitesse-dark","vitesse-light","rose-pine-dawn","rose-pine-moon","css-variables"]
},
"capture.fontFamily": {
"type": "string",
"default": "Cascadia Code PL",
"description": "Select a font for the code in the screenshot.",
"enum": [
"Cascadia Code PL",
"Fira Code",
"JetBrains Mono",
"Source Code Pro",
"Consolas",
"Roboto Mono",
"Ubuntu Mono",
"Inconsolata",
"Anonymous Pro",
"Hack",
"IBM Plex Mono",
"Droid Sans Mono",
"Courier Prime",
"PT Mono",
"Space Mono"
]
}
}
}]
Expand Down
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export function activate(context: vscode.ExtensionContext) {

const configuration = vscode.workspace.getConfiguration('capture');
const themeName = configuration.get('themeName', 'one-dark-pro');
const fontFamily = configuration.get('fontFamily', 'Cascadia Code PL');

const content = await generateTemplate(text,themeName);
const content = await generateTemplate(text, themeName, fontFamily);
await page.setContent(content);
const contentHeight = content.split("\n").length;
const totalHeight = contentHeight * 3;
Expand Down
16 changes: 14 additions & 2 deletions src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const highlightCode = async (themeName: string) => {
return highlighter;
};

const generateTemplate = async (content: string, themeName: string) => {
const generateTemplate = async (content: string, themeName: string, fontFamily: string = 'Cascadia Code PL') => {
// get hightlighter
const highlighter = await highlightCode(themeName);
// set content
Expand All @@ -20,13 +20,20 @@ const generateTemplate = async (content: string, themeName: string) => {
<html lang="en">
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.26.0/themes/prism.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Fira+Code&family=JetBrains+Mono&family=Source+Code+Pro&family=Roboto+Mono&family=Ubuntu+Mono&family=Inconsolata&family=Anonymous+Pro&family=Hack&family=IBM+Plex+Mono&family=Droid+Sans+Mono&family=Courier+Prime&family=PT+Mono&family=Space+Mono&display=swap" rel="stylesheet">
<style>
@font-face {
font-family: 'Cascadia Code PL';
src: url('https://cdn.jsdelivr.net/gh/microsoft/cascadia-code@latest/ttf/CascadiaCodePL.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}

body {
background: ${backgroundClr};
padding: 0px;
margin: 0px;
font-family: 'Cascadia Code PL', sans-serif;
font-family: '${fontFamily}', monospace;
}

.header {
Expand Down Expand Up @@ -70,6 +77,11 @@ const generateTemplate = async (content: string, themeName: string) => {
font-size: 28px;
height: 30px;
}

/* Apply font to code elements */
pre, code, .shiki, .shiki span {
font-family: '${fontFamily}', monospace !important;
}
</style>
</head>
<body>
Expand Down