Skip to content
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

Pass link prefixes to external markup parsers #5201

Merged
merged 10 commits into from
Oct 30, 2018
Merged

Pass link prefixes to external markup parsers #5201

merged 10 commits into from
Oct 30, 2018

Conversation

Eisfunke
Copy link
Contributor

Should close #5031.

This passes the current URL prefixes to external markup parsers as environment variables.

GITEA_PREFIX_SRC is the current link prefix in the src path tree, GITEA_PREFIX_RAW is the prefix for images in the raw path tree.

The raw prefix is obtained by string replacement. That's not quite elegant, but it's what markdown.go does, so I copied that.

I tested the change with Pandoc as markdown parser, and I was able to get links and images working using the environment variables.

Signed-off-by: Nicolas Lenz nicolas@eisfunke.com

Signed-off-by: Nicolas Lenz <nicolas@eisfunke.com>
Signed-off-by: Nicolas Lenz <nicolas@eisfunke.com>
Signed-off-by: Nicolas Lenz <nicolas@eisfunke.com>
@codecov-io
Copy link

codecov-io commented Oct 27, 2018

Codecov Report

Merging #5201 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5201      +/-   ##
==========================================
- Coverage   37.49%   37.47%   -0.02%     
==========================================
  Files         310      310              
  Lines       45934    45934              
==========================================
- Hits        17223    17215       -8     
- Misses      26237    26242       +5     
- Partials     2474     2477       +3
Impacted Files Coverage Δ
models/repo_indexer.go 44.49% <0%> (-3.39%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e61c6cd...24cdf6f. Read the comment docs.

@bkcsoft bkcsoft added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 27, 2018
@Eisfunke Eisfunke changed the title Link prefix Pass link prefixes to external markup parsers Oct 27, 2018
@lunny
Copy link
Member

lunny commented Oct 27, 2018

After this merged so we can change the ini for example:

[markup.ascii]
ENABLED = false
FILE_EXTENSIONS = .adoc,.asciidoc
RENDER_COMMAND = "asciidoc --imagesdir=$GITEA_PREFIX_SRC --out-file=- -"
IS_INPUT_FILE = false

@bkcsoft bkcsoft added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Oct 29, 2018
@techknowlogick techknowlogick added the type/enhancement An improvement of existing functionality label Oct 29, 2018
@Eisfunke
Copy link
Contributor Author

After this merged so we can change the ini for example:

[markup.ascii]
ENABLED = false
FILE_EXTENSIONS = .adoc,.asciidoc
RENDER_COMMAND = "asciidoc --imagesdir=$GITEA_PREFIX_SRC --out-file=- -"
IS_INPUT_FILE = false

For images GITEA_PREFIX_RAW, not GITEA_PREFIX_SRC, should be used, I think.

@lunny lunny added this to the 1.7.0 milestone Oct 30, 2018
Copy link
Member

@lunny lunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[markup.ascii]
ENABLED = false
FILE_EXTENSIONS = .adoc,.asciidoc
RENDER_COMMAND = "asciidoc --imagesdir=$GITEA_PREFIX_RAW --out-file=- -"
IS_INPUT_FILE = false

It's not right you can config as above, $GITEA_PREFIX_RAW is blank, you have to write a shell script and use $GITEA_PREFIX_RAW in your script.

@bkcsoft bkcsoft added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Oct 30, 2018
@techknowlogick techknowlogick merged commit 220ee6a into go-gitea:master Oct 30, 2018
@Cellebyte
Copy link

[markup.asciidoc]
ENABLED = true
FILE_EXTENSIONS = .adoc,.asciidoc
RENDER_COMMAND = 'asciidoctor -b html5 -a imagesdir="$GITEA_PREFIX_RAW" -a relfileprefix="$GITEA_PREFIX_SRC" --out-file=- -'
IS_INPUT_FILE = false

The config is not working with commit ref:078c404c3b0f283a242ad93b6a2f4cabb2575410

@lunny
Copy link
Member

lunny commented Nov 5, 2018

@Cellebyte Yes, it will not except you create a shell script and save that command there.

@Cellebyte
Copy link

Cellebyte commented Nov 5, 2018

@lunny thanks so i should copy a simple wrapper script with $@ to asciidoc?
Do you have an example?

@lunny
Copy link
Member

lunny commented Nov 5, 2018

I mean you can create a script file such as convert.sh and copy your command there, i.e.

#!/bin/bash
asciidoctor -b html5 -a imagesdir="$GITEA_PREFIX_RAW" -a relfileprefix="$GITEA_PREFIX_SRC" --out-file=- -

@Cellebyte
Copy link

Cellebyte commented Nov 5, 2018

Have done that. Will test it thanks for the reply ;)

#!/bin/bash
asciidoctor -b html5 -a imagesdir="$GITEA_PREFIX_RAW/" -a relfileprefix="$GITEA_PREFIX_SRC/" --out-file=- $1 | sed 's/lang="en">//'

Need to use sed, don't know why this lang="en" appears.

@Eisfunke Eisfunke deleted the link-prefix branch November 5, 2018 20:00
@andreashaerter
Copy link

I tested the change with Pandoc as markdown parser, and I was able to get links and images working using the environment variables.

@Eisfunke Would you mind to share the used RENDER_COMMAND for pandoc? :-)

@garyritchie
Copy link

Sounds like this might close #3025 - can anyone confirm?

@Cellebyte did the shell script work in your case?

@Cellebyte
Copy link

Yes @garyritchie it worked very well. The only problem are svg images. But this is referenced in another Issue.

@garyritchie
Copy link

Thanks @Cellebyte !

Where should I put the script? I'll need to include it when I build my gitea-asciidoc docker image (based on gitea:1.8).

@Cellebyte
Copy link

Cellebyte commented Jun 14, 2019

@garyritchie

FROM gitea/gitea:1.8

RUN apk add --update --no-cache \
    ruby \
    sed \
    asciidoctor && \
    gem install --no-ri --no-rdoc coderay && \
    gem update --no-ri --no-rdoc asciidoctor && \
    gem cleanup && \
    rm -rf /tmp/* /var/cache/apk/*

COPY asciidoc.sh /usr/bin/asciidoc.sh
RUN chown 1000:1000 /usr/bin/asciidoc.sh && \
    chmod 0755 /usr/bin/asciidoc.sh

Thats my Dockerfile

@garyritchie
Copy link

Got it working, thanks!

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

External markup renderers can't use in-repo images
8 participants