Skip to content

Align markdown and orgmode link rendering #29100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
KN4CK3R opened this issue Feb 8, 2024 · 2 comments · Fixed by #32671
Closed

Align markdown and orgmode link rendering #29100

KN4CK3R opened this issue Feb 8, 2024 · 2 comments · Fixed by #32671
Labels
topic/content-rendering Changes how certain filetypes are displayed type/bug

Comments

@KN4CK3R
Copy link
Member

KN4CK3R commented Feb 8, 2024

Do we want the orgmode renderer behave like the markdown renderer? I created multiple test cases extracted from the markdown renderer:

	input := `/just/a/path.bin
https://example.com/file.bin
[[file:file.bin][local link]]
[[https://example.com][remote link]]
[[file:image.jpg][local image]]
[[file:path/file.jpg][local image]]
[[file:/path/file.jpg][local image]]
[[file:https://example.com/image.jpg][remote image]]`

	cases := []struct {
		Links    markup.Links
		Expected string
	}{
		{ // 0
			Links:  markup.Links{},
			Expected: `<p>/just/a/path.bin<br/>
<a href="https://example.com/file.bin" rel="nofollow">https://example.com/file.bin</a><br/>
<a href="/file.bin" rel="nofollow">local link</a><br/>
<a href="https://example.com" rel="nofollow">remote link</a><br/>
<a href="/image.jpg" target="_blank" rel="nofollow noopener"><img src="/image.jpg" alt="local image"/></a><br/>
<a href="/path/file.jpg" target="_blank" rel="nofollow noopener"><img src="/path/file.jpg" alt="local image"/></a><br/>
<a href="/path/file.jpg" target="_blank" rel="nofollow noopener"><img src="/path/file.jpg" alt="local image"/></a><br/>
<a href="https://example.com/image.jpg" target="_blank" rel="nofollow noopener"><img src="https://example.com/image.jpg" alt="remote image"/></a></p>`,
		},
		{ // 1
			Links:  markup.Links{
				Base:"https://gitea.io/",
			},
			Expected: `<p>/just/a/path.bin<br/>
<a href="https://example.com/file.bin" rel="nofollow">https://example.com/file.bin</a><br/>
<a href="https://gitea.io/file.bin" rel="nofollow">local link</a><br/>
<a href="https://example.com" rel="nofollow">remote link</a><br/>
<a href="https://gitea.io/image.jpg" target="_blank" rel="nofollow noopener"><img src="https://gitea.io/image.jpg" alt="local image"/></a><br/>
<a href="https://gitea.io/path/file.jpg" target="_blank" rel="nofollow noopener"><img src="https://gitea.io/path/file.jpg" alt="local image"/></a><br/>
<a href="https://gitea.io/path/file.jpg" target="_blank" rel="nofollow noopener"><img src="https://gitea.io/path/file.jpg" alt="local image"/></a><br/>
<a href="https://example.com/image.jpg" target="_blank" rel="nofollow noopener"><img src="https://example.com/image.jpg" alt="remote image"/></a></p>`,
		},
		{ // 2
			Links:  markup.Links{
				Base: "/relative/path",
			},
			Expected: `<p>/just/a/path.bin<br/>
<a href="https://example.com/file.bin" rel="nofollow">https://example.com/file.bin</a><br/>
<a href="/relative/path/file.bin" rel="nofollow">local link</a><br/>
<a href="https://example.com" rel="nofollow">remote link</a><br/>
<a href="/relative/path/image.jpg" target="_blank" rel="nofollow noopener"><img src="/relative/path/image.jpg" alt="local image"/></a><br/>
<a href="/relative/path/path/file.jpg" target="_blank" rel="nofollow noopener"><img src="/relative/path/path/file.jpg" alt="local image"/></a><br/>
<a href="/relative/path/path/file.jpg" target="_blank" rel="nofollow noopener"><img src="/relative/path/path/file.jpg" alt="local image"/></a><br/>
<a href="https://example.com/image.jpg" target="_blank" rel="nofollow noopener"><img src="https://example.com/image.jpg" alt="remote image"/></a></p>`,
		},
		{ // 3
			Links:  markup.Links{
				Base:       "/user/repo",
				BranchPath: "branch/main",
			},
			Expected: `<p>/just/a/path.bin<br/>
<a href="https://example.com/file.bin" rel="nofollow">https://example.com/file.bin</a><br/>
<a href="/user/repo/src/branch/main/file.bin" rel="nofollow">local link</a><br/>
<a href="https://example.com" rel="nofollow">remote link</a><br/>
<a href="/user/repo/media/branch/main/image.jpg" target="_blank" rel="nofollow noopener"><img src="/user/repo/media/branch/main/image.jpg" alt="local image"/></a><br/>
<a href="/user/repo/media/branch/main/path/file.jpg" target="_blank" rel="nofollow noopener"><img src="/user/repo/media/branch/main/path/file.jpg" alt="local image"/></a><br/>
<a href="/user/repo/media/branch/main/path/file.jpg" target="_blank" rel="nofollow noopener"><img src="/user/repo/media/branch/main/path/file.jpg" alt="local image"/></a><br/>
<a href="https://example.com/image.jpg" target="_blank" rel="nofollow noopener"><img src="https://example.com/image.jpg" alt="remote image"/></a></p>`,
		},
		{ // 4
			Links:  markup.Links{
				Base:     "/relative/path",
				TreePath: "sub/folder",
			},
			Expected: `<p>/just/a/path.bin<br/>
<a href="https://example.com/file.bin" rel="nofollow">https://example.com/file.bin</a><br/>
<a href="/relative/path/file.bin" rel="nofollow">local link</a><br/>
<a href="https://example.com" rel="nofollow">remote link</a><br/>
<a href="/relative/path/image.jpg" target="_blank" rel="nofollow noopener"><img src="/relative/path/image.jpg" alt="local image"/></a><br/>
<a href="/relative/path/path/file.jpg" target="_blank" rel="nofollow noopener"><img src="/relative/path/path/file.jpg" alt="local image"/></a><br/>
<a href="/relative/path/path/file.jpg" target="_blank" rel="nofollow noopener"><img src="/relative/path/path/file.jpg" alt="local image"/></a><br/>
<a href="https://example.com/image.jpg" target="_blank" rel="nofollow noopener"><img src="https://example.com/image.jpg" alt="remote image"/></a></p>`,
		},
		{ // 5
			Links:  markup.Links{
				Base:       "/user/repo",
				BranchPath: "branch/main",
				TreePath:   "sub/folder",
			},
			Expected: `<p>/just/a/path.bin<br/>
<a href="https://example.com/file.bin" rel="nofollow">https://example.com/file.bin</a><br/>
<a href="/user/repo/src/branch/main/sub/folder/file.bin" rel="nofollow">local link</a><br/>
<a href="https://example.com" rel="nofollow">remote link</a><br/>
<a href="/user/repo/media/branch/main/sub/folder/image.jpg" target="_blank" rel="nofollow noopener"><img src="/user/repo/media/branch/main/sub/folder/image.jpg" alt="local image"/></a><br/>
<a href="/user/repo/media/branch/main/sub/folder/path/file.jpg" target="_blank" rel="nofollow noopener"><img src="/user/repo/media/branch/main/sub/folder/path/file.jpg" alt="local image"/></a><br/>
<a href="/user/repo/media/branch/main/sub/folder/path/file.jpg" target="_blank" rel="nofollow noopener"><img src="/user/repo/media/branch/main/sub/folder/path/file.jpg" alt="local image"/></a><br/>
<a href="https://example.com/image.jpg" target="_blank" rel="nofollow noopener"><img src="https://example.com/image.jpg" alt="remote image"/></a></p>`,
		},
	}

	for i, c := range cases {
		result, err := RenderString(&markup.RenderContext{Ctx: context.Background(), Links: c.Links}, input)
		assert.NoError(t, err, "Unexpected error in testcase: %v", i)
		assert.Equal(t, c.Expected, result, "Unexpected result in testcase %v", i)
	}

The corresponding markdown input looks like this:

input := `/just/a/path.bin
https://example.com/file.bin
[local link](file.bin)
[remote link](https://example.com)
![local image](image.jpg)
![local image](path/file.jpg)
![local image](/path/file.jpg)
![remote image](https://example.com/image.jpg)`

Things I noticed:

  • \n gets rendered as <br/>\n in markdown and just \n in orgmode
  • links in markdown get decorated with target and rel attributes.

Originally posted by @KN4CK3R in #29024 (comment)

@KN4CK3R KN4CK3R added type/bug topic/content-rendering Changes how certain filetypes are displayed labels Feb 8, 2024
@silverwind
Copy link
Member

silverwind commented Feb 8, 2024

Does Orgmode have a spec that shows expected HTML output like CommonMark for Markdown? If so, might be worth to look there. Otherwise I'd lean towards bringing the render output closer together, maybe even so close as to share functions for link generation etc.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Nov 29, 2024

The path problem should have been completely fixed by recent render system refactoring changes.

And to make it better, refactor the orgmode renderer and add tests: Refactor render system (orgmode) #32671


\n gets rendered as
\n in markdown and just \n in orgmode

It is right to keep "\n" in document mode (rendering files)

links in markdown get decorated with target and rel attributes.

Gitea pages already have global "rel", no need to add them one by one.

@go-gitea go-gitea locked as resolved and limited conversation to collaborators Feb 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic/content-rendering Changes how certain filetypes are displayed type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants