mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-10-01 09:19:34 +05:30
- src/main/UrlTitle.js — fetch a URL, return its <title>. Pure module
with injectable fetch for tests. Decodes named + numeric + hex entities
(AT&T, Café, —), strips the <title> tags, collapses
whitespace, caps the label at 200 chars. 5s timeout via AbortController,
2 MiB body cap to avoid OOM on big downloads, streaming reader with
overflow cancellation. Rejects non-http(s) URLs up front.
- src/main.js — IPC url-title:fetch proxies to fetchTitle.
- src/editor/smart-paste.js — CodeMirror 6 extension that detects
URL-only pastes (one URL, surrounded only by whitespace), inserts the
URL immediately, then async-rewrites the insertion range to
[Title](url) once the title arrives. Multi-line / prose pastes pass
through untouched.
- src/editor/codemirror-setup.js — accepts smartPasteFetcher option and
pushes the extension when provided.
- src/renderer.js — passes ipcRenderer.invoke('url-title:fetch') as
the fetcher.
- src/preload.js — url-title:fetch added to ALLOWED_SEND_CHANNELS.
- eslint.config.js — AbortController / TextDecoder / TextEncoder added
to globals (available in Node 20+ and Chromium).
Tests (34 new):
- tests/main/UrlTitle.test.js (24): isHttpUrl scheme filter, decodeTitle
named/numeric/hex entities + whitespace + non-string, extractTitleFromHtml
first match + case-insensitive + null fallback, fetchTitle success +
long-title cap + streaming body, all failure paths (non-http,
no-fetch, non-OK, wrong content-type, no <title>, network error,
body over maxBytes — including streaming overflow cancellation).
- tests/smart-paste.test.js (10): URL_ONLY_RE detection (bare URL,
path/query/fragment, whitespace padding, scheme rejection, embedded
rejection, empty/malformed), replacement format ([T](url), brackets
in title survive, query strings preserved).
Full suite: 71 suites, 831 tests, lint+format clean.
Amit Haridas
119 lines
3.0 KiB
JavaScript
119 lines
3.0 KiB
JavaScript
/**
|
|
* ESLint Configuration for PanConverter
|
|
* Uses flat config format (ESLint 9+)
|
|
*/
|
|
|
|
module.exports = [
|
|
{
|
|
// Global ignores
|
|
ignores: [
|
|
'node_modules/**',
|
|
'dist/**',
|
|
'coverage/**',
|
|
'*.min.js'
|
|
]
|
|
},
|
|
{
|
|
// JavaScript files
|
|
files: ['**/*.js'],
|
|
languageOptions: {
|
|
ecmaVersion: 2022,
|
|
sourceType: 'module',
|
|
globals: {
|
|
// Node.js
|
|
require: 'readonly',
|
|
module: 'readonly',
|
|
exports: 'readonly',
|
|
__dirname: 'readonly',
|
|
__filename: 'readonly',
|
|
process: 'readonly',
|
|
Buffer: 'readonly',
|
|
console: 'readonly',
|
|
setTimeout: 'readonly',
|
|
setInterval: 'readonly',
|
|
clearTimeout: 'readonly',
|
|
clearInterval: 'readonly',
|
|
// Browser
|
|
window: 'readonly',
|
|
document: 'readonly',
|
|
localStorage: 'readonly',
|
|
alert: 'readonly',
|
|
prompt: 'readonly',
|
|
confirm: 'readonly',
|
|
Event: 'readonly',
|
|
CustomEvent: 'readonly',
|
|
HTMLElement: 'readonly',
|
|
MutationObserver: 'readonly',
|
|
TextEncoder: 'readonly',
|
|
FileReader: 'readonly',
|
|
requestAnimationFrame: 'readonly',
|
|
cancelAnimationFrame: 'readonly',
|
|
navigator: 'readonly',
|
|
location: 'readonly',
|
|
fetch: 'readonly',
|
|
URL: 'readonly',
|
|
Blob: 'readonly',
|
|
Image: 'readonly',
|
|
DragEvent: 'readonly',
|
|
ClipboardEvent: 'readonly',
|
|
KeyboardEvent: 'readonly',
|
|
MouseEvent: 'readonly',
|
|
NodeList: 'readonly',
|
|
HTMLInputElement: 'readonly',
|
|
HTMLTextAreaElement: 'readonly',
|
|
getComputedStyle: 'readonly',
|
|
CSS: 'readonly',
|
|
Element: 'readonly',
|
|
// Modern Web APIs available in Node 20+ and Chromium
|
|
AbortController: 'readonly',
|
|
TextDecoder: 'readonly',
|
|
TextEncoder: 'readonly',
|
|
// Electron
|
|
electronAPI: 'readonly',
|
|
// Libraries
|
|
marked: 'readonly',
|
|
DOMPurify: 'readonly',
|
|
hljs: 'readonly',
|
|
mermaid: 'readonly',
|
|
// Node.js global object
|
|
global: 'writable',
|
|
// Jest
|
|
jest: 'readonly',
|
|
describe: 'readonly',
|
|
test: 'readonly',
|
|
it: 'readonly',
|
|
expect: 'readonly',
|
|
beforeEach: 'readonly',
|
|
afterEach: 'readonly',
|
|
beforeAll: 'readonly',
|
|
afterAll: 'readonly'
|
|
}
|
|
},
|
|
rules: {
|
|
// Error prevention
|
|
'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
'no-undef': 'error',
|
|
'no-console': 'off', // Allow console for Electron apps
|
|
|
|
// Code quality
|
|
'eqeqeq': ['warn', 'always'],
|
|
'no-var': 'warn',
|
|
'prefer-const': 'warn',
|
|
|
|
// Style (handled by Prettier)
|
|
'semi': 'off',
|
|
'quotes': 'off',
|
|
'indent': 'off',
|
|
|
|
// Async handling
|
|
'no-async-promise-executor': 'warn',
|
|
'require-await': 'off',
|
|
|
|
// Security
|
|
'no-eval': 'error',
|
|
'no-implied-eval': 'error',
|
|
'no-new-func': 'error'
|
|
}
|
|
}
|
|
];
|