aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Green <andy@warmcat.com>2018-06-18 14:25:59 +0800
committerAndy Green <andy@warmcat.com>2018-06-29 07:53:21 +0800
commit1ef4d396b1043c6b8e871d56bd93a85bc70bd533 (patch)
treebe5afda5e5c6d7a58209cdf22b1000124dcb0d6b
parentui-shared: add helper for generating non-urlencoded links (diff)
downloadcgit-1ef4d396b1043c6b8e871d56bd93a85bc70bd533.tar.xz
cgit-1ef4d396b1043c6b8e871d56bd93a85bc70bd533.zip
render: adapt for providing extra filter args for plain
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@warmcat.com> Reviewed-by: John Keeping <john@keeping.me.uk>
-rw-r--r--cgitrc.5.txt16
-rw-r--r--filter.c5
-rw-r--r--ui-tree.c9
3 files changed, 22 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..e4cb558 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -102,16 +102,21 @@ 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);
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);
}