mirror of
https://github.com/ytliu74/obsidian-pseudocode.git
synced 2026-07-22 07:40:25 +00:00
Compare commits
No commits in common. "master" and "1.6.0" have entirely different histories.
9 changed files with 19 additions and 138 deletions
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
|
|
@ -22,7 +22,7 @@ jobs:
|
|||
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
npm config set registry https://registry.npmjs.org/
|
||||
npm config set registry http://registry.npmjs.org/
|
||||
npm install
|
||||
|
||||
- name: Build
|
||||
|
|
|
|||
94
CLAUDE.md
94
CLAUDE.md
|
|
@ -1,94 +0,0 @@
|
|||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## Project Overview
|
||||
|
||||
Obsidian-Pseudocode is an Obsidian plugin that renders LaTeX-style pseudocode inside code blocks. It uses pseudocode.js to convert LaTeX algorithmic constructs to HTML, with support for math formulas via KaTeX.
|
||||
|
||||
## Build and Development Commands
|
||||
|
||||
```bash
|
||||
# Development mode with file watching
|
||||
npm run dev
|
||||
|
||||
# Production build (includes TypeScript type checking)
|
||||
npm run build
|
||||
|
||||
# Version bump
|
||||
npm run version
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
### Plugin Entry Point
|
||||
- `main.ts`: Core plugin class (`PseudocodePlugin`)
|
||||
- Registers markdown code block processor for `pseudo` language
|
||||
- Manages settings and preamble loading
|
||||
- Handles theme observer lifecycle
|
||||
|
||||
### Core Processing Flow
|
||||
1. User creates a code block with `pseudo` language specifier
|
||||
2. `pseudocodeHandler()` in main.ts processes the block:
|
||||
- Extracts inline macros (before `\begin{algorithm}`)
|
||||
- Combines with global preamble if enabled
|
||||
- Injects preamble into all math expressions (`$...$`)
|
||||
- Renders using pseudocode.js library
|
||||
- Adds export button and applies theme
|
||||
|
||||
### Key Modules
|
||||
|
||||
**src/inline_macro.ts**
|
||||
- Separates inline macro definitions from algorithm content
|
||||
- Macros before `\begin{algorithm}` are treated as preamble
|
||||
|
||||
**src/latex_translator.ts**
|
||||
- Converts unsupported LaTeX macros to KaTeX-compatible commands
|
||||
- Handles `\DeclarePairedDelimiter`, `\DeclareMathOperator*`, `\DeclareMathOperator`
|
||||
- Validates macros using KaTeX parser and converts `\newcommand` to `\renewcommand` when redefining
|
||||
|
||||
**src/export_button.ts**
|
||||
- Creates "Export to clipboard" button for each pseudocode block
|
||||
- Generates compilable LaTeX document with required packages (algorithm, algpseudocodex, amsmath)
|
||||
- Includes both global and inline macros
|
||||
|
||||
**src/theme.ts**
|
||||
- MutationObserver watches document.body for theme changes
|
||||
- Applies Obsidian theme colors (--background-primary, --text-normal) to pseudocode blocks
|
||||
- Updates .ps-root, .ps-algorithm, and border colors dynamically
|
||||
|
||||
**src/setting_tab.ts**
|
||||
- UI for plugin settings (block size, preamble path, line numbers, theme following, etc.)
|
||||
|
||||
**src/auto_complete.ts**
|
||||
- EditorSuggestor for autocomplete within `pseudo` code blocks
|
||||
|
||||
### Build System
|
||||
- Uses esbuild (config in `esbuild.config.mjs`)
|
||||
- Bundles to CommonJS format targeting ES2018
|
||||
- Main entry: `main.ts` → `main.js`
|
||||
- External: Obsidian API, CodeMirror 6, Electron
|
||||
|
||||
## Important Implementation Details
|
||||
|
||||
### Preamble System
|
||||
- Global preamble: loaded from file (default `preamble.sty`)
|
||||
- Inline preamble: defined per-block before `\begin{algorithm}`
|
||||
- Preamble is injected into every math expression in the pseudocode
|
||||
- Must reload plugin after changing global preamble file
|
||||
|
||||
### Theme Integration
|
||||
- When `followSystemTheme` is enabled, plugin observes Obsidian theme changes
|
||||
- CSS custom properties are read from document.body and applied to rendered pseudocode
|
||||
- Observer must be detached on plugin unload to prevent memory leaks
|
||||
|
||||
### Error Handling
|
||||
- Pseudocode rendering errors display in-block with ✖ symbol
|
||||
- Preamble loading failures show Notice to user
|
||||
- Invalid LaTeX in preamble is caught and logged to console
|
||||
|
||||
## Dependencies
|
||||
- `pseudocode`: Uses forked version from ytliu74/pseudocode.js#master
|
||||
- `katex`: Fixed at 0.11.1 for macro rendering
|
||||
- `obsidian`: Latest API
|
||||
- TypeScript 4.7.4 with strict null checks enabled
|
||||
|
|
@ -22,7 +22,6 @@ This is a plugin for [Obsidian](https://obsidian.md/) that allows you to render
|
|||
- Auto-completion inside `pseudo` code block. (Release 1.1.0)
|
||||
- [Preamble style (macros) customization.](#preamble-style-customization) (Release 1.2.0 & 1.5.0)
|
||||
- [Export a LaTeX file that can be compiled, including any required additional macros.](#export-to-a-compilable-latex-file) (Release 1.3.0)
|
||||
- Pseudocode block follows Obsidian theme and supports both light and dark ones. (Release 1.6.0)
|
||||
|
||||
### Future Features
|
||||
|
||||
|
|
|
|||
9
main.ts
9
main.ts
|
|
@ -30,15 +30,6 @@ export default class PseudocodePlugin extends Plugin {
|
|||
const blockDiv = el.createDiv({ cls: "pseudocode-block" });
|
||||
const blockWidth = this.settings.blockSize;
|
||||
blockDiv.style.width = `${blockWidth}em`;
|
||||
blockDiv.addEventListener("click", (event) => {
|
||||
const target = (event.target as HTMLElement | null);
|
||||
if(target && target.tagName !== 'BUTTON')
|
||||
(target
|
||||
.closest('.pseudocode-block')
|
||||
?.parentElement?.parentElement
|
||||
?.querySelector('.edit-block-button') as HTMLElement | null)
|
||||
?.click();
|
||||
});
|
||||
|
||||
// Extract inline macros
|
||||
const [inlineMacros, nonMacroLines] = extractInlineMacros(source);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "pseudocode-in-obs",
|
||||
"name": "Pseudocode",
|
||||
"version": "1.6.5",
|
||||
"version": "1.6.0",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "This is an obsidian plugin that helps to render a LaTeX-style pseudocode inside a code block.",
|
||||
"author": "Yaotian Liu",
|
||||
|
|
|
|||
8
package-lock.json
generated
8
package-lock.json
generated
|
|
@ -1,16 +1,16 @@
|
|||
{
|
||||
"name": "pseudocode-in-obs",
|
||||
"version": "1.6.4",
|
||||
"version": "1.5.4",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "pseudocode-in-obs",
|
||||
"version": "1.6.4",
|
||||
"version": "1.5.4",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"katex": "0.11.1",
|
||||
"pseudocode": "github:ytliu74/pseudocode.js#master"
|
||||
"pseudocode": "ytliu74/pseudocode.js#master"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/katex": "0.11.1",
|
||||
|
|
@ -1888,7 +1888,7 @@
|
|||
},
|
||||
"node_modules/pseudocode": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "git+ssh://git@github.com/ytliu74/pseudocode.js.git#db17188d06528b12b3279f4f1025c1a978519d1e",
|
||||
"resolved": "git+ssh://git@github.com/ytliu74/pseudocode.js.git#4ac293a977b191d66b3cba640804814651c95aaf",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/punycode": {
|
||||
|
|
|
|||
10
package.json
10
package.json
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "pseudocode-in-obs",
|
||||
"version": "1.6.5",
|
||||
"version": "1.6.0",
|
||||
"description": "This is an obsidian plugin that helps to render a LaTeX-style pseudocode inside a code block.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
@ -12,7 +12,6 @@
|
|||
"author": "",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/katex": "0.11.1",
|
||||
"@types/node": "^16.11.6",
|
||||
"@typescript-eslint/eslint-plugin": "5.29.0",
|
||||
"@typescript-eslint/parser": "5.29.0",
|
||||
|
|
@ -20,10 +19,11 @@
|
|||
"esbuild": "0.17.3",
|
||||
"obsidian": "latest",
|
||||
"tslib": "2.4.0",
|
||||
"typescript": "4.7.4"
|
||||
"typescript": "4.7.4",
|
||||
"@types/katex": "0.11.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"katex": "0.11.1",
|
||||
"pseudocode": "github:ytliu74/pseudocode.js#master"
|
||||
"pseudocode": "ytliu74/pseudocode.js#master",
|
||||
"katex": "0.11.1"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
24
styles.css
24
styles.css
|
|
@ -1399,22 +1399,12 @@ If your plugin does not need CSS, delete this file.
|
|||
text-transform: none;
|
||||
}
|
||||
|
||||
.ps-root {
|
||||
font-family: KaTeX_Main, "Times New Roman", Times, serif;
|
||||
font-weight: 400;
|
||||
font-variant: normal;
|
||||
font-style: normal;
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
.ps-comment {
|
||||
font-family: KaTeX_Main, "Times New Roman", Times, serif;
|
||||
font-weight: 400;
|
||||
font-variant: normal;
|
||||
font-style: italic;
|
||||
text-transform: none;
|
||||
opacity: 70%;
|
||||
float: right;
|
||||
.ps-root .ps-comment {
|
||||
font-family: KaTeX_Main, "Times New Roman", Times, serif;
|
||||
font-weight: 400;
|
||||
font-variant: normal;
|
||||
font-style: normal;
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
.ps-root .ps-linenum {
|
||||
|
|
@ -1478,4 +1468,4 @@ If your plugin does not need CSS, delete this file.
|
|||
background-color: white;
|
||||
opacity: 1;
|
||||
color: black;
|
||||
}
|
||||
}
|
||||
|
|
@ -32,10 +32,5 @@
|
|||
"1.5.6": "0.15.0",
|
||||
"1.5.7": "0.15.0",
|
||||
"1.5.8": "0.15.0",
|
||||
"1.6.0": "0.15.0",
|
||||
"1.6.1": "0.15.0",
|
||||
"1.6.2": "0.15.0",
|
||||
"1.6.3": "0.15.0",
|
||||
"1.6.4": "0.15.0",
|
||||
"1.6.5": "0.15.0"
|
||||
"1.6.0": "0.15.0"
|
||||
}
|
||||
Loading…
Reference in a new issue