This commit is contained in:
xingguishuai 2025-02-09 20:02:53 +08:00
parent edab48dc00
commit e6f8e94815
8 changed files with 868 additions and 140 deletions

View file

@ -1,94 +1,6 @@
# Obsidian Sample Plugin
# Obsidian Image-share Plugin
This is a sample plugin for Obsidian (https://obsidian.md).
This image-sharing plugin for Obsidian (https://obsidian.md) allows you to share selected text as beautiful images.
This project uses TypeScript to provide type checking and documentation.
The repo depends on the latest plugin API (obsidian.d.ts) in TypeScript Definition format, which contains TSDoc comments describing what it does.
This sample plugin demonstrates some of the basic functionality the plugin API can do.
- Adds a ribbon icon, which shows a Notice when clicked.
- Adds a command "Open Sample Modal" which opens a Modal.
- Adds a plugin setting tab to the settings page.
- Registers a global click event and output 'click' to the console.
- Registers a global interval which logs 'setInterval' to the console.
## First time developing plugins?
Quick starting guide for new plugin devs:
- Check if [someone already developed a plugin for what you want](https://obsidian.md/plugins)! There might be an existing plugin similar enough that you can partner up with.
- Make a copy of this repo as a template with the "Use this template" button (login to GitHub if you don't see it).
- Clone your repo to a local development folder. For convenience, you can place this folder in your `.obsidian/plugins/your-plugin-name` folder.
- Install NodeJS, then run `npm i` in the command line under your repo folder.
- Run `npm run dev` to compile your plugin from `main.ts` to `main.js`.
- Make changes to `main.ts` (or create new `.ts` files). Those changes should be automatically compiled into `main.js`.
- Reload Obsidian to load the new version of your plugin.
- Enable plugin in settings window.
- For updates to the Obsidian API run `npm update` in the command line under your repo folder.
## Releasing new releases
- Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release.
- Update your `versions.json` file with `"new-plugin-version": "minimum-obsidian-version"` so older versions of Obsidian can download an older version of your plugin that's compatible.
- Create new GitHub release using your new version number as the "Tag version". Use the exact version number, don't include a prefix `v`. See here for an example: https://github.com/obsidianmd/obsidian-sample-plugin/releases
- Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments. Note: The manifest.json file must be in two places, first the root path of your repository and also in the release.
- Publish the release.
> You can simplify the version bump process by running `npm version patch`, `npm version minor` or `npm version major` after updating `minAppVersion` manually in `manifest.json`.
> The command will bump version in `manifest.json` and `package.json`, and add the entry for the new version to `versions.json`
## Adding your plugin to the community plugin list
- Check the [plugin guidelines](https://docs.obsidian.md/Plugins/Releasing/Plugin+guidelines).
- Publish an initial version.
- Make sure you have a `README.md` file in the root of your repo.
- Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin.
## How to use
- Clone this repo.
- Make sure your NodeJS is at least v16 (`node --version`).
- `npm i` or `yarn` to install dependencies.
- `npm run dev` to start compilation in watch mode.
## Manually installing the plugin
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.
## Improve code quality with eslint (optional)
- [ESLint](https://eslint.org/) is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code.
- To use eslint with this project, make sure to install eslint from terminal:
- `npm install -g eslint`
- To use eslint to analyze this project use this command:
- `eslint main.ts`
- eslint will then create a report with suggestions for code improvement by file and line number.
- If your source code is in a folder, such as `src`, you can use eslint with this command to analyze all files in that folder:
- `eslint .\src\`
## Funding URL
You can include funding URLs where people who use your plugin can financially support it.
The simple way is to set the `fundingUrl` field to your link in your `manifest.json` file:
```json
{
"fundingUrl": "https://buymeacoffee.com"
}
```
If you have multiple URLs, you can also do:
```json
{
"fundingUrl": {
"Buy Me a Coffee": "https://buymeacoffee.com",
"GitHub Sponsor": "https://github.com/sponsors",
"Patreon": "https://www.patreon.com/"
}
}
```
## API Documentation
See https://github.com/obsidianmd/obsidian-api

271
main.css

File diff suppressed because one or more lines are too long

203
main.ts
View file

@ -1,5 +1,6 @@
import { App, Editor, Modal, Plugin, Menu, MarkdownRenderer, Component } from 'obsidian';
import './styles.css';
import './markdown-sspai.css';
import html2canvas from 'html2canvas';
// Remember to rename these classes and interfaces!
@ -189,53 +190,177 @@ class ImageGenerator {
// 应用优化的样式
const styleSheet = document.createElement('style');
styleSheet.textContent = `
.markdown-preview-view {
letter-spacing: 0.05em;
.markdown-here-wrapper {
font-size: 16px;
line-height: 1.8em;
letter-spacing: 0.1em;
}
.markdown-preview-view h1,
.markdown-preview-view h2,
.markdown-preview-view h3 {
font-weight: 600;
line-height: 1.3;
margin: 1.2em 0 0.6em;
pre, code {
font-size: 14px;
font-family: Roboto, 'Courier New', Consolas, Inconsolata, Courier, monospace;
margin: auto 5px;
}
.markdown-preview-view h1 { font-size: 1.6em; }
.markdown-preview-view h2 { font-size: 1.4em; }
.markdown-preview-view h3 { font-size: 1.2em; }
.markdown-preview-view p {
margin: 0.8em 0;
line-height: 1.6;
code {
white-space: pre-wrap;
border-radius: 2px;
display: inline;
}
.markdown-preview-view ul,
.markdown-preview-view ol {
margin: 0.4em 0;
padding-left: 1.2em;
pre {
font-size: 15px;
line-height: 1.4em;
display: block; !important;
}
.markdown-preview-view li {
margin: 0.2em 0;
line-height: 1.5;
}
.markdown-preview-view code {
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.9em;
padding: 0.2em 0.4em;
pre code {
white-space: pre;
overflow: auto;
border-radius: 3px;
background: ${this.currentTemplate.id === 'dark' ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.06)'};
padding: 1px 1px;
display: block !important;
}
.markdown-preview-view blockquote {
margin: 1em 0;
padding: 0.2em 0 0.2em 0.8em;
border-left: 3px solid ${this.currentTemplate.id === 'dark' ? '#666' : '#ddd'};
color: ${this.currentTemplate.id === 'dark' ? '#bbb' : '#666'};
strong, b{
color: #BF360C;
}
.markdown-preview-view strong {
font-weight: 600;
color: ${this.currentTemplate.id === 'dark' ? '#fff' : '#000'};
em, i {
color: #009688;
}
.markdown-preview-view em {
font-style: normal;
border-bottom: 1px dashed ${this.currentTemplate.id === 'dark' ? '#666' : '#999'};
padding-bottom: 0.1em;
hr {
border: 1px solid #BF360C;
margin: 1.5em auto;
}
p {
margin: 1.5em 5px !important;
}
table, pre, dl, blockquote, q, ul, ol {
margin: 10px 5px;
}
ul, ol {
padding-left: 15px;
}
li {
margin: 10px;
}
li p {
margin: 10px 0 !important;
}
ul ul, ul ol, ol ul, ol ol {
margin: 0;
padding-left: 10px;
}
ul {
list-style-type: circle;
}
dl {
padding: 0;
}
dl dt {
font-size: 1em;
font-weight: bold;
font-style: italic;
}
dl dd {
margin: 0 0 10px;
padding: 0 10px;
}
blockquote, q {
border-left: 2px solid #009688;
padding: 0 10px;
color: #777;
quotes: none;
margin-left: 1em;
}
blockquote::before, blockquote::after, q::before, q::after {
content: none;
}
h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-style: bold !important;
color: #009688 !important;
text-align: center !important;
margin: 1.5em 5px !important;
padding: 0.5em 1em !important;
}
h1 {
font-size: 24px !important;
border-bottom: 1px solid #ddd !important;
}
h2 {
font-size: 20px !important;
border-bottom: 1px solid #eee !important;
}
h3 {
font-size: 18px;
}
h4 {
font-size: 16px;
}
table {
padding: 0;
border-collapse: collapse;
border-spacing: 0;
font-size: 1em;
font: inherit;
border: 0;
margin: 0 auto;
}
tbody {
margin: 0;
padding: 0;
border: 0;
}
table tr {
border: 0;
border-top: 1px solid #CCC;
background-color: white;
margin: 0;
padding: 0;
}
table tr:nth-child(2n) {
background-color: #F8F8F8;
}
table tr th, table tr td {
font-size: 16px;
border: 1px solid #CCC;
margin: 0;
padding: 5px 10px;
}
table tr th {
font-weight: bold;
color: #eee;
border: 1px solid #009688;
background-color: #009688;
}
`;
document.head.appendChild(styleSheet);

View file

@ -1,11 +1,11 @@
{
"id": "obsidian-image-share",
"id": "Image-share",
"name": "Image Share",
"version": "1.0.0",
"minAppVersion": "0.15.0",
"version": "0.0.1",
"minAppVersion": "1.18.0",
"description": "Share selected text as beautiful images",
"author": "shawn",
"authorUrl": "https://obsidian.md",
"fundingUrl": "https://obsidian.md/pricing",
"author": "Shawn",
"authorUrl": "https://full-stacker.com",
"fundingUrl": "https://full-stacker.com",
"isDesktopOnly": false
}

172
markdown-here.css Normal file
View file

@ -0,0 +1,172 @@
.markdown-here-wrapper {
font-size: 16px;
line-height: 1.8em;
letter-spacing: 0.1em;
}
pre, code {
font-size: 14px;
font-family: Roboto, 'Courier New', Consolas, Inconsolata, Courier, monospace;
margin: auto 5px;
}
code {
white-space: pre-wrap;
border-radius: 2px;
display: inline;
}
pre {
font-size: 15px;
line-height: 1.4em;
display: block; !important;
}
pre code {
white-space: pre;
overflow: auto;
border-radius: 3px;
padding: 1px 1px;
display: block !important;
}
strong, b{
color: #BF360C;
}
em, i {
color: #009688;
}
hr {
border: 1px solid #BF360C;
margin: 1.5em auto;
}
p {
margin: 1.5em 5px !important;
}
table, pre, dl, blockquote, q, ul, ol {
margin: 10px 5px;
}
ul, ol {
padding-left: 15px;
}
li {
margin: 10px;
}
li p {
margin: 10px 0 !important;
}
ul ul, ul ol, ol ul, ol ol {
margin: 0;
padding-left: 10px;
}
ul {
list-style-type: circle;
}
dl {
padding: 0;
}
dl dt {
font-size: 1em;
font-weight: bold;
font-style: italic;
}
dl dd {
margin: 0 0 10px;
padding: 0 10px;
}
blockquote, q {
border-left: 2px solid #009688;
padding: 0 10px;
color: #777;
quotes: none;
margin-left: 1em;
}
blockquote::before, blockquote::after, q::before, q::after {
content: none;
}
h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-style: bold !important;
color: #009688 !important;
text-align: center !important;
margin: 1.5em 5px !important;
padding: 0.5em 1em !important;
}
h1 {
font-size: 24px !important;
border-bottom: 1px solid #ddd !important;
}
h2 {
font-size: 20px !important;
border-bottom: 1px solid #eee !important;
}
h3 {
font-size: 18px;
}
h4 {
font-size: 16px;
}
table {
padding: 0;
border-collapse: collapse;
border-spacing: 0;
font-size: 1em;
font: inherit;
border: 0;
margin: 0 auto;
}
tbody {
margin: 0;
padding: 0;
border: 0;
}
table tr {
border: 0;
border-top: 1px solid #CCC;
background-color: white;
margin: 0;
padding: 0;
}
table tr:nth-child(2n) {
background-color: #F8F8F8;
}
table tr th, table tr td {
font-size: 16px;
border: 1px solid #CCC;
margin: 0;
padding: 5px 10px;
}
table tr th {
font-weight: bold;
color: #eee;
border: 1px solid #009688;
background-color: #009688;
}

250
markdown-sspai.css Normal file
View file

@ -0,0 +1,250 @@
/* Sspai Web Theme A theme to [sspai](ssp.ai) default theme. Developed by Codegass(wchweichenhao@gmial.com) & Yves(yves@sspai.com) Download Cuto on the App Store and Google Play! */
body {
font-size: 15px;
color: #333;
background: #fff;
font-family: Helvetica, Arial, "PingFang SC", "Microsoft YaHei", "WenQuanYi Micro Hei", "tohoma,sans-serif";
margin: 0;
padding: 10%;
}
h1 {
font-size: 2.2em;
font-weight: 700;
line-height: 1.1;
padding-top: 16px;
margin-bottom: 4px;
}
h2, h3, h4, h5, h6 {
line-height: 1.5em;
margin-top: 2.2em;
margin-bottom: 4px;
}
h2 {
font-size: 1.4em;
margin: 40px 10px 20px 0;
padding-left: 9px;
border-left: 6px solid #ff7e79;
font-weight: 700;
line-height: 1.4;
}
h3 {
font-weight: 700;
font-size: 1.2em;
line-height: 1.4;
margin: 10px 0 5px;
padding-top: 10px;
}
h4 {
font-weight: 700;
text-transform: uppercase;
font-size: 1.1em;
line-height: 1.4;
margin: 10px 0 5px;
padding-top: 10px
}
h5, h6 {
font-size: .9em;
}
h5 {
font-weight: bold;
text-transform: uppercase;
}
h6 {
font-weight: normal;
color: #AAA;
}
img {
width: 100%;
border-radius: 5px;
display: block;
margin-bottom: 15px;
height: auto;
}
dl, ol, ul {
margin-top: 12px;
margin-bottom: 20px;
padding-left: 5%;
line-height: 1.8;
}
p {
margin: 0 0 20px;
padding: 0;
line-height: 1.8;
}
a {
color: #f22f27;
text-decoration: none;
}
a:hover {
color: #f55852;
text-decoration: underline;
}
a:focus {
outline-offset: -2px;
}
blockquote {
font-size: 1em;
font-style: normal;
padding: 30px 38px;
margin: 0 0 15px;
position: relative;
line-height: 1.8;
text-indent: 0;
border: none;
color: #888;
}
blockquote:before {
content: "“";
left: 12px;
top: 0;
color: #E0E0E0;
font-size: 4em;
font-family: Arial, serif;
line-height: 1em;
font-weight: 700;
position: absolute;
}
blockquote:after {
content: "”";
right: 12px;
bottom: -26px;
color: #E0E0E0;
font-size: 4em;
font-family: Arial, serif;
line-height: 1em;
font-weight: 700;
position: absolute;
bottom: -31px;
}
strong, dfn {
font-weight: 700;
}
em, dfn {
font-style: italic;
font-weight: 400;
}
del {
text-decoration: line-through;
}
/*code {font-size:90%;}*/
/*pre {text-align:left; overflow-x: scroll; color: #257fa0; background: #f6f6f6; padding: 10pt 15pt; border-radius: 3px; border: solid 1px #e2e2e2;}*/
pre {
margin: 0 0 10px;
font-size: 13px;
line-height: 1.42857;
word-break: break-all;
word-wrap: break-word;
border-radius: 4px;
white-space: pre-wrap;
display: block;
background: #f8f8f8;
padding: 10px 20px;
border: none;
margin-bottom: 25px;
color: #666;
font-family: Courier, sans-serif;
}
code {
color: #c7254e;
background-color: #f9f2f4;
border-radius: 4px;
font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
padding: 2px 4px;
font-size: 90%;
}
p>code {
color: #c7264e;
background-color: #f9f2f4;
font-size: .95em;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}
figure {
margin: 1em 0;
}
figcaption {
font-size: 0.75em;
padding: 0.5em 2em;
margin-bottom: 2em;
}
figure img {
margin-bottom: 0px;
}
hr {
margin-top: 20px;
margin-bottom: 20px;
border: 0;
border-top: 1px solid #eee;
}
ol p, ul p {
margin-bottom: 0px;
}
li {
margin-bottom: 0.75em;
margin-top: 0.75em;
}
ol#footnotes {
font-size: 0.95em;
padding-top: 1em;
margin-top: 1em;
margin-left: 0;
border-top: 1px solid #eaeaea;
counter-reset: footer-counter;
list-style: none;
color: #555;
padding-left: 5%;
margin: 20px 0;
}
ol#footnotes li {
margin-bottom: 10px;
margin-left: 16px;
font-weight: 400;
line-height: 2;
list-style-type: none;
}
ol#footnotes li:before {
content: counter(footer-counter) ". ";
counter-increment: footer-counter;
font-weight: 800;
font-size: .95em;
}
@keyframes highfade {
0% {
background-color: none;
}
20% {
background-color: yellow;
}
100% {
background-color: none;
}
}
@-webkit-keyframes highfade {
0% {
background-color: none;
}
20% {
background-color: yellow;
}
100% {
background-color: none;
}
}
a:target, ol#footnotes li:target, sup a:target {
animation-name: highfade;
animation-duration: 2s;
animation-iteration-count: 1;
animation-timing-function: ease-in-out;
-webkit-animation-name: highfade;
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease-in-out;
}
a:target {
border: 0;
outline: 0;
}

View file

@ -1,5 +1,5 @@
{
"name": "obsidian-image-share",
"name": "image-share",
"version": "1.0.0",
"description": "share text as image",
"main": "main.js",
@ -8,8 +8,8 @@
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json"
},
"keywords": [],
"author": "shawn",
"keywords": ["share","image"],
"author": "Shawn",
"license": "MIT",
"devDependencies": {
"@types/node": "^16.11.6",

View file

@ -1,3 +1,3 @@
{
"1.0.0": "0.15.0"
"0.0.1": "1.18.0"
}