diff --git a/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.html b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.html index f9dee23bce..dc21dbf51e 100644 --- a/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.html +++ b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.html @@ -25,7 +25,7 @@ @for (release of releases(); track release.version) {
{{ release.version }}
-
+
} } diff --git a/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.scss b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.scss index 289faa2e94..0d88c8f358 100644 --- a/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.scss +++ b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.scss @@ -1,6 +1,39 @@ -:host ::ng-deep .release-notes-body > h3 { - font-size: 1rem; - font-weight: 600; - margin-top: 1rem; - margin-bottom: 0.5rem; +// Styles for GitHub-rendered release notes (body_html) +:host ::ng-deep .release-notes-body { + // Repeats the version heading + > h2:first-child { + display: none; + } + + > h3 { + font-size: 1rem; + font-weight: 600; + margin-top: 1rem; + margin-bottom: 0.5rem; + } + + details { + margin-bottom: 1rem; + + > summary { + color: var(--bs-secondary-color); + cursor: pointer; + margin-bottom: 0.5rem; + } + } + + .markdown-alert { + border-left: 0.25rem solid var(--bs-info); + padding: 0.5rem 1rem; + margin-bottom: 1rem; + + > :last-child { + margin-bottom: 0; + } + } + + .markdown-alert-title { + font-weight: 600; + margin-bottom: 0.25rem; + } } diff --git a/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.spec.ts b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.spec.ts index 93935f3554..71b5c168cb 100644 --- a/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.spec.ts +++ b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.spec.ts @@ -8,10 +8,7 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' import { SETTINGS_KEYS } from 'src/app/data/ui-settings' import { SettingsService } from 'src/app/services/settings.service' import { environment } from 'src/environments/environment' -import { - cleanReleaseBody, - ReleaseNotesDialogComponent, -} from './release-notes-dialog.component' +import { ReleaseNotesDialogComponent } from './release-notes-dialog.component' describe('ReleaseNotesDialogComponent', () => { let component: ReleaseNotesDialogComponent @@ -58,7 +55,9 @@ describe('ReleaseNotesDialogComponent', () => { { version: '3.5.1', name: 'Paperless-ngx v3.5.1', - body: '## paperless-ngx 3.5.1\r\n\r\n### Bug Fixes\r\n\r\n- Fix: a thing ([#1](https://github.com/paperless-ngx/paperless-ngx/pull/1))', + body_html: + '

paperless-ngx 3.5.1

Bug Fixes

' + + '

All App Changes

1 change
', html_url: '', published_at: '', }, @@ -69,35 +68,10 @@ describe('ReleaseNotesDialogComponent', () => { const text = fixture.nativeElement.textContent expect(text).toContain('Updated from 3.4.2 to 3.5.1') expect(text).toContain('Bug Fixes') - expect(text).not.toContain('paperless-ngx 3.5.1') - expect(text).not.toContain('(github.com)') - }) - - it('should drop the duplicate All App Changes section and details markup', () => { - const body = [ - '## paperless-ngx 3.5.1', - '### Bug Fixes', - '- Fix: a thing', - '### Dependencies', - '
', - '1 change', - '', - '- Chore(deps): bump a thing', - '
', - '### All App Changes', - '
', - '2 changes', - '', - '- Fix: a thing', - '- Chore(deps): bump a thing', - '
', - ].join('\r\n') - const cleaned = cleanReleaseBody(body) - expect(cleaned).toContain('### Dependencies') - expect(cleaned).toContain('- Chore(deps): bump a thing') - expect(cleaned).not.toContain('All App Changes') - expect(cleaned).not.toContain('details>') - expect(cleaned).not.toContain('summary>') + expect( + fixture.nativeElement.querySelector('.release-notes-body details summary') + .textContent + ).toEqual('1 change') }) it('should show a message if release notes could not be loaded', () => { diff --git a/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.ts b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.ts index 66644700b5..80e0a2b16b 100644 --- a/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.ts +++ b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.ts @@ -3,7 +3,6 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' import { first } from 'rxjs' import { BootstrapIconComponent } from 'src/app/components/common/bootstrap-icon/bootstrap-icon.component' import { SETTINGS_KEYS } from 'src/app/data/ui-settings' -import { MarkdownPipe } from 'src/app/pipes/markdown.pipe' import { AppRelease, RemoteVersionService, @@ -12,25 +11,11 @@ import { SettingsService } from 'src/app/services/settings.service' const RELEASES_URL = 'https://github.com/paperless-ngx/paperless-ngx/releases' -const RELEASE_TITLE = /^\s*##\s+paperless-ngx[^\n]*\n+/i -const ALL_CHANGES_SECTION = /^###\s+All App Changes\s*$[\s\S]*/im -const DETAILS_MARKUP = /^\s*(<\/?details>|.*<\/summary>)\s*$/gim - -/** - * Drops the "## paperless-ngx x.y.z" title, the "All App Changes" - * section and `
` / `` wrappers. - */ -export function cleanReleaseBody(body: string): string { - body = body.replace(RELEASE_TITLE, '') - body = body.replace(ALL_CHANGES_SECTION, '') - return body.replace(DETAILS_MARKUP, '').trim() -} - @Component({ selector: 'pngx-release-notes-dialog', templateUrl: './release-notes-dialog.component.html', styleUrls: ['./release-notes-dialog.component.scss'], - imports: [BootstrapIconComponent, MarkdownPipe], + imports: [BootstrapIconComponent], }) export class ReleaseNotesDialogComponent { readonly activeModal = inject(NgbActiveModal) @@ -63,12 +48,7 @@ export class ReleaseNotesDialogComponent { .pipe(first()) .subscribe({ next: (notes) => { - this.releases.set( - notes.releases.map((release) => ({ - ...release, - body: cleanReleaseBody(release.body), - })) - ) + this.releases.set(notes.releases) this.loading.set(false) }, error: () => { diff --git a/src-ui/src/app/pipes/markdown.pipe.spec.ts b/src-ui/src/app/pipes/markdown.pipe.spec.ts index a9d42c070f..a0655486e7 100644 --- a/src-ui/src/app/pipes/markdown.pipe.spec.ts +++ b/src-ui/src/app/pipes/markdown.pipe.spec.ts @@ -87,10 +87,4 @@ describe('MarkdownPipe', () => { ) expect(html).not.toMatch(/"\s*onmouseover=/) }) - - it('should omit link hostnames when requested', () => { - const html = pipe.transform('[PR](https://github.com/x/y/pull/1)', false) - expect(html).toContain('href="https://github.com/x/y/pull/1"') - expect(html).not.toContain('(github.com)') - }) }) diff --git a/src-ui/src/app/pipes/markdown.pipe.ts b/src-ui/src/app/pipes/markdown.pipe.ts index 4a33e4e45c..992714c148 100644 --- a/src-ui/src/app/pipes/markdown.pipe.ts +++ b/src-ui/src/app/pipes/markdown.pipe.ts @@ -12,59 +12,41 @@ function allowedUrl(href: string): URL | null { } } -/** - * Treat content as untrusted: no raw HTML, no images, and only - * absolute links. All escaping is done by marked's default renderer, and - * Angular's sanitizer should run on top of this as well. - */ -function buildRenderer(showLinkHosts: boolean): Partial { - return { - html(this: Renderer, { raw, text }: Tokens.HTML | Tokens.Tag): string { - return this.text({ type: 'text', raw, text }) - }, - image(this: Renderer, { raw, text }: Tokens.Image): string { - return this.text({ type: 'text', raw, text }) - }, - link(this: Renderer, token: Tokens.Link): string { - const url = allowedUrl(token.href) - if (!url) return this.parser.parseInline(token.tokens) - const anchor = Renderer.prototype.link - .call(this, token) - .replace( - '(${hostname})` - }, - } +// Treat chat content as untrusted: no raw HTML, no images, and only +// absolute links. All escaping is done by marked's default renderer, and +// Angular's sanitizer runs on top of this as well. +const renderer: Partial = { + html(this: Renderer, { raw, text }: Tokens.HTML | Tokens.Tag): string { + return this.text({ type: 'text', raw, text }) + }, + image(this: Renderer, { raw, text }: Tokens.Image): string { + return this.text({ type: 'text', raw, text }) + }, + link(this: Renderer, token: Tokens.Link): string { + const url = allowedUrl(token.href) + if (!url) return this.parser.parseInline(token.tokens) + const anchor = Renderer.prototype.link + .call(this, token) + .replace('(${hostname})` + }, } -function buildMarked(showLinkHosts: boolean): Marked { - return new Marked({ - async: false, - gfm: true, - breaks: true, - renderer: buildRenderer(showLinkHosts), - }) -} - -const markdown = buildMarked(true) -const markdownWithoutLinkHosts = buildMarked(false) +const markdown = new Marked({ + async: false, + gfm: true, + breaks: true, + renderer, +}) @Pipe({ name: 'markdown', }) export class MarkdownPipe implements PipeTransform { - /** - * @param showLinkHosts append each link's hostname, e.g. "(example.com)". - * Can be disabled for trusted content where every link points to the same host. - */ - transform(value: string | null | undefined, showLinkHosts = true): string { + transform(value: string | null | undefined): string { if (!value) return '' - return (showLinkHosts ? markdown : markdownWithoutLinkHosts).parse( - value - ) as string + return markdown.parse(value) as string } } diff --git a/src-ui/src/app/services/rest/remote-version.service.ts b/src-ui/src/app/services/rest/remote-version.service.ts index ba0c3445d5..fb193b213a 100644 --- a/src-ui/src/app/services/rest/remote-version.service.ts +++ b/src-ui/src/app/services/rest/remote-version.service.ts @@ -11,7 +11,7 @@ export interface AppRemoteVersion { export interface AppRelease { version: string name: string - body: string + body_html: string html_url: string published_at: string } diff --git a/src/documents/tests/test_api_release_notes.py b/src/documents/tests/test_api_release_notes.py index 10cbf406c6..888810fb60 100644 --- a/src/documents/tests/test_api_release_notes.py +++ b/src/documents/tests/test_api_release_notes.py @@ -15,7 +15,7 @@ def _release(tag: str, **kwargs) -> dict: return { "tag_name": tag, "name": f"Paperless-ngx {tag}", - "body": f"## paperless-ngx {tag}", + "body_html": f"

paperless-ngx {tag}

", "html_url": f"https://github.com/paperless-ngx/paperless-ngx/releases/tag/{tag}", "published_at": "2026-11-17T03:36:20Z", "draft": False, @@ -44,6 +44,7 @@ class TestApiReleaseNotes: def releases(self, httpx_mock: HTTPXMock) -> HTTPXMock: httpx_mock.add_response( url=RELEASES_URL, + match_headers={"Accept": "application/vnd.github.html+json"}, json=[ _release(f"v{_bump(patch=1)}"), _release(f"v{_bump(minor=1)}-beta.1", prerelease=True), @@ -77,7 +78,10 @@ class TestApiReleaseNotes: PREVIOUS, ] assert response.data["releases"][0]["html_url"].endswith(f"v{CURRENT}") - assert response.data["releases"][0]["body"] == f"## paperless-ngx v{CURRENT}" + assert ( + response.data["releases"][0]["body_html"] + == f"

paperless-ngx v{CURRENT}

" + ) def test_without_since_returns_current_only( self, diff --git a/src/documents/views.py b/src/documents/views.py index 443a1e111a..2deb542c16 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -4330,7 +4330,8 @@ def get_github_releases( resp = httpx.get( "https://api.github.com/repos/paperless-ngx/paperless-ngx/releases", params={"per_page": 10}, - headers={"Accept": "application/json"}, + # GitHub renders release bodies as HTML + headers={"Accept": "application/vnd.github.html+json"}, ) resp.raise_for_status() releases = [] @@ -4348,7 +4349,7 @@ def get_github_releases( { "version": str(release_version), "name": release.get("name") or release["tag_name"], - "body": release.get("body") or "", + "body_html": release.get("body_html") or "", "html_url": release["html_url"], "published_at": release.get("published_at"), },