This commit is contained in:
Mayuran Visakan 2024-02-13 22:44:37 +00:00
parent 338528938c
commit 286c2178a4
12 changed files with 210 additions and 31 deletions

16
main.js

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,36 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
]
}
}

View file

@ -0,0 +1 @@
{"title":".eslintrc.json","rawUrl":"https://github.com/mayurankv/Obsidian-Code-Styler/raw/00eb0dfd4949c12cb5dc9f37e80a819cd24d42e1/.eslintrc.json","displayUrl":"https://github.com/mayurankv/Obsidian-Code-Styler/blob/00eb0dfd4949c12cb5dc9f37e80a819cd24d42e1/.eslintrc.json","author":"mayurankv","repository":"Obsidian-Code-Styler","path":".eslintrc.json","fileName":".eslintrc.json","refInfo":{"ref":"00eb0dfd4949c12cb5dc9f37e80a819cd24d42e1","type":"tree","hash":"00eb0dfd4949c12cb5dc9f37e80a819cd24d42e1"}}

View file

@ -0,0 +1,24 @@
# VSCode
.vscode
# Intellij
*.iml
.idea
# npm
node_modules
# Don't include the compiled main.js file in the repo -this should be uploaded to GitHub releases instead.
main.js
# Exclude sourcemaps
*.map
# Obsidian Data
data.json
# Exclude macOS Finder (System Explorer) View States
.DS_Store
# Local Content
local

View file

@ -0,0 +1 @@
{"title":".gitignore","rawUrl":"https://github.com/mayurankv/Obsidian-Code-Styler/raw/main/.gitignore","displayUrl":"https://github.com/mayurankv/Obsidian-Code-Styler/blob/main/.gitignore","author":"mayurankv","repository":"Obsidian-Code-Styler","path":".gitignore","fileName":".gitignore","refInfo":{"ref":"main","type":"branch","hash":"338528938c6fe221f381ae4541911b249c05d3e9"}}

View file

@ -0,0 +1,98 @@
Features:
Code Referencing:
☐ Codeblock syntax highlighting
☐ Local reference
☐ Prevent clicking links causing fold
☐ Regex finding lines
☐ File watcher?
☐ External Referencing
☐ Update button
☐ Automatic updating (set frequency in setttings an dupdate if older than that at every plugin load, manual command for updating all, manual update button)
☐ Remove old files? (check if any blocks exist requiring it, if not delete it - how to do this?)
☐ Add colours to settings
☐ Update settings converter to reflect
☐ Non github compatibility
☐ Allow iframe
☐ LaTeX Functionality
☐ Compiling and Previewing
☐ Me
☐ Ligatures
☐ Nerdfonts
Codeblocks:
Implementation:
☐ Folding Fade #128
☐ Indented Codeblocks not properly parsed (i.e. 4\t code) #7
☐ List codeblocks not indented properly #13
☐ Edit Mode Line Wrapping #12
☐ Command to select all text in codeblock #75
☐ Hanging Indents #109
☐ Reading Mode Section Code Folding #110
☐ Automatic Link Updating #204
☐ Alternative Fold Toggler Button at bottom of Codeblock #129
☐ Remember and Sync Fold State #126
Prettification:
☐ Change token colours
☐ Match in both live preview and reading mode?
☐ Codeblock Shadow #25
☐ Codeblock Border #24
☐ Retain some styling in source mode #74
Long Term:
☐ Edit Mode Folding Transitions #11
☐ Terminal Appearance #9
Inline Code:
☐ Add copy button via settings and parameter #88
General:
Improvements:
☐ Error Handling
☐ Colors #210
Settings:
☐ Always display inline code #35
☐ Settings Improvements #124
Plugin Compatibility:
Execute Code:
☐ `run-*` codeblocks not styled #27
☐ Better Compatibility with Execute Code Parameters #98
Dataview:
☐ Dataview created codeblocks #10
Tasks:
☐ Check if conflict
Bugs:
Major Bugs:
☐ Inline code regex parsing #208 #212
☐ Active Line Highlight not working #207
☐ Editing Source Mode Issue? #198
☐ Performance Issues #91
Minor Bugs:
☐ Hovering over copy button in specific position causes it to glitch in and out
☐ Imperfect gutter margins #17
☐ Copy and Paste in Reading Mode retains line numbers, header and icons #23
☐ In reading mode, folding from uncollapsed to collapsed, but interrupting the fold by unfolding causes a non-smooth transition #65
☐ Editing Mode Folded Codeblock Issues #67
Testing:
☐ Set up unit Tests #120
Documentation:
☐ Proper documentation #14
☐ `throw Error` s instead of `return`
☐ Use docstrings and better commenting #119
☐ Add test vault #15
☐ Notes for each feature
Device Compatibility:
Phone:
☐ Phone version working badly #20 #99 #151
Upstream:
☐ Links don't show up in metadata #203
☐ High DPI Flicker on Collapse #18
☐ Instant Reading Mode Updates #16

View file

@ -0,0 +1 @@
{"title":".todo","rawUrl":"https://github.com/mayurankv/Obsidian-Code-Styler/raw/main/.todo","displayUrl":"https://github.com/mayurankv/Obsidian-Code-Styler/blob/main/.todo","author":"mayurankv","repository":"Obsidian-Code-Styler","path":".todo","fileName":".todo","refInfo":{"ref":"main","type":"branch","hash":"338528938c6fe221f381ae4541911b249c05d3e9"}}

View file

@ -1,9 +1,8 @@
import { LANGUAGE_NAMES, CodeStylerThemeSettings, FOLD_PLACEHOLDER, BRANCH_ICON, COMMIT_ICON } from "./Settings";
import { LANGUAGE_NAMES, CodeStylerThemeSettings, FOLD_PLACEHOLDER, GIT_ICONS } from "./Settings";
import { CodeblockParameters, Highlights } from "./Parsing/CodeblockParsing";
import { InlineCodeParameters } from "./Parsing/InlineCodeParsing";
import { MarkdownRenderer } from "obsidian";
import CodeStylerPlugin from "./main";
import { ExternalReferenceInfo } from "./Parsing/ReferenceParsing";
export function createHeader(codeblockParameters: CodeblockParameters, themeSettings: CodeStylerThemeSettings, sourcePath: string, plugin: CodeStylerPlugin): HTMLElement {
const headerContainer = createDiv();
@ -18,7 +17,7 @@ export function createHeader(codeblockParameters: CodeblockParameters, themeSett
}
headerContainer.appendChild(createTitleContainer(codeblockParameters, themeSettings, sourcePath, plugin));
if (codeblockParameters?.externalReference) //TODO (@mayurankv) Add settings toggle
headerContainer.appendChild(createExternalReferenceContainer(codeblockParameters, themeSettings, plugin));
headerContainer.appendChild(createExternalReferenceContainer(codeblockParameters, themeSettings));
if (false) //TODO (@mayurankv) Add settings toggle
headerContainer.appendChild(createExecuteCodeContainer(codeblockParameters, themeSettings, plugin));
} else
@ -36,17 +35,28 @@ function createTitleContainer(codeblockParameters: CodeblockParameters, themeSet
MarkdownRenderer.render(plugin.app,`[[${codeblockParameters.reference}|${title}]]`,titleContainer,sourcePath,plugin); //TODO (@mayurankv) Add links to metadata cache properly
return titleContainer;
}
function createExternalReferenceContainer(codeblockParameters: CodeblockParameters, themeSettings: CodeStylerThemeSettings, plugin: CodeStylerPlugin): HTMLElement {
function createExternalReferenceContainer(codeblockParameters: CodeblockParameters, themeSettings: CodeStylerThemeSettings): HTMLElement {
//TODO (@mayurankv) Add theme settings to conditionally set sections
const externalReferenceContainer = createDiv({ cls: "code-styler-header-external-reference" });
externalReferenceContainer.appendChild(createDiv({cls: "external-reference-repo", text: codeblockParameters?.externalReference?.author+"/"+codeblockParameters?.externalReference?.repository}));
const refIcon = createDiv({ cls: "external-reference-ref-icon" });
if (codeblockParameters?.externalReference?.refInfo?.type === "branch")
refIcon.innerHTML = plugin.gitIcons["branch"];
refIcon.innerHTML = GIT_ICONS["branch"];
else if (codeblockParameters?.externalReference?.refInfo?.type === "tree")
refIcon.innerHTML = plugin.gitIcons["commit"];
refIcon.innerHTML = GIT_ICONS["commit"];
else
refIcon.innerHTML = plugin.gitIcons["branch"];
refIcon.innerHTML = GIT_ICONS["branch"];
// refIcon.innerHTML = "<svgxmlns=\"http://www.w3.org/2000/svg\"viewBox=\"00100100\"><style>svg{font-family:'code-styler-nerdfon';font-size:50px;fill:black;}</style>&#xe0a0;</svg>";
// refIcon.innerHTML = `<svgxmlns="http://www.w3.org/2000/svg><style>
// @font-face{
// font-family:'MesloLGLDZNerdFont-Regular';
// src:url('https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/Meslo/L-DZ/Regular/MesloLGLDZNerdFont-Regular.ttf') format('ttf');
// }
// text{
// font-family:'MesloLGLDZNerdFont-Regular';
// font-size:50px;
// }
// </style>&#xe0a0;</svg>`;
externalReferenceContainer.appendChild(refIcon);
externalReferenceContainer.appendChild(createDiv({cls: "external-reference-ref", text: codeblockParameters?.externalReference?.refInfo?.ref as string}));
return externalReferenceContainer;

View file

@ -673,11 +673,10 @@ export const LOCAL_PREFIX = "@/";
export const REFERENCE_CODEBLOCK = "reference";
export const EXTERNAL_REFERENCE_PATH = ".obsidian/plugins/code-styler/reference-files/";
export const EXTERNAL_REFERENCE_INFO_SUFFIX = "-info.json";
export const GIT_ICONS: {[key: string]: string} = {
"branch": "<svg xmlns=\"http://www.w3.org/2000/svg\"viewBox=\"00100100\"><style>@font-face{font-family:'MesloLGLDZNerdFont-Regular';src:url('https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/Meslo/L-DZ/Regular/MesloLGLDZNerdFont-Regular.ttf')format('ttf');}text{font-family:'MesloLGLDZNerdFont-Regular';font-size:50px;fill:black;}</style>&#xe0a0;</svg>";
"commit": "<svg xmlns=\"http://www.w3.org/2000/svg\"viewBox=\"00100100\"><style>@font-face{font-family:'MesloLGLDZNerdFont-Regular';src:url('https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/Meslo/L-DZ/Regular/MesloLGLDZNerdFont-Regular.ttf')format('ttf');}text{font-family:'MesloLGLDZNerdFont-Regular';font-size:50px;fill:black;}</style>&#xe729;</svg>";
}
// `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-git-branch"><line x1="6" x2="6" y1="3" y2="15"/><circle cx="18" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><path d="M18 9a9 9 0 0 1-9 9"/></svg>`;
export const GIT_ICONS: { [key: string]: string } = {
"branch": "&#xe0a0;",
"commit": "&#xeafc",
};
const PRISM_LANGUAGES: {[key: string]: string} = { // Prism Languages: https://prismjs.com/plugins/show-language/
// "none": "Plain text", // NOTE: Obsidian uses this for codeblocks without language names

View file

@ -44,6 +44,11 @@ body {
--copy-code-header-right-margin: calc(3 * var(--header-button-spacing));
}
@font-face {
font-family: code-styler-nerdfont;
src: url('https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/MesloLGS%20NF%20Regular.ttf') format('truetype');
}
/** Pre elements */
.code-styler-pre-parent{
margin-bottom: 16px;
@ -238,7 +243,7 @@ body .code-styler-header-container:not(:has( .code-styler-header-language-tag))
}
.code-styler-header-external-reference > div {
padding-left: 6px;
font-size: var(--font-adaptive-smallest, xx-small);
font-size: var(--font-smallest, xx-small);
}
div.external-reference-repo {
color: var(--code-styler-external-reference-repo-color, cyan);
@ -246,6 +251,7 @@ div.external-reference-repo {
div.external-reference-ref,
div.external-reference-ref-icon {
color: var(--code-styler-external-reference-ref-color, pink);
font-family: code-styler-nerdfont, menlo, var(--font-monospace);
}
div:has(> img.code-styler-icon) {
display: inline-flex;

View file

@ -1,6 +1,6 @@
import { Plugin, MarkdownView, WorkspaceLeaf } from "obsidian";
import { convertSettings, DEFAULT_SETTINGS, LANGUAGES, CodeStylerSettings, REFERENCE_CODEBLOCK, EXTERNAL_REFERENCE_PATH, GIT_ICONS } from "./Settings";
import { convertSettings, DEFAULT_SETTINGS, LANGUAGES, CodeStylerSettings, REFERENCE_CODEBLOCK, EXTERNAL_REFERENCE_PATH } from "./Settings";
import { SettingsTab } from "./SettingsTab";
import { removeStylesAndClasses, updateStyling } from "./ApplyStyling";
import { createCodeblockCodeMirrorExtensions, editingDocumentFold } from "./EditingView";
@ -11,7 +11,6 @@ export default class CodeStylerPlugin extends Plugin {
settings: CodeStylerSettings;
executeCodeMutationObserver: MutationObserver;
languageIcons: Record<string,string>;
gitIcons: Record<string,string>;
sizes: {
font: string;
zoom: string;
@ -29,11 +28,7 @@ export default class CodeStylerPlugin extends Plugin {
if (LANGUAGES[key]?.icon)
result[key] = URL.createObjectURL(new Blob([`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32">${LANGUAGES[key].icon}</svg>`], { type: "image/svg+xml" }));
return result;
}, {});
this.gitIcons = Object.keys(GIT_ICONS).reduce((result: { [key: string]: string }, key: string) => {
result[key] = URL.createObjectURL(new Blob([GIT_ICONS[key]], { type: "image/svg+xml" }));
return result;
}, {});
},{});
this.sizes = {
font: document.body.getCssPropertyValue("--font-text-size"),
zoom: document.body.getCssPropertyValue("--zoom-factor"),
@ -116,8 +111,6 @@ export default class CodeStylerPlugin extends Plugin {
destroyReadingModeElements();
for (const url of Object.values(this.languageIcons)) // Unload icons
URL.revokeObjectURL(url);
for (const url of Object.values(this.gitIcons)) // Unload icons
URL.revokeObjectURL(url);
console.log("Unloaded plugin: Code Styler");
}

File diff suppressed because one or more lines are too long