Skip to content

Commit 2e9f8da

Browse files
committed
fix unnecessary eslint-disable
1 parent 1a9c2b3 commit 2e9f8da

File tree

5 files changed

+9
-12
lines changed

5 files changed

+9
-12
lines changed

web_src/js/features/comp/EditorUpload.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ async function handleUploadFiles(editor: CodeMirrorEditor | TextareaEditor, drop
114114

115115
export function removeAttachmentLinksFromMarkdown(text: string, fileUuid: string) {
116116
text = text.replace(new RegExp(`!?\\[([^\\]]+)\\]\\(/?attachments/${fileUuid}\\)`, 'g'), '');
117-
// eslint-disable-next-line github/unescaped-html-literal
118-
text = text.replace(new RegExp(`<img[^>]+src="/?attachments/${fileUuid}"[^>]*>`, 'g'), '');
117+
text = text.replace(new RegExp(`[<]img[^>]+src="/?attachments/${fileUuid}"[^>]*>`, 'g'), '');
119118
return text;
120119
}
121120

web_src/js/markup/html2markdown.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {htmlEscape} from '../utils/html.ts';
1+
import {html, htmlRaw} from '../utils/html.ts';
22

33
type Processor = (el: HTMLElement) => string | HTMLElement | void;
44

@@ -38,11 +38,10 @@ function prepareProcessors(ctx:ProcessorContext): Processors {
3838
IMG(el: HTMLElement) {
3939
const alt = el.getAttribute('alt') || 'image';
4040
const src = el.getAttribute('src');
41-
const widthAttr = el.hasAttribute('width') ? ` width="${htmlEscape(el.getAttribute('width') || '')}"` : '';
42-
const heightAttr = el.hasAttribute('height') ? ` height="${htmlEscape(el.getAttribute('height') || '')}"` : '';
41+
const widthAttr = el.hasAttribute('width') ? htmlRaw` width="${el.getAttribute('width') || ''}"` : '';
42+
const heightAttr = el.hasAttribute('height') ? htmlRaw` height="${el.getAttribute('height') || ''}"` : '';
4343
if (widthAttr || heightAttr) {
44-
// eslint-disable-next-line github/unescaped-html-literal
45-
return `<img alt="${htmlEscape(alt)}"${widthAttr}${heightAttr} src="${htmlEscape(src)}">`;
44+
return html`<img alt="${alt}"${widthAttr}${heightAttr} src="${src}">`;
4645
}
4746
return `![${alt}](${src})`;
4847
},

web_src/js/svg.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {defineComponent, h, type PropType} from 'vue';
22
import {parseDom, serializeXml} from './utils.ts';
3+
import {html, htmlRaw} from './utils/html.ts';
34
import giteaDoubleChevronLeft from '../../public/assets/img/svg/gitea-double-chevron-left.svg';
45
import giteaDoubleChevronRight from '../../public/assets/img/svg/gitea-double-chevron-right.svg';
56
import giteaEmptyCheckbox from '../../public/assets/img/svg/gitea-empty-checkbox.svg';
@@ -220,8 +221,7 @@ export const SvgIcon = defineComponent({
220221
const classes = Array.from(svgOuter.classList);
221222
if (this.symbolId) {
222223
classes.push('tw-hidden', 'svg-symbol-container');
223-
// eslint-disable-next-line github/unescaped-html-literal
224-
svgInnerHtml = `<symbol id="${this.symbolId}" viewBox="${attrs['^viewBox']}">${svgInnerHtml}</symbol>`;
224+
svgInnerHtml = html`<symbol id="${this.symbolId}" viewBox="${attrs['^viewBox']}">${htmlRaw(svgInnerHtml)}</symbol>`;
225225
}
226226
// create VNode
227227
return h('svg', {

web_src/js/utils/dom.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,9 @@ export function replaceTextareaSelection(textarea: HTMLTextAreaElement, text: st
312312

313313
// Warning: Do not enter any unsanitized variables here
314314
export function createElementFromHTML<T extends HTMLElement>(htmlString: string): T {
315-
// FIXME: maybe we need to use other approaches to create elements from HTML, e.g. using DOMParser
316315
htmlString = htmlString.trim();
317316
// some tags like "tr" are special, it must use a correct parent container to create
318-
// eslint-disable-next-line github/unescaped-html-literal
317+
// eslint-disable-next-line github/unescaped-html-literal -- FIXME: maybe we need to use other approaches to create elements from HTML, e.g. using DOMParser
319318
if (htmlString.startsWith('<tr')) {
320319
const container = document.createElement('table');
321320
container.innerHTML = htmlString;

web_src/js/utils/html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export function htmlEscape(s: string, ...args: Array<any>): string {
2-
if (args.length !== 0) throw new Error('use html or htmlRaw instead of htmlEscape');
2+
if (args.length !== 0) throw new Error('use html or htmlRaw instead of htmlEscape'); // check legacy usages
33
return s.replace(/&/g, '&amp;')
44
.replace(/"/g, '&quot;')
55
.replace(/'/g, '&#39;')

0 commit comments

Comments
 (0)