Skip to content

[proposal] Enable external renderers to render binary files #7614

Closed
@HarvsG

Description

@HarvsG
  • Gitea version (or commit ref): 1.8.2
  • Git version: 2.17.1
  • Operating system: Ubuntu 18.04
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

After having success with jupyter notebooks and nbconvert, I wanted to try pandoc. So I installed pandoc and added the below to my app.ini:

[markup.word]
ENABLED = true
FILE_EXTENSIONS = .docx
RENDER_COMMAND = "pandoc -f docx -t html "
IS_INPUT_FILE = true

I have tested on the machine to ensure that pandoc is correctly configured and when I run pandoc -f docx -t html test.docx I get html output. However if I navigate to the repo I just get the 'view raw' hyperlink

I have also tested pandoc on other file types and it appears to be working - or at least doing something. With this it is like the command is not being called at all. Could it be because the file is labelled as a binary and so never even beings to render?
...

Looks as if it might be related to/a duplicate of #4996

Edit & Proposal

As per my entry in #4996
I propose the following untested addition in order to allow external renderers to render binary files if specified by the user

	default:
		if blob.Size() >= setting.UI.MaxDisplayFileSize {
			ctx.Data["IsFileTooLarge"] = true
			break
		}

		d, _ := ioutil.ReadAll(dataRc)
		buf = templates.ToUTF8WithFallback(append(buf, d...))
		if markup.Type(blob.Name()) != "" {
			ctx.Data["IsMarkup"] = true // or ctx.Data["IsRenderedHTML"] = true
			ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
		}

at line

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/enhancementAn improvement of existing functionality

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions