diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-11-29 16:08:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-29 16:08:29 +0800 |
commit | 93640993e3cca9d0e0261591ba38b84b0b99ab12 (patch) | |
tree | 6d6e490a2082317224015935689ea7f87883fec6 /models/renderhelper | |
parent | a1f56f83bff56f86180e59742efd3748908b82c1 (diff) | |
download | gitea-93640993e3cca9d0e0261591ba38b84b0b99ab12.tar.gz gitea-93640993e3cca9d0e0261591ba38b84b0b99ab12.zip |
Refactor render system (orgmode) (#32671)
Close #29100
Diffstat (limited to 'models/renderhelper')
-rw-r--r-- | models/renderhelper/repo_file_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/models/renderhelper/repo_file_test.go b/models/renderhelper/repo_file_test.go index 40027ec76f..959648b660 100644 --- a/models/renderhelper/repo_file_test.go +++ b/models/renderhelper/repo_file_test.go @@ -12,6 +12,8 @@ import ( "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" + _ "code.gitea.io/gitea/modules/markup/orgmode" + "github.com/stretchr/testify/assert" ) @@ -81,3 +83,40 @@ func TestRepoFile(t *testing.T) { </video>`, rendered) }) } + +func TestRepoFileOrgMode(t *testing.T) { + unittest.PrepareTestEnv(t) + repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) + + t.Run("Links", func(t *testing.T) { + rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{ + CurrentRefPath: "/commit/1234", + CurrentTreePath: "my-dir", + }).WithRelativePath("my-dir/a.org") + + rendered, err := markup.RenderString(rctx, ` +[[https://google.com/]] +[[ImageLink.svg][The Image Desc]] +`) + assert.NoError(t, err) + assert.Equal(t, `<p> +<a href="https://google.com/" rel="nofollow">https://google.com/</a> +<a href="/user2/repo1/media/commit/1234/my-dir/ImageLink.svg" rel="nofollow">The Image Desc</a></p> +`, rendered) + }) + + t.Run("CodeHighlight", func(t *testing.T) { + rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{}).WithRelativePath("my-dir/a.org") + + rendered, err := markup.RenderString(rctx, ` +#+begin_src c +int a = 1; +#+end_src +`) + assert.NoError(t, err) + assert.Equal(t, `<div> +<pre><code class="chroma language-c"><span class="kt">int</span> <span class="n">a</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span></code></pre> +</div> +`, rendered) + }) +} |