Merge pull request #5 from Alddar/dev

Merge dev to main
This commit is contained in:
Ondřej Závodný 2023-08-22 10:32:27 +02:00 committed by GitHub
commit ff3acb5b6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 2804 additions and 82 deletions

2842
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -6,20 +6,28 @@
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json"
"version": "node version-bump.mjs && git add manifest.json versions.json",
"commit": "cz"
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"@codemirror/language": "^6.8.0",
"@types/node": "^16.11.6",
"@types/node": "^16.111.6",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"commitizen": "^4.3.0",
"cz-conventional-changelog": "^3.3.0",
"esbuild": "0.17.3",
"obsidian": "latest",
"tslib": "2.4.0",
"typescript": "4.7.4"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}

View file

@ -10,7 +10,13 @@ export class CopyWidget extends WidgetType {
const icon = createSpan({cls: "copy-to-clipboard-icon", text: " 📋"})
icon.onclick = (event) => {
const textToCopy = (event.target as HTMLElement)?.parentNode?.querySelector('.cm-inline-code:not(.cm-formatting)')?.innerHTML
const element = (event.target as HTMLElement)
let previousElement = element.previousElementSibling
while(previousElement && !previousElement.matches('.cm-inline-code:not(.cm-formatting)')) {
previousElement = previousElement.previousElementSibling
}
const textToCopy = previousElement?.innerHTML
if(textToCopy) {
navigator.clipboard.writeText(textToCopy)
new Notice(`Copied '${textToCopy}' to clipboard!`);

View file

@ -1,8 +1,30 @@
import { Plugin } from 'obsidian';
import { Notice, Plugin } from 'obsidian';
import { copyPlugin as copyInlineCodePlugin } from './copy-inline-code-view-plugin';
export default class CopyInlineCodePlugin extends Plugin {
async onload() {
this.registerEditorExtension([copyInlineCodePlugin]);
this.registerMarkdownPostProcessor((element, context) => {
const inlineCodes = element.querySelectorAll("*:not(pre) > code");
inlineCodes.forEach(code => {
if(code.querySelector('span.copy-to-clipboard-icon')) {
return
}
const icon = createSpan({cls: "copy-to-clipboard-icon", text: " 📋"})
const textToCopy = code.textContent
icon.onclick = () => {
if(textToCopy) {
navigator.clipboard.writeText(textToCopy)
new Notice(`Copied '${textToCopy}' to clipboard!`);
}
}
code.appendChild(icon)
})
})
}
}