From mboxrd@z Thu Jan 1 00:00:00 1970 From: john at keeping.me.uk (John Keeping) Date: Tue, 19 Jun 2018 22:56:16 +0100 Subject: [PATCH v3 17/17] render: adapt for providing extra filter args for plain In-Reply-To: <152939897283.4492.4296837350232991703.stgit@mail.warmcat.com> References: <152939875224.4492.4288866616332837866.stgit@mail.warmcat.com> <152939897283.4492.4296837350232991703.stgit@mail.warmcat.com> Message-ID: <20180619215616.GE1922@john.keeping.me.uk> On Tue, Jun 19, 2018 at 05:02:52PM +0800, Andy Green wrote: > This changes the render filter exec part to provide a second > and third argument, which are used by md2html to fix up the url > path for "plain" for the repo, eg, "/cgit/plain/" and > "?h=mybranch", as required by the modifications to md2html in > the previous patches. > > The combination means cgit becomes able to serve assets using > markdown urls starting from the repo root dir, without mentioning > any virtual url part specific to a cgit or other web rendering > instance, while respecting the version context. > > Eg, continuing the example of the arguments being > "/cgit/plain/" and "?h=mybranch" from above, if the markdown has > > ![overview](./doc-assets/overview.png) > > the img src will be fixed up to > > "/cgit/plain/doc-assets/overview.png?h=mybranch" > > If the same document is viewed from a different rev in cgit, the > processed markdown url will change to match the cgit context, even > though the markdown relative URL is the same for all versions. > > Signed-off-by: Andy Green Reviewed-by: John Keeping > --- > filter.c | 5 ++++- > ui-tree.c | 11 +++++++++-- > 2 files changed, 13 insertions(+), 3 deletions(-) > > diff --git a/filter.c b/filter.c > index 4ae4aaa..7c1f188 100644 > --- a/filter.c > +++ b/filter.c > @@ -424,6 +424,10 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype) > argument_count = 12; > break; > > + case RENDER: > + argument_count = 3; > + break; > + > case EMAIL: > argument_count = 2; > break; > @@ -434,7 +438,6 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype) > > case SOURCE: > case ABOUT: > - case RENDER: > argument_count = 1; > break; > > diff --git a/ui-tree.c b/ui-tree.c > index 6ffd4dd..2e94755 100644 > --- a/ui-tree.c > +++ b/ui-tree.c > @@ -102,16 +102,23 @@ static void print_buffer(const char *basename, char *buf, unsigned long size) > } > > static void render_buffer(struct cgit_filter *render, const char *name, > - char *buf, unsigned long size) > + char *buf, unsigned long size) > { > char *filter_arg = xstrdup(name); > + struct strbuf sb_pre = STRBUF_INIT, sb_post = STRBUF_INIT; > + > + cgit_repo_create_url(&sb_pre, &sb_post, "plain", ctx.qry.head, NULL); > + > + fprintf(stderr, "'%s' '%s'\n", sb_pre.buf, sb_post.buf); > > html("
"); > - cgit_open_filter(render, filter_arg); > + cgit_open_filter(render, filter_arg, sb_pre.buf, sb_post.buf); > html_raw(buf, size); > cgit_close_filter(render); > html("
"); > > + strbuf_release(&sb_pre); > + strbuf_release(&sb_post); > free(filter_arg); > } > > > _______________________________________________ > CGit mailing list > CGit at lists.zx2c4.com > https://lists.zx2c4.com/mailman/listinfo/cgit