This commit is contained in:
Mayuran Visakan 2024-02-20 15:51:56 +00:00
parent 4ffdba811e
commit 64dd012fd5
17 changed files with 123 additions and 155 deletions

View file

@ -1,39 +1,47 @@
{
"env": {
"browser": true,
"env": {
"browser": true,
"node": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:json/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"json"
],
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
]
}
],
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
}
}

5
.gitignore vendored
View file

@ -1,5 +1,5 @@
# VSCode
.vscode
.vscode
# Intellij
*.iml
@ -22,3 +22,6 @@ data.json
# Local Content
local
# Plugin Downloaded Files
reference-files

19
.todo
View file

@ -1,20 +1,18 @@
Features:
Other:
☐ Embed other online markdown files?
Code Referencing:
☐ Local reference
☐ Embed other online markdown files? (@low)
☐ Local reference (@low)
☐ Prevent clicking reading mode external links causing fold (@low)
☐ File watcher? (@low)
☐ File watcher? Or refresh button? (@low)
☐ External Referencing
☐ base64 encode and bundle font (check license) (@low)
☐ base64 encode and bundle font (check license)
☐ Update button (@medium)
☐ Update inplace
☐ 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 (@medium)
☐ Update settings converter to reflect
☐ Non github compatibility (@low)
☐ Non github compatibility
☐ finish gitlab
☐ gitlab based things
☐ https://foss.heptapod.net/mercurial/tortoisehg/thg/-/blob/branch/stable/COPYING.txt?ref_type=heads
@ -22,8 +20,8 @@ Features:
☐ sourceforge
☐ Allow iframe (@low)
☐ LaTeX Functionality (@low)
☐ Compiling and Previewing
☐ Me
☐ Compiling and Previewing (@low)
☐ Me (@low)
☐ Ligatures (@low)
☐ Nerdfonts (@low)
@ -76,7 +74,6 @@ Features:
Bugs:
Major Bugs:
☐ Inline code regex parsing #208 #212
☐ Active Line Highlight not working #207
☐ Editing Source Mode Issue? #198
☐ Performance Issues #91
@ -100,7 +97,7 @@ Documentation:
Device Compatibility:
Phone:
☐ Phone version working badly #20 #99 #151
☐ Phone version working badly #20 #151
Upstream:
☐ Links don't show up in metadata #203

View file

@ -24,6 +24,8 @@ See this project's [releases](/../../../releases).
- Reference codeblocks for referencing local and external files
- Markdown links, local links and html links
- Syntax Highlighting
- YAML frontmatter Syntax Highlighting in source mode
### Changed

18
External Referencing.todo Normal file
View file

@ -0,0 +1,18 @@
# To Release - https://forum.obsidian.md/t/reference-a-git-repo/73697/11
☐ Update
☐ Update button
☐ Get codeblock settings
☐ Automatic Updating All
☐ Frequency: "Never", "On Load", "Frequency"
☐ Command to Update All
☐ Implementation: Check if any files are outdated, if so, update them
☐ How to know if file is outdated?
☐ Removing Files
☐ No reference block, remove files
☐ Occur on plugin load
☐ 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?)
☐ Gitlab compatibility
☐ Add colours to settings
☐ Update settings converter to reflect
☐ base64 encode and bundle font (check license)

23
main.js

File diff suppressed because one or more lines are too long

View file

@ -1,23 +0,0 @@
# vscode
.vscode
# Intellij
*.iml
.idea
# npm
node_modules
# Don't include the compiled main.js file in the repo.
# They should be uploaded to GitHub releases instead.
main.js
# Exclude sourcemaps
*.map
# obsidian
data.json
# Exclude macOS Finder (System Explorer) View States
.DS_Store
*.log

View file

@ -1 +0,0 @@
{"title":".gitignore","rawUrl":"https://github.com/twibiral/obsidian-execute-code/raw/master/.gitignore","datetime":"2024-02-14 05:57","displayUrl":"https://github.com/twibiral/obsidian-execute-code/blob/master/.gitignore","author":"twibiral","repository":"obsidian-execute-code","path":".gitignore","fileName":".gitignore","refInfo":{"ref":"master","type":"branch","hash":"6ee175e5cd802eafe034d6a9c68d39d831139818"}}

View file

@ -9,7 +9,7 @@ import { CodeblockParameters, parseCodeblockParameters, testOpeningLine, trimPar
import { InlineCodeParameters, parseInlineCode } from "./Parsing/InlineCodeParsing";
import { createHeader, createInlineOpener, getLanguageIcon, getLineClass, isHeaderHidden } from "./CodeblockDecorating";
import CodeStylerPlugin from "./main";
import { addReferenceSyntaxHighlight, addYamlFrontmatterSyntaxHighlighting } from "./SyntaxHighlighting";
import { addReferenceSyntaxHighlight } from "./SyntaxHighlighting";
interface SettingsState {
excludedLanguages: string;

View file

@ -36,7 +36,7 @@ export interface ExternalReferenceInfo {
ref: string;
type: string;
hash: string;
}
};
}
interface PassedParameters {
@ -84,7 +84,7 @@ export async function parseExternalReference(reference: Reference): Promise<Part
ref: info.payload.refInfo.name,
type: info.payload.refInfo.refType,
hash: info.payload.refInfo.currentOid
}
},
};
} else if (reference.external?.website === "gitlab") {
reference.path = (reference.path.split("?")[0]).replace(/(?<=gitlab.com\/.*\/.*\/)raw(?=\/)/, "blob");
@ -103,7 +103,7 @@ export async function parseExternalReference(reference: Reference): Promise<Part
ref: "", //TODO (@mayurankv) Parse from url
type: "", //TODO (@mayurankv) Parse from url
hash: info.last_commit_sha
}
},
};
} else if (reference.external?.website === "bitbucket") {
//TODO (@mayurankv) Update

View file

@ -1,6 +1,6 @@
import { MarkdownPostProcessorContext, MarkdownRenderer, MarkdownSectionInformation, normalizePath, request } from "obsidian";
import { Reference, getLineLimits, parseExternalReference, parseReferenceParameters } from "src/Parsing/ReferenceParsing";
import { EXTERNAL_REFERENCE_PATH, EXTERNAL_REFERENCE_INFO_SUFFIX, LOCAL_PREFIX, REFERENCE_CODEBLOCK } from "src/Settings";
import { EXTERNAL_REFERENCE_PATH, EXTERNAL_REFERENCE_INFO_SUFFIX, LOCAL_PREFIX, REFERENCE_CODEBLOCK, EXTERNAL_REFERENCE_CACHE } from "src/Settings";
import CodeStylerPlugin from "src/main";
import { renderSpecificReadingSection } from "./ReadingView";
@ -40,8 +40,8 @@ export async function getReference(codeblockLines: Array<string>, sourcePath: st
storePath: plugin.app.vault.configDir + EXTERNAL_REFERENCE_PATH + externalReferenceId.id,
info: {title: "", url: reference.path, site: externalReferenceId.website, datetime: "", rawUrl: reference.path},
};
referenceParameters.filePath = await accessExternalReference(reference, plugin);
reference.external.info = { ...reference.external.info, ...JSON.parse(await plugin.app.vault.adapter.read(reference.external.storePath + EXTERNAL_REFERENCE_INFO_SUFFIX)) };
referenceParameters.filePath = await accessExternalReference(reference, externalReferenceId.id, sourcePath, plugin);
reference.external.info = {...reference.external.info, ...JSON.parse(await plugin.app.vault.adapter.read(reference.external.storePath + EXTERNAL_REFERENCE_INFO_SUFFIX))};
}
const vaultPath = getPath(referenceParameters.filePath, sourcePath, plugin);
if (referenceParameters.filePath.startsWith("[[") && referenceParameters.filePath.endsWith("]]"))
@ -58,10 +58,18 @@ export async function getReference(codeblockLines: Array<string>, sourcePath: st
return reference;
}
async function accessExternalReference(reference: Reference, plugin: CodeStylerPlugin): Promise<string> {
async function accessExternalReference(reference: Reference, id: string, sourcePath: string, plugin: CodeStylerPlugin): Promise<string> {
try {
if (!(await plugin.app.vault.adapter.exists(reference?.external?.storePath as string)))
await updateExternalReference(reference, plugin);
const cache = JSON.parse(await plugin.app.vault.adapter.read(plugin.app.vault.configDir + EXTERNAL_REFERENCE_CACHE));
if (!cache[id].sourcePaths.includes(sourcePath)) {
if (!cache?.[id])
cache[id] = {sourcePaths: [sourcePath]};
else
cache[id].sourcePaths.push(sourcePath);
await plugin.app.vault.adapter.write(plugin.app.vault.configDir + EXTERNAL_REFERENCE_CACHE, JSON.stringify(cache));
}
return reference?.external?.storePath as string;
} catch (error) {
throw Error(error);

View file

@ -672,6 +672,7 @@ export const SETTINGS_SOURCEPATH_PREFIX = "@Code-Styler-Settings:";
export const LOCAL_PREFIX = "@/";
export const REFERENCE_CODEBLOCK = "reference";
export const EXTERNAL_REFERENCE_PATH = "/plugins/code-styler/reference-files/";
export const EXTERNAL_REFERENCE_CACHE = EXTERNAL_REFERENCE_PATH + "cache.json";
export const EXTERNAL_REFERENCE_INFO_SUFFIX = "-info.json";
export const GIT_ICONS: { [key: string]: string } = {
"branch": "&#xe0a0;",

View file

@ -27,7 +27,7 @@ function removeMode(modeName: string) {
}
export function addReferenceSyntaxHighlight(CodeMirror: typeof window.CodeMirror) {
CodeMirror.defineMode("reference", function(config, parserConfig) {
CodeMirror.defineMode("reference", function(config, _parserConfig) {
const keyPattern = /^([a-zA-Z0-9_-]+)\s*(?=:)/;
const valuePattern = /^(:?(\s*(?:"(?:\\.|[^"])*"|\S+))?)/;
return {
@ -74,61 +74,3 @@ export function addReferenceSyntaxHighlight(CodeMirror: typeof window.CodeMirror
});
CodeMirror.defineMIME("text/reference", "reference");
}
export function addYamlFrontmatterSyntaxHighlighting(CodeMirror: typeof window.CodeMirror) {
const START = 0, FRONTMATTER = 1, BODY = 2;
CodeMirror.defineMode("yaml-frontmatter", function(config, parserConfig) {
const yamlMode = CodeMirror.getMode(config, "yaml");
console.log(yamlMode);
const innerMode = CodeMirror.getMode(config, parserConfig?.base ?? "markdown");
function curMode(state) {
return state.state == BODY ? innerMode : yamlMode;
}
return {
startState: () => {
return {
state: START,
inner: CodeMirror.startState(yamlMode)
};
},
copyState: (state) => {
return {
state: state.state,
// @ts-expect-error Hidden Method
inner: CodeMirror.copyState(curMode(state), state.inner)
};
},
token: (stream, state) => {
if (state.state == START) {
if (stream.match(/---/, false)) {
state.state = FRONTMATTER;
return yamlMode.token(stream, state.inner);
} else {
state.state = BODY;
state.inner = CodeMirror.startState(innerMode);
return innerMode.token(stream, state.inner);
}
} else if (state.state == FRONTMATTER) {
const end = stream.sol() && stream.match(/(---|\.\.\.)/, false);
const style = yamlMode.token(stream, state.inner);
if (end) {
state.state = BODY;
state.inner = CodeMirror.startState(innerMode);
}
return style;
} else {
return innerMode.token(stream, state.inner);
}
},
innerMode: (state) => {
return {mode: curMode(state), state: state.inner};
},
blankLine: (state) => {
const mode = curMode(state);
if (mode.blankLine) return mode.blankLine(state.inner);
}
};
});
CodeMirror.defineMIME("text/yaml-frontmatter", "yaml-frontmatter");
}

View file

@ -264,15 +264,15 @@ pre.code-styler-pre .code-styler-header-external-reference > button {
}
div.external-reference-repo,
div.external-reference-repo-icon {
color: var(--code-styler-external-reference-repo-color, cyan);
color: var(--code-styler-external-reference-repo-colour, cyan);
}
div.external-reference-ref,
div.external-reference-ref-icon {
color: var(--code-styler-external-reference-ref-color, pink);
color: var(--code-styler-external-reference-ref-colour, pink);
}
div.external-reference-timestamp,
div.external-reference-timestamp-icon {
color: var(--code-styler-external-reference-timestamp-color, yellow);
color: var(--code-styler-external-reference-timestamp-colour, grey);
}
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 } from "./Settings";
import { convertSettings, DEFAULT_SETTINGS, LANGUAGES, CodeStylerSettings, REFERENCE_CODEBLOCK, EXTERNAL_REFERENCE_PATH, EXTERNAL_REFERENCE_CACHE } from "./Settings";
import { SettingsTab } from "./SettingsTab";
import { removeStylesAndClasses, updateStyling } from "./ApplyStyling";
import { createCodeblockCodeMirrorExtensions, editingDocumentFold } from "./EditingView";
@ -35,8 +35,10 @@ export default class CodeStylerPlugin extends Plugin {
zoom: document.body.getCssPropertyValue("--zoom-factor"),
};
if (!(await this.app.vault.adapter.exists(EXTERNAL_REFERENCE_PATH))) // Create folder for external references
await this.app.vault.adapter.mkdir(EXTERNAL_REFERENCE_PATH);
if (!(await this.app.vault.adapter.exists(EXTERNAL_REFERENCE_PATH))) {// Create folder for external references
await this.app.vault.adapter.mkdir(this.app.vault.configDir + EXTERNAL_REFERENCE_PATH);
await this.app.vault.adapter.write(this.app.vault.configDir + EXTERNAL_REFERENCE_CACHE, JSON.stringify({}));
}
this.executeCodeMutationObserver = executeCodeMutationObserver; // Add execute code mutation observer

File diff suppressed because one or more lines are too long

View file

@ -10,7 +10,7 @@
"moduleResolution": "node",
"importHelpers": true,
"isolatedModules": true,
"strictNullChecks": true,
"strictNullChecks": true,
"lib": [
"DOM",
"ES5",
@ -19,6 +19,6 @@
]
},
"include": [
"**/*.ts",
"**/*.ts"
]
}