mirror of
https://github.com/h-sphere/sql-seal.git
synced 2026-07-22 10:10:28 +00:00
fix: fixed how links behave and parameter order
This commit is contained in:
parent
5cf7f247de
commit
c2fe8b0eff
6 changed files with 77 additions and 9 deletions
|
|
@ -1,3 +1,6 @@
|
|||
# 0.24.2 (2025-02-05)
|
||||
- Fixed how links are displayed. Now you can use links as `a(href)` or `a(href, name)`.
|
||||
|
||||
# 0.24.1 (2025-02-05)
|
||||
- Added `path` columns to `tags` and `tasks` tables. Thanks to that you can use `NATURAL JOIN`s now to connect join them.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "sqlseal",
|
||||
"name": "SQLSeal",
|
||||
"version": "0.24.1",
|
||||
"version": "0.24.2",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Use SQL in your notes to query your vault files and CSV content.",
|
||||
"author": "hypersphere",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "sqlseal",
|
||||
"version": "0.24.1",
|
||||
"version": "0.24.2",
|
||||
"description": "A plugin for Obsidian that allows you to run SQL queries on your notes.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
49
src/utils/ui.test.ts
Normal file
49
src/utils/ui.test.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { renderLink } from "./ui"
|
||||
|
||||
const makeApp = () => ({ metadataCache: { getFirstLinkpathDest: jest.fn(p => ({ path: p })) } })
|
||||
|
||||
describe('UI', () => {
|
||||
it('should properly render links', () => {
|
||||
const app = makeApp()
|
||||
const createEl = jest.fn()
|
||||
renderLink(app as any, createEl)(['a/b/c.md'])
|
||||
expect(createEl).toHaveBeenCalledWith('a', {
|
||||
cls: 'internal-link',
|
||||
href: 'a/b/c.md',
|
||||
text: 'c'
|
||||
})
|
||||
})
|
||||
|
||||
it('should properly render link with name provided', () => {
|
||||
const app = makeApp()
|
||||
const createEl = jest.fn()
|
||||
renderLink(app as any, createEl)(['a/b/c.md', 'Name'])
|
||||
expect(createEl).toHaveBeenCalledWith('a', {
|
||||
cls: 'internal-link',
|
||||
href: 'a/b/c.md',
|
||||
text: 'Name'
|
||||
})
|
||||
})
|
||||
|
||||
it('should properly render link with external url', () => {
|
||||
const app = makeApp()
|
||||
const createEl = jest.fn()
|
||||
renderLink(app as any, createEl)(['https://wikipedia.org', 'Wikipedia'])
|
||||
expect(createEl).toHaveBeenCalledWith('a', {
|
||||
cls: '',
|
||||
href: 'https://wikipedia.org',
|
||||
text: 'Wikipedia'
|
||||
})
|
||||
})
|
||||
|
||||
it('should properly render link using wikilink tag', () => {
|
||||
const app = makeApp()
|
||||
const createEl = jest.fn()
|
||||
renderLink(app as any, createEl)(['[[a/b/c.md|Alias]]'])
|
||||
expect(createEl).toHaveBeenCalledWith('a', {
|
||||
cls: 'internal-link',
|
||||
href: 'a/b/c.md',
|
||||
text: 'Alias'
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { App, getLinkpath, parseLinktext } from "obsidian"
|
||||
import { App } from "obsidian"
|
||||
import { CellParserRegistar } from "src/cellParser"
|
||||
|
||||
export const displayNotice = (el: HTMLElement, text: string) => {
|
||||
|
|
@ -28,9 +28,21 @@ const renderCheckbox = (app: App) => ([value]: [string]) => {
|
|||
}
|
||||
return el
|
||||
}
|
||||
const renderLink = (app: App) => ([name, href]: [string, string]) => {
|
||||
if (!href) {
|
||||
href = name
|
||||
|
||||
const removeExtension = (filename: string) => {
|
||||
const parts = filename.split('.')
|
||||
if (parts.length > 1) {
|
||||
return parts.slice(0, -1).join('.')
|
||||
}
|
||||
return filename
|
||||
}
|
||||
|
||||
|
||||
type LinkType = [string] | [string, string]
|
||||
|
||||
export const renderLink = (app: App, create = createEl) => ([href, name]: LinkType) => {
|
||||
if (!name) {
|
||||
name = href
|
||||
}
|
||||
href = href.trim()
|
||||
let cls = ''
|
||||
|
|
@ -54,10 +66,13 @@ const renderLink = (app: App) => ([name, href]: [string, string]) => {
|
|||
if (fileHref.endsWith('.md')) {
|
||||
fileHref = fileHref.slice(0, -3)
|
||||
}
|
||||
href = href
|
||||
if (name === href) {
|
||||
const components = href.split('/')
|
||||
name = removeExtension(components[components.length - 1])
|
||||
}
|
||||
cls = 'internal-link'
|
||||
}
|
||||
const el = createEl('a', { text: name, href, cls })
|
||||
const el = create('a', { text: name, href, cls })
|
||||
return el
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,5 +44,6 @@
|
|||
"0.23.1": "0.15.0",
|
||||
"0.23.2": "0.15.0",
|
||||
"0.24.0": "0.15.0",
|
||||
"0.24.1": "0.15.0"
|
||||
"0.24.1": "0.15.0",
|
||||
"0.24.2": "0.15.0"
|
||||
}
|
||||
Loading…
Reference in a new issue