[PATCH v4 15/16] render: adapt for providing extra filter args for plain
Andy Green
andy at warmcat.com
Wed Jun 20 12:13:15 CEST 2018
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 <andy at warmcat.com>
Reviewed-by: John Keeping <john at keeping.me.uk>
---
cgitrc.5.txt | 16 +++++++++++-----
filter.c | 5 ++++-
ui-tree.c | 11 +++++++++--
3 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 62d7c2a..99fc799 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -738,11 +738,17 @@ owner filter::
output. The output is included in the Owner column.
render filter::
- This filter is given a single parameter: the filename of the source
- file to render. The filter can use the filename to determine (for
- example) the syntax highlighting mode. The contents of the file that
- is to be rendered is available on standard input and the rendered
- content is expected on standard output.
+ This filter is given a single required parameter: the filename of
+ the source file to render. The filter can use the filename to
+ determine (for example) the syntax highlighting mode. The
+ contents of the file that is to be rendered is available on standard
+ input and the rendered content is expected on standard output. Two
+ additional optional parameters are the base URL path and optional
+ URL parameter arguments needed to adapt relative paths in the input
+ to absolute URLs pointing to the "plain" version of the file in the
+ repo rev context, eg, "/myvirt/reponame/plain" and "?h=mybranch"
+ could be used to convert input references like "pics/myfile.png" to
+ '<img src="/myvirt/reponame/plain/pics/myfile.png?h=mybranch">'
source filter::
This filter is given a single parameter: the filename of the source
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("<div class='blob'>");
- 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("</div>");
+ strbuf_release(&sb_pre);
+ strbuf_release(&sb_post);
free(filter_arg);
}
More information about the CGit
mailing list