[yelp/yelp-3-0] [libyelp] Changed relative links to use xref: URI scheme
- From: Shaun McCance <shaunm src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [yelp/yelp-3-0] [libyelp] Changed relative links to use xref: URI scheme
- Date: Mon, 19 Oct 2009 16:58:13 +0000 (UTC)
commit 6a0a475a2f5615bf028163f704bf9d5ee5561a5b
Author: Shaun McCance <shaunm gnome org>
Date: Sun Oct 18 22:30:51 2009 -0500
[libyelp] Changed relative links to use xref: URI scheme
This really simplifies the processing, as we don't have to guess from
the existence and position of # to determine if something is a cross
reference or just an internal link.
libyelp/yelp-uri.c | 38 +++++++++++++++++++++-----------------
stylesheets/db2html.xsl.in | 4 ++--
stylesheets/mal2html.xsl.in | 4 ++--
tests/test-uri.c | 4 +++-
tests/uri/ghelp-docbook-2.test | 2 +-
tests/uri/ghelp-mallard-2.test | 2 +-
6 files changed, 30 insertions(+), 24 deletions(-)
---
diff --git a/libyelp/yelp-uri.c b/libyelp/yelp-uri.c
index ea0946b..63452eb 100644
--- a/libyelp/yelp-uri.c
+++ b/libyelp/yelp-uri.c
@@ -50,7 +50,7 @@ static void resolve_data_dirs (YelpUri *uri,
static void resolve_ghelp_uri (YelpUri *uri);
static void resolve_man_uri (YelpUri *uri);
static void resolve_info_uri (YelpUri *uri);
-static void resolve_relative_multipage (YelpUri *uri);
+static void resolve_xref_uri (YelpUri *uri);
static void resolve_page_and_frag (YelpUri *uri,
const gchar *arg);
static void resolve_gfile (YelpUri *uri,
@@ -258,21 +258,19 @@ resolve_async (YelpUri *uri)
else if (g_str_has_prefix (priv->res_arg, "info:")) {
resolve_info_uri (uri);
}
- else if (strchr (priv->res_arg, ':')) {
- priv->tmptype = YELP_URI_DOCUMENT_TYPE_EXTERNAL;
- /* FIXME: resolve as external URI */
- }
- else if (strchr (priv->res_arg, '/')) {
- resolve_file_path (uri);
- }
- else if (priv->res_base != NULL) {
- YelpUriPrivate *base_priv = GET_PRIV (priv->res_base);
+ else if (g_str_has_prefix (priv->res_arg, "xref:")) {
+ YelpUriPrivate *base_priv;
+ if (priv->res_base == NULL) {
+ priv->tmptype = YELP_URI_DOCUMENT_TYPE_ERROR;
+ goto done;
+ }
+ base_priv = GET_PRIV (priv->res_base);
switch (base_priv->doctype) {
case YELP_URI_DOCUMENT_TYPE_UNRESOLVED:
break;
case YELP_URI_DOCUMENT_TYPE_DOCBOOK:
case YELP_URI_DOCUMENT_TYPE_MALLARD:
- resolve_relative_multipage (uri);
+ resolve_xref_uri (uri);
break;
case YELP_URI_DOCUMENT_TYPE_MAN:
/* FIXME: what do we do? */
@@ -297,10 +295,15 @@ resolve_async (YelpUri *uri)
break;
}
}
+ else if (strchr (priv->res_arg, ':')) {
+ priv->tmptype = YELP_URI_DOCUMENT_TYPE_EXTERNAL;
+ /* FIXME: resolve as external URI */
+ }
else {
resolve_file_path (uri);
}
+ done:
g_idle_add ((GSourceFunc) resolve_final, uri);
}
@@ -779,9 +782,10 @@ resolve_info_uri (YelpUri *uri)
}
static void
-resolve_relative_multipage (YelpUri *uri)
+resolve_xref_uri (YelpUri *uri)
{
YelpUriPrivate *priv = GET_PRIV (uri);
+ const gchar *arg = priv->res_arg + 5;
YelpUriPrivate *base_priv = GET_PRIV (priv->res_base);
priv->tmptype = base_priv->doctype;
@@ -789,18 +793,18 @@ resolve_relative_multipage (YelpUri *uri)
priv->search_path = g_strdupv (base_priv->search_path);
priv->docuri = g_strdup (base_priv->docuri);
- if (priv->res_arg[0] == '#') {
+ if (arg == '#') {
priv->page_id = g_strdup (base_priv->page_id);
- priv->frag_id = g_strdup (priv->res_arg + 1);
+ priv->frag_id = g_strdup (arg + 1);
}
else {
- gchar *hash = strchr (priv->res_arg, '#');
+ gchar *hash = strchr (arg, '#');
if (hash) {
- priv->page_id = g_strndup (priv->res_arg, hash - priv->res_arg);
+ priv->page_id = g_strndup (arg, hash - arg);
priv->frag_id = g_strdup (hash + 1);
}
else {
- priv->page_id = g_strdup (priv->res_arg);
+ priv->page_id = g_strdup (arg);
priv->frag_id = NULL;
}
}
diff --git a/stylesheets/db2html.xsl.in b/stylesheets/db2html.xsl.in
index 02e597c..cfd681d 100644
--- a/stylesheets/db2html.xsl.in
+++ b/stylesheets/db2html.xsl.in
@@ -73,10 +73,10 @@ FIXME: yelp:cache no longer works
</xsl:param>
<xsl:choose>
<xsl:when test="$depth_in_chunk != 0">
- <xsl:value-of select="concat('#', $linkend)"/>
+ <xsl:value-of select="concat('xref:#', $linkend)"/>
</xsl:when>
<xsl:otherwise>
- <xsl:value-of select="concat('?', $linkend)"/>
+ <xsl:value-of select="concat('xref:', $linkend)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
diff --git a/stylesheets/mal2html.xsl.in b/stylesheets/mal2html.xsl.in
index a8af26a..4f2d637 100644
--- a/stylesheets/mal2html.xsl.in
+++ b/stylesheets/mal2html.xsl.in
@@ -44,10 +44,10 @@
<xsl:when test="contains($xref, '#')">
<xsl:variable name="pageid" select="substring-before($xref, '#')"/>
<xsl:variable name="sectionid" select="substring-after($xref, '#')"/>
- <xsl:value-of select="concat('#', $pageid, '/', $sectionid)"/>
+ <xsl:value-of select="concat('xref:', $pageid, '#', $sectionid)"/>
</xsl:when>
<xsl:otherwise>
- <xsl:value-of select="concat('#', $xref)"/>
+ <xsl:value-of select="concat('xref:', $xref)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
diff --git a/tests/test-uri.c b/tests/test-uri.c
index b9b41ec..bf295f0 100644
--- a/tests/test-uri.c
+++ b/tests/test-uri.c
@@ -141,6 +141,8 @@ print_uri (gchar *orig, YelpUri *uri, GOutputStream *stream)
g_free (out);
g_free (tmp);
}
+
+ g_output_stream_write (stream, "\0", 1, NULL, NULL);
}
static void run_test (gconstpointer data)
@@ -177,7 +179,7 @@ static void run_test (gconstpointer data)
print_uri (curi, uri, outstream);
out = (gchar *) g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (outstream));
g_free (curi);
- g_assert_cmpstr (out, ==, contents);
+ g_assert (!strncmp (out, contents, bytes));
}
static int
diff --git a/tests/uri/ghelp-docbook-2.test b/tests/uri/ghelp-docbook-2.test
index cf96c42..24d0a7b 100644
--- a/tests/uri/ghelp-docbook-2.test
+++ b/tests/uri/ghelp-docbook-2.test
@@ -1,4 +1,4 @@
-ghelp:user-guide gosnautilus
+ghelp:user-guide xref:gosnautilus
DOCUMENT TYPE: DOCBOOK
DOCUMENT URI: ghelp:user-guide
CANONICAL URI: ghelp:user-guide?gosnautilus
diff --git a/tests/uri/ghelp-mallard-2.test b/tests/uri/ghelp-mallard-2.test
index 9b2dd03..c8f5133 100644
--- a/tests/uri/ghelp-mallard-2.test
+++ b/tests/uri/ghelp-mallard-2.test
@@ -1,4 +1,4 @@
-ghelp:gnome-doc-mallard-spec mal_block#basic
+ghelp:gnome-doc-mallard-spec xref:mal_block#basic
DOCUMENT TYPE: MALLARD
DOCUMENT URI: ghelp:gnome-doc-mallard-spec
CANONICAL URI: ghelp:gnome-doc-mallard-spec?mal_block#basic
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]