Fix formatting and update Chinese docs for custom attributes PR

- Convert spaces to tabs for consistent indentation
- Fix typos in comments (Wheteher -> Whether, attribues -> attributes)
- Add missing newline at EOF in types.ts
- Add space before parenthesis in if statement
- Remove AI translation disclaimer comment
- Fix incomplete Chinese translation for useCustomAttributes description
- Add custom attributes section and settings to README_CN.md
This commit is contained in:
Ke Yan 2026-05-09 21:58:46 +08:00
parent afd858c47e
commit 0e11a8439b
6 changed files with 46 additions and 36 deletions

View file

@ -10,6 +10,7 @@
- 支持自定义图片宽度
- 支持自定义图片保存路径(如 `./assets`
- 可选择是否包含 alt 属性
- 支持自定义 HTML 属性(如自定义 class 或样式)
- 粘贴时可选择显示通知
## 为什么使用 HTML 格式?
@ -48,12 +49,22 @@ HTML 格式的图片标签比 Markdown 或 Obsidian 的 wikilink 格式更广泛
<img src="image_1234567890.jpg" width="auto" alt="image_1234567890.jpg">
```
### 关于自定义属性
您可以启用"使用自定义属性"来完全自定义 HTML 属性(如自定义 class 或 CSS 变量),启用后将忽略图片宽度和 alt 属性设置。使用此功能可以生成如下标签:
```html
<img src="./assets/image_1778330017341.png" class="image-class" style="--img-width: 40vw;">
```
## 设置
- **图片宽度**:设置图片的宽度,可以是像素值(如 500px、百分比如 100%)或 auto
- **使用自定义图片路径**:启用后,图片将保存到指定路径而不是当前文件所在目录
- **自定义图片路径**:设置图片保存的路径,可以是相对路径(如 ./assets或绝对路径如 assets
- **包含 alt 属性**启用后HTML 图片标签将包含 alt 属性,有助于无障碍性和 SEO但会使标签更长
- **使用自定义属性**:启用后,使用下方指定的自定义 HTML 属性,同时忽略图片宽度和 alt 属性设置
- **自定义属性**:用于最终 HTML 输出的自定义属性字符串
- **显示通知**:粘贴图片时是否显示通知
## 安装

View file

@ -59,10 +59,9 @@ const zh: Translations = {
name: '显示通知',
desc: '粘贴图片时显示通知'
},
// Translation was provided by AI (not sure if correct)
useCustomAttributes: {
name: '使用自定义 HTML 属性',
desc: '启用后将使用下方指定的自定义 HTML 属性(如自定义 class注意这会移除图片宽度设置'
desc: '启用后将使用下方指定的自定义 HTML 属性(如自定义 class注意这会忽略图片宽度和 alt 属性设置'
},
customAttributes: {
name: '自定义属性',

View file

@ -92,12 +92,12 @@ export class Img2HtmlSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
});
// Styling settings to make the text area bigger
text.inputEl.style.resize = 'none';
text.inputEl.style.height = '100px';
text.inputEl.style.width = '100%';
});
new Setting(containerEl)
.setName(i18n.settings.showNotice.name)
.setDesc(i18n.settings.showNotice.desc)

View file

@ -12,9 +12,9 @@ export interface Img2HtmlSettings {
useCustomPath: boolean;
// Whether to include alt attribute
includeAlt: boolean;
// Wheteher to use custom HTML attribues
// Whether to use custom HTML attributes
useCustomAttributes: boolean;
// String of custom HTML attribues
// String of custom HTML attributes
customAttributes: string;
}
@ -30,3 +30,4 @@ export const DEFAULT_SETTINGS: Img2HtmlSettings = {
useCustomAttributes: false,
customAttributes: ''
};

View file

@ -48,10 +48,9 @@ export function createHtmlImgTag(
}
// Build HTML tag
if(useCustomAttributes) {
// Remove trailing and leading whitespace and prevent early closure
if (useCustomAttributes) {
const attrs = customAttributes.trim().replace(/>/g, '');
const space = attrs ? ' ': '';
const space = attrs ? ' ' : '';
return `<img src="${src}"${space}${attrs}>`;
} else if (includeAlt) {
return `<img src="${src}" width="${imageWidth}" alt="${fileName}">`;