mirror of
https://github.com/mayurankv/Obsidian-Code-Styler.git
synced 2026-07-22 08:10:29 +00:00
update
This commit is contained in:
parent
8e4e3e730f
commit
9b411f1a55
13 changed files with 2432 additions and 1641 deletions
22
.todo
22
.todo
|
|
@ -1,19 +1,21 @@
|
|||
Features:
|
||||
Code Referencing:
|
||||
☐ Local file reference functionality `file`
|
||||
☐ Replace dependence on
|
||||
☐ Local reference
|
||||
☐ Regex finding lines
|
||||
☐ Path by markdown links
|
||||
☐ Adjust line number in codeblock parsing for this codeblock as with other plugins
|
||||
☐ Return line number at start of file for this
|
||||
☐ Also keep repository for title
|
||||
☐ Allow links to external sites in titles
|
||||
☐ File watcher?
|
||||
☐ Github/Gitlab/Bitbucket code reference functionality `repository`
|
||||
☐ https://forum.obsidian.md/t/reference-a-git-repo/73697 (Do 3rd implementation)
|
||||
☐ `site` and `tree path` or just `file path`
|
||||
☐ `lines`
|
||||
☐ External Referencing
|
||||
☐ Update button
|
||||
☐ Automatic updating
|
||||
☐ Remove old files?
|
||||
☐ Show more info like commit, branch etc.
|
||||
☐ Non github compatibility
|
||||
☐ Allow iframe
|
||||
☐ LaTeX Functionality
|
||||
☐ Compiling and Previewing
|
||||
☐ Me
|
||||
☐ Ligatures
|
||||
☐ Nerdfonts
|
||||
|
||||
Codeblocks:
|
||||
Implementation:
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ See this project's [releases](/../../../releases).
|
|||
### Added
|
||||
|
||||
- Added markdown links and wikilinks in comments
|
||||
- Reference codeblocks for referencing local and external files
|
||||
- Markdown links, local links and html links
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ Example:
|
|||
|
||||
### References
|
||||
|
||||
To display the title as a link to another page which can be clicked or hovered over, add the `ref:` or `reference:` parameter followed by a wikilink. The title will then show as a link to the referenced note. If no `title:` parameter is given, then the wikilink note name (or alias if given) will be used as the title.
|
||||
To display the title as a link to another page which can be clicked or hovered over, add the `ref:` or `reference:` parameter followed by a wikilink or markdown link. The title will then show as a link to the referenced note or website. If no `title:` parameter is given, then the wikilink note name (or alias if given) will be used as the title.
|
||||
|
||||
Note that these links will not show up on the Graph or in Backlinks - this is an upstream issue with Obsidian. To get this resolved, please support the forum issue [here](https://forum.obsidian.md/t/api-method-to-add-link-and-have-it-parsed-into-metadatacache/72046).
|
||||
|
||||
|
|
|
|||
2473
main.js
2473
main.js
File diff suppressed because one or more lines are too long
1337
package-lock.json
generated
1337
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -52,6 +52,7 @@
|
|||
"hast": "^1.0.0",
|
||||
"hast-util-from-html": "^2.0.1",
|
||||
"hast-util-to-html": "^9.0.0",
|
||||
"request": "^2.88.2",
|
||||
"unist-util-visit-parents": "^6.0.1"
|
||||
},
|
||||
"contributors": [
|
||||
|
|
|
|||
|
|
@ -26,9 +26,8 @@ function createTitleContainer(codeblockParameters: CodeblockParameters, themeSet
|
|||
const title = codeblockParameters.title || (codeblockParameters.fold.enabled?(codeblockParameters.fold.placeholder || themeSettings.header.foldPlaceholder || FOLD_PLACEHOLDER):"");
|
||||
if (codeblockParameters.reference === "")
|
||||
titleContainer.innerText = title;
|
||||
else {
|
||||
else
|
||||
MarkdownRenderer.render(plugin.app,`[[${codeblockParameters.reference}|${title}]]`,titleContainer,sourcePath,plugin); //TODO (@mayurankv) Add links to metadata cache properly
|
||||
}
|
||||
return titleContainer;
|
||||
}
|
||||
export function createInlineOpener(inlineCodeParameters: InlineCodeParameters, languageIcons: Record<string,string>, containerClasses: Array<string> = ["code-styler-inline-opener"]): HTMLElement {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { MarkdownPreviewRenderer, Plugin, TFile } from "obsidian";
|
|||
import CodeStylerPlugin from "../main";
|
||||
import { CodeStylerTheme, EXECUTE_CODE_SUPPORTED_LANGUAGES } from "../Settings";
|
||||
import { CodeBlockArgs, getArgs } from "../External/ExecuteCode/CodeBlockArgs";
|
||||
import { getReference } from "src/Referencing";
|
||||
|
||||
export interface CodeblockParameters {
|
||||
language: string;
|
||||
|
|
@ -92,7 +93,7 @@ async function parseCodeblock(codeblockLines: Array<string>, plugin: CodeStylerP
|
|||
return null;
|
||||
const codeblockParameters = parseCodeblockParameters(parameterLine,plugin.settings.currentTheme);
|
||||
|
||||
if (isCodeblockIgnored(codeblockParameters.language,plugin.settings.processedCodeblocksWhitelist))
|
||||
if (isCodeblockIgnored(codeblockParameters.language,plugin.settings.processedCodeblocksWhitelist) && codeblockParameters.language !== "reference")
|
||||
return null;
|
||||
|
||||
return await (typeof sourcePath !== "undefined"?pluginAdjustParameters(codeblockParameters,plugin,plugins,codeblockLines,sourcePath):pluginAdjustParameters(codeblockParameters,plugin,plugins,codeblockLines));
|
||||
|
|
@ -154,7 +155,11 @@ export function parseCodeblockParameters(parameterLine: string, theme: CodeStyle
|
|||
return codeblockParameters;
|
||||
}
|
||||
async function pluginAdjustParameters(codeblockParameters: CodeblockParameters, plugin: CodeStylerPlugin, plugins: Record<string,ExternalPlugin>, codeblockLines: Array<string>, sourcePath?: string): Promise<CodeblockParameters> {
|
||||
if (codeblockParameters.language === "preview")
|
||||
if (codeblockParameters.language === "reference") {
|
||||
if (sourcePath === undefined)
|
||||
throw Error("Reference block has undefined sourcePath");
|
||||
codeblockParameters = await adjustReference(codeblockParameters, codeblockLines, sourcePath, plugin);
|
||||
} else if (codeblockParameters.language === "preview")
|
||||
codeblockParameters = await (typeof sourcePath !== "undefined"?pluginAdjustPreviewCode(codeblockParameters,plugins,codeblockLines,sourcePath):pluginAdjustPreviewCode(codeblockParameters,plugins,codeblockLines));
|
||||
else if (codeblockParameters.language === "include")
|
||||
codeblockParameters = pluginAdjustFileInclude(codeblockParameters,plugins,codeblockLines);
|
||||
|
|
@ -163,6 +168,21 @@ async function pluginAdjustParameters(codeblockParameters: CodeblockParameters,
|
|||
codeblockParameters = pluginAdjustExecuteCode(codeblockParameters,plugins,codeblockLines);
|
||||
return codeblockParameters;
|
||||
}
|
||||
async function adjustReference(codeblockParameters: CodeblockParameters, codeblockLines: Array<string>, sourcePath: string, plugin: CodeStylerPlugin): Promise<CodeblockParameters> {
|
||||
const reference = await getReference(codeblockLines, sourcePath, plugin);
|
||||
if (!codeblockParameters.lineNumbers.alwaysDisabled && !codeblockParameters.lineNumbers.alwaysEnabled) {
|
||||
codeblockParameters.lineNumbers.offset = reference.startLine - 1;
|
||||
codeblockParameters.lineNumbers.alwaysEnabled = Boolean(reference.startLine !== 1);
|
||||
}
|
||||
if (codeblockParameters.title === "")
|
||||
//TODO (@mayurankv) Set Local Title
|
||||
codeblockParameters.title = reference.external?.info?.title ?? "file title";
|
||||
if (codeblockParameters.reference === "")
|
||||
//TODO (@mayurankv) Set Local Link
|
||||
codeblockParameters.reference = reference.external?.info?.displayUrl ?? reference.external?.info?.url ?? "file uri";
|
||||
codeblockParameters.language = reference.language;
|
||||
return codeblockParameters;
|
||||
}
|
||||
async function pluginAdjustPreviewCode(codeblockParameters: CodeblockParameters, plugins: Record<string,ExternalPlugin>, codeblockLines: Array<string>, sourcePath?: string): Promise<CodeblockParameters> {
|
||||
if (plugins?.["obsidian-code-preview"]?.code && plugins?.["obsidian-code-preview"]?.analyzeHighLightLines) {
|
||||
const codePreviewParams = await plugins["obsidian-code-preview"].code(codeblockLines.slice(1,-1).join("\n"),sourcePath);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import { parseYaml } from "obsidian";
|
|||
export interface ReferenceParameters {
|
||||
filePath: string;
|
||||
language: string;
|
||||
repository?: string;
|
||||
start?: string | number | RegExp;
|
||||
end?: string | number | RegExp;
|
||||
}
|
||||
|
|
@ -13,8 +12,6 @@ interface PassedParameters {
|
|||
file?: string;
|
||||
path?: string;
|
||||
link?: string;
|
||||
repository?: string;
|
||||
repo?: string;
|
||||
language?: string;
|
||||
lang?: string;
|
||||
start?: string | number;
|
||||
|
|
@ -22,17 +19,15 @@ interface PassedParameters {
|
|||
}
|
||||
|
||||
export function parseReferenceParameters(source: string): ReferenceParameters {
|
||||
source = source.replace(/^([^:]+):(.+)\n/, "$1: $2\n");
|
||||
const passedParameters: PassedParameters = parseYaml(source);
|
||||
if (passedParameters === source)
|
||||
source = source.replace(/^([^:]+):(.+)\n/, "$1: $2\n").replace(/(?<!")\[\[(.*?)\]\](?!")/, "\"[[$1]]\"");
|
||||
let passedParameters: PassedParameters | string | null = parseYaml(source);
|
||||
if (passedParameters as string === source || passedParameters === null)
|
||||
throw Error("YAML Parse Error");
|
||||
passedParameters = passedParameters as PassedParameters;
|
||||
const filePath = passedParameters?.filePath ?? passedParameters?.file ?? passedParameters?.path ?? passedParameters?.link;
|
||||
if (filePath === undefined)
|
||||
throw Error("No file specified");
|
||||
const referenceParameters: ReferenceParameters = {filePath: filePath, language: passedParameters?.language ?? passedParameters?.lang ?? getLanguage(filePath)};
|
||||
const repository = passedParameters?.repository ?? passedParameters?.repo;
|
||||
if (repository !== undefined)
|
||||
referenceParameters.repository = repository;
|
||||
const start = getLineIdentifier(String(passedParameters.start));
|
||||
if (start !== undefined)
|
||||
referenceParameters.start = start;
|
||||
|
|
@ -62,5 +57,7 @@ function getLineIdentifier(lineIdentifier: string | undefined): RegExp | string
|
|||
}
|
||||
|
||||
function getLanguage(filePath: string): string {
|
||||
if (filePath.startsWith("[[") && filePath.endsWith("]]"))
|
||||
filePath = filePath.slice(2, -2);
|
||||
return filePath.slice((filePath.lastIndexOf(".") - 1 >>> 0) + 2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,9 +84,9 @@ export function destroyReadingModeElements(): void {
|
|||
});
|
||||
}
|
||||
|
||||
async function renderSpecificReadingSection(codeblockPreElements: Array<HTMLElement>, sourcePath: string, codeblockSectionInfo: MarkdownSectionInformation, plugin: CodeStylerPlugin) {
|
||||
export async function renderSpecificReadingSection(codeblockPreElements: Array<HTMLElement>, sourcePath: string, codeblockSectionInfo: MarkdownSectionInformation, plugin: CodeStylerPlugin) {
|
||||
const codeblocksParameters = (await parseCodeblockSource(Array.from({length: codeblockSectionInfo.lineEnd-codeblockSectionInfo.lineStart+1}, (_,num) => num + codeblockSectionInfo.lineStart).map((lineNumber)=>codeblockSectionInfo.text.split("\n")[lineNumber]),plugin,sourcePath)).codeblocksParameters;
|
||||
await remakeCodeblocks(codeblockPreElements,codeblocksParameters,sourcePath,true,false,plugin);
|
||||
await remakeCodeblocks(codeblockPreElements, codeblocksParameters, sourcePath, true, false, plugin);
|
||||
}
|
||||
async function renderSettings(codeblockPreElements: Array<HTMLElement>, sourcePath: string, plugin: CodeStylerPlugin) {
|
||||
const codeblocksParameters = (await parseCodeblockSource(sourcePath.substring(SETTINGS_SOURCEPATH_PREFIX.length).split("\n"),plugin)).codeblocksParameters;
|
||||
|
|
@ -187,7 +187,7 @@ async function getCodeblocksParameters(sourcePath: string, cache: CachedMetadata
|
|||
for (const section of cache.sections) {
|
||||
if (!editingEmbeds || section.type === "code" || section.type === "callout") {
|
||||
const parsedCodeblocksParameters = await parseCodeblockSource(fileContentLines.slice(section.position.start.line,section.position.end.line+1),plugin,sourcePath);
|
||||
if (!editingEmbeds || (editingEmbeds && parsedCodeblocksParameters?.codeblocksParameters?.[0]?.language === "reference") || parsedCodeblocksParameters.nested)
|
||||
if (!editingEmbeds || parsedCodeblocksParameters.nested)
|
||||
codeblocksParameters = codeblocksParameters.concat(parsedCodeblocksParameters.codeblocksParameters);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,41 +1,168 @@
|
|||
import { MarkdownPostProcessorContext, MarkdownRenderer, MarkdownSectionInformation, TFile, normalizePath } from "obsidian";
|
||||
import { ReferenceParameters, parseReferenceParameters } from "src/Parsing/ReferenceParsing";
|
||||
import { LOCAL_PREFIX, REFERENCE_CODEBLOCK } from "src/Settings";
|
||||
import { MarkdownPostProcessorContext, MarkdownRenderer, MarkdownSectionInformation, normalizePath, requestUrl, request } from "obsidian";
|
||||
import { parseReferenceParameters } from "src/Parsing/ReferenceParsing";
|
||||
import { EXTERNAL_REFERENCE_PATH, EXTERNAL_REFERENCE_INFO_SUFFIX, LOCAL_PREFIX, REFERENCE_CODEBLOCK } from "src/Settings";
|
||||
import CodeStylerPlugin from "src/main";
|
||||
import { renderSpecificReadingSection } from "./ReadingView";
|
||||
|
||||
export interface Reference {
|
||||
startLine: number;
|
||||
code: string;
|
||||
language: string;
|
||||
path: string;
|
||||
external?: {
|
||||
storePath: string,
|
||||
website: string,
|
||||
info: ExternalReferenceInfo;
|
||||
}
|
||||
}
|
||||
|
||||
interface ExternalReferenceInfo {
|
||||
title: string,
|
||||
url: string,
|
||||
site: string,
|
||||
datetime: string,
|
||||
rawUrl: string,
|
||||
displayUrl?: string,
|
||||
author?: string,
|
||||
repository?: string,
|
||||
path?: string,
|
||||
fileName?: string,
|
||||
refInfo?: {
|
||||
ref: string,
|
||||
type: string,
|
||||
hash: string
|
||||
}
|
||||
}
|
||||
|
||||
export async function referenceCodeblockProcessor(source: string, codeblockElement: HTMLElement, context: MarkdownPostProcessorContext, plugin: CodeStylerPlugin) {
|
||||
const codeblockSectionInfo: MarkdownSectionInformation | null = context.getSectionInfo(codeblockElement);
|
||||
if (codeblockSectionInfo === null)
|
||||
throw Error("Could not retrieve codeblock information");
|
||||
const referenceParameters = parseReferenceParameters(source);
|
||||
if (referenceParameters?.repository !== undefined) {
|
||||
// Get github file
|
||||
// Store in settings folder
|
||||
const storePath = "";
|
||||
|
||||
referenceParameters.filePath = storePath;
|
||||
}
|
||||
renderLocalFile(referenceParameters, codeblockElement, context, codeblockSectionInfo, plugin);
|
||||
const codeblockLines = [codeblockSectionInfo.text.split("\n")[codeblockSectionInfo.lineStart], ...source.split("\n")];
|
||||
if (codeblockLines[codeblockLines.length - 1] !== "")
|
||||
codeblockLines.push("");
|
||||
const reference = await getReference(codeblockLines, context.sourcePath, plugin);
|
||||
renderFile(reference, codeblockElement, context, plugin);
|
||||
renderSpecificReadingSection(Array.from(codeblockElement.querySelectorAll("pre:not(.frontmatter)")), context.sourcePath, codeblockSectionInfo, plugin);
|
||||
}
|
||||
|
||||
export async function renderLocalFile(referenceParameters: ReferenceParameters, codeblockElement: HTMLElement, context: MarkdownPostProcessorContext, codeblockSectionInfo: MarkdownSectionInformation, plugin: CodeStylerPlugin) {
|
||||
let codeblockContent: string;
|
||||
function renderFile(reference: Reference, codeblockElement: HTMLElement, context: MarkdownPostProcessorContext, plugin: CodeStylerPlugin) {
|
||||
MarkdownRenderer.render(plugin.app, reference.code, codeblockElement, context.sourcePath, plugin);
|
||||
}
|
||||
|
||||
export async function getReference(codeblockLines: Array<string>, sourcePath: string, plugin: CodeStylerPlugin): Promise<Reference> {
|
||||
const referenceParameters = parseReferenceParameters(codeblockLines.slice(1,-1).join("\n"));
|
||||
const reference: Reference = {
|
||||
code: "",
|
||||
language: referenceParameters.language,
|
||||
startLine: 1,
|
||||
path: referenceParameters.filePath,
|
||||
};
|
||||
|
||||
try {
|
||||
const vaultPath = getPath(normalizePath(referenceParameters.filePath), context.sourcePath);
|
||||
const vaultFile = this.app.vault.getAbstractFileByPath(vaultPath);
|
||||
if (!(vaultFile instanceof TFile))
|
||||
throw Error(`${vaultPath} is not a file`);
|
||||
const codeContent = (await this.app.vault.read(vaultFile)).trim();
|
||||
const parameterLine = codeblockSectionInfo.text.split("\n")[codeblockSectionInfo.lineStart].substring(REFERENCE_CODEBLOCK.length).trim();
|
||||
codeblockContent = ["```", referenceParameters.language," ",parameterLine, "\n", codeContent, "\n", "```"].join("");
|
||||
if (/^https?:\/\//.test(referenceParameters.filePath)) {
|
||||
const externalReferenceId = idExternalReference(reference.path);
|
||||
reference.external = {
|
||||
website: externalReferenceId.website,
|
||||
storePath: EXTERNAL_REFERENCE_PATH + externalReferenceId.id,
|
||||
info: {title: "", url: reference.path, site: externalReferenceId.website, datetime: String(new Date()), 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)) };
|
||||
}
|
||||
const vaultPath = getPath(referenceParameters.filePath, sourcePath, plugin);
|
||||
if (!(await plugin.app.vault.adapter.exists(vaultPath)))
|
||||
throw Error(`Local File does not exist at ${vaultPath}`);
|
||||
const codeContent = (await plugin.app.vault.adapter.read(vaultPath)).trim();
|
||||
//TODO (@mayurankv) Get starting line number
|
||||
reference.code = ["```", referenceParameters.language," ",codeblockLines[0].substring(REFERENCE_CODEBLOCK.length).trim(), "\n", codeContent, "\n", "```"].join("");
|
||||
} catch (error) {
|
||||
codeblockContent = `> [!error] ${(error instanceof Error) ? error.message : String(error)}`;
|
||||
reference.code = `> [!error] ${(error instanceof Error) ? error.message : String(error)}`;
|
||||
}
|
||||
MarkdownRenderer.render(plugin.app, codeblockContent, codeblockElement, context.sourcePath, plugin);
|
||||
return reference;
|
||||
}
|
||||
|
||||
function getPath(filePath: string, sourcePath: string): string {
|
||||
filePath = filePath.trim().replace("\\", "/");
|
||||
async function accessExternalReference(reference: Reference, plugin: CodeStylerPlugin): Promise<string> {
|
||||
try {
|
||||
if (!(await plugin.app.vault.adapter.exists(reference?.external?.storePath as string)))
|
||||
await updateExternalReference(reference, plugin);
|
||||
return reference?.external?.storePath as string;
|
||||
} catch (error) {
|
||||
throw Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function updateExternalReference(reference: Reference, plugin: CodeStylerPlugin) {
|
||||
try {
|
||||
const sourceInfo = await parseExternalReference(reference);
|
||||
const content = await request(sourceInfo.rawUrl ?? reference.path);
|
||||
await plugin.app.vault.adapter.write(reference?.external?.storePath as string, content);
|
||||
await plugin.app.vault.adapter.write(reference?.external?.storePath as string + EXTERNAL_REFERENCE_INFO_SUFFIX, JSON.stringify(sourceInfo));
|
||||
} catch(error) {
|
||||
throw Error(`Could not download file: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function parseExternalReference(reference: Reference): Promise<Partial<ExternalReferenceInfo>> {
|
||||
try {
|
||||
if (reference.external?.website === "github") {
|
||||
reference.path = (reference.path.split("?")[0]).replace(/(?<=github.com\/.*\/.*\/)raw(?=\/)/,"/blob/");
|
||||
const info = (await requestUrl({ url: reference.path, method: "GET", headers: { "Accept": "application/json", "Content-Type": "application/json" } })).json;
|
||||
return {
|
||||
title: info.title,
|
||||
rawUrl: info.payload.blob.rawBlobUrl,
|
||||
displayUrl: reference.path,
|
||||
author: info.payload.repo.ownerLogin,
|
||||
repository: info.payload.repo.name,
|
||||
path: info.payload.path,
|
||||
fileName: info.payload.blob.displayName,
|
||||
refInfo: {
|
||||
ref: info.payload.refInfo.name,
|
||||
type: info.payload.refInfo.refType,
|
||||
hash: info.payload.refInfo.currentOid
|
||||
}
|
||||
};
|
||||
} else if (reference.external?.website === "gitlab")
|
||||
//TODO (@mayurankv) Update
|
||||
return {
|
||||
title: "",
|
||||
rawUrl: "",
|
||||
};
|
||||
else if (reference.external?.website === "bitbucket")
|
||||
//TODO (@mayurankv) Update
|
||||
return {
|
||||
title: "",
|
||||
rawUrl: "",
|
||||
};
|
||||
else if (reference.external?.website === "sourceforge")
|
||||
//TODO (@mayurankv) Update
|
||||
return {
|
||||
title: "",
|
||||
rawUrl: "",
|
||||
};
|
||||
else
|
||||
//TODO (@mayurankv) Update
|
||||
return {
|
||||
title: "",
|
||||
};
|
||||
} catch (error) {
|
||||
throw Error(`Could not parse external URL: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
function idExternalReference(fileLink: string): {id: string, website: string} {
|
||||
const linkInfo = /^https?:\/\/(.+)\.com\/(.+)$/.exec(fileLink);
|
||||
if (!linkInfo?.[1] || !linkInfo?.[2])
|
||||
throw Error("No such repository could be found");
|
||||
return {id: [linkInfo[1], ...linkInfo[2].split("/")].join("-"), website: linkInfo[1]};
|
||||
}
|
||||
|
||||
function getPath(filePath: string, sourcePath: string, plugin: CodeStylerPlugin): string {
|
||||
filePath = filePath.trim();
|
||||
if (filePath.startsWith("[[") && filePath.endsWith("]]"))
|
||||
return plugin.app.metadataCache.getFirstLinkpathDest(filePath.slice(2,-2), sourcePath)?.path ?? filePath;
|
||||
filePath = filePath.replace("\\", "/");
|
||||
if (filePath.startsWith(LOCAL_PREFIX))
|
||||
return filePath.substring(2);
|
||||
else if (filePath.startsWith("./") || /^[^<:"/\\>?|*]/.test(filePath)) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { normalizePath } from "obsidian";
|
||||
|
||||
// Typing
|
||||
export type HEX = `#${string}`;
|
||||
export type CSS = `--${string}`;
|
||||
|
|
@ -585,8 +587,8 @@ export const INBUILT_THEMES: Record<string,CodeStylerTheme> = {
|
|||
export const EXAMPLE_CODEBLOCK_PARAMETERS = "python title:foo";
|
||||
export const EXAMPLE_CODEBLOCK_CONTENT = "print(\"This line is very long and should be used as an example for how the plugin deals with wrapping and unwrapping very long lines given the choice of codeblock parameters and settings.\")\nprint(\"This line is highlighted.\")";
|
||||
export const EXAMPLE_INLINE_CODE = "{python icon title:foo} print(\"This is inline code\")";
|
||||
export const EXCLUDED_LANGUAGES = "ad-*";
|
||||
export const WHITELIST_CODEBLOCKS = "run-*, reference, include";
|
||||
export const EXCLUDED_LANGUAGES = "ad-*, reference";
|
||||
export const WHITELIST_CODEBLOCKS = "run-*, include";
|
||||
|
||||
// Plugin default settings
|
||||
export const DEFAULT_SETTINGS: CodeStylerSettings = {
|
||||
|
|
@ -671,6 +673,8 @@ export const SPECIAL_LANGUAGES = ["^reference$","^preview$","^include$","^output
|
|||
export const SETTINGS_SOURCEPATH_PREFIX = "@Code-Styler-Settings:";
|
||||
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";
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Plugin, MarkdownView, WorkspaceLeaf } from "obsidian";
|
||||
|
||||
import { convertSettings, DEFAULT_SETTINGS, LANGUAGES, CodeStylerSettings, REFERENCE_CODEBLOCK } 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";
|
||||
|
|
@ -34,6 +34,9 @@ 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);
|
||||
|
||||
this.executeCodeMutationObserver = executeCodeMutationObserver; // Add execute code mutation observer
|
||||
|
||||
this.registerMarkdownCodeBlockProcessor(REFERENCE_CODEBLOCK, async (source, el, ctx) => { await referenceCodeblockProcessor(source, el, ctx, this);});
|
||||
|
|
|
|||
Loading…
Reference in a new issue