Skip to content
This repository has been archived by the owner on Oct 8, 2022. It is now read-only.

feature:background and font color(Github Dark Mode) #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions package-lock.json

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

10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@
"type": "string",
"default": "background: white;",
"description": "Optional style for rendered display SVG equations. (Only supported when inserting as HTML)"
},
"vscode-math-to-image.backgroundColor": {
"type": "string",
"default": "white",
"description": "Optional background color for rendered equations. (Only supported when inserting as HTML)"
},
"vscode-math-to-image.fontColor": {
"type": "string",
"default": "black",
"description": "Optional font color for rendered equations. (Only supported when inserting as HTML)"
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ function insertMathImage(renderedImagePath: string, start: vscode.Position, end:
vscode.window.showInformationMessage(`Render equation successfully!`)
}

function setSvgColor(equation: string) {
const fontColor = vscode.workspace.getConfiguration().get("vscode-math-to-image.fontColor")
const backgroundColor = vscode.workspace.getConfiguration().get("vscode-math-to-image.backgroundColor")
return `\\color{${fontColor}}\\bbox[${backgroundColor}]{${equation}}`
}

/**
* Render function to insert image form of the selected equation into current editor
*
Expand All @@ -183,7 +189,7 @@ function renderEntry(renderType: RenderType) {
} else {
if (displayMath.test(selection)) {
// Remove leading $$ and trailing $$
const equation = selection.split('\n').slice(1, -1).join('\n')
const equation = setSvgColor(selection.split('\n').slice(1, -1).join('\n'))

const renderedImage =
renderType === RenderType.REMOTE
Expand All @@ -192,7 +198,7 @@ function renderEntry(renderType: RenderType) {
insertMathImage(renderedImage, selectionStart, selectionEnd, MathType.DISPLAY)
} else if (inlineMath.test(selection)) {
// Remove leading $ and trailing $
const equation = selection.slice(1, -1).trim()
const equation = setSvgColor(selection.slice(1, -1).trim())

const renderedImage =
renderType === RenderType.REMOTE
Expand Down