Linking to named locations

25 views
Skip to first unread message

Rob Beezer

unread,
Oct 26, 2016, 12:24:57 PM10/26/16
to sage-...@googlegroups.com
Is it possible to use a link from one Sage worksheet to another, with a named
location within the target worksheet? In other words, employ a link such as
written below?

<a href="target.sagews#location">link</a>

It seems that presently clicking on a link like this makes a new empty file with
the name "target.sagews#location"

A MWE is in

https://cloud.sagemath.com/projects/abdc6f9f-cf83-4b5e-ad1c-0012ae18c1d3/files/linkid/

Thanks,
Rob

Harald Schilly

unread,
Oct 26, 2016, 12:40:51 PM10/26/16
to sage-cloud
Hello, do you mean normal anchor links? Usually, that makes no sense,
since in many codemirror based editors those parts of the document
aren't part of the webpage at all -- they only show the region where
you're currently in (performance, etc.)

What I can offer is a way to reference a concrete line number in such
an editor. Here is the slightly dusted ticket:
https://github.com/sagemathinc/smc/issues/161

I'm aware that this ticket doesn't solve what you want to accomplish.

My take is: we should strip away everything beginning from the
hash-sign to the end when opening a URL. That should be a small change
to avoid such a stupidity. Second, would you expect that such a file
is being created when you land on the page, or rather to be told that
the file doesn't exist?

-- harald
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cloud+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cloud/MTAwMDAyNi5iZWV6ZXI.1477499094%40quikprotect.
> For more options, visit https://groups.google.com/d/optout.

William Stein

unread,
Oct 26, 2016, 1:18:16 PM10/26/16
to sage-cloud
On Wed, Oct 26, 2016 at 9:40 AM, Harald Schilly
<harald....@gmail.com> wrote:
> Hello, do you mean normal anchor links? Usually, that makes no sense,
> since in many codemirror based editors those parts of the document
> aren't part of the webpage at all -- they only show the region where
> you're currently in (performance, etc.)
>

He means he wants to jump to the first anchor link in an html:...
output of some worksheet cell. This is well defined and possible to
implement. I can't really think how to do it besides actually
running through all such outputs via javascrip then trying to match
with jquery. This will break when we rewrite sagews rendering using
react. Another potentially more robust (and more difficult) approach
would be parsing the source sagews file's contents.



William
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-cloud/CAGG4CB5gDnadK9X7nnQu1--%3DZ2z3PovpxZyforXcLohJ6AGDEA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--

Best Regards,
William Stein

CEO, SageMath, Inc.

William Stein

unread,
Oct 26, 2016, 1:19:18 PM10/26/16
to sage-cloud
Anyway... do-able but hard. Probably what we really want is just a
way to embed compute cells in static html documents -- i.e., invert
the whole thing and have something different than a sagews
worksheet.... But that's another can of worms for later.

Rob Beezer

unread,
Oct 26, 2016, 1:21:19 PM10/26/16
to sage-...@googlegroups.com
Thanks very much, Harald.

On 10/26/2016 09:40 AM, Harald Schilly wrote:
> Hello, do you mean normal anchor links? Usually, that makes no sense,
> since in many codemirror based editors those parts of the document
> aren't part of the webpage at all -- they only show the region where
> you're currently in (performance, etc.)

Yes, I'm trying to duplicate how a cross-reference would work in HTML from one
page to another, when you want to land at a definite place. I'm not surprised
that this is not so easy, since CodeMirror does not have the whole file/page.

> What I can offer is a way to reference a concrete line number in such
> an editor. Here is the slightly dusted ticket:
> https://github.com/sagemathinc/smc/issues/161
>
> I'm aware that this ticket doesn't solve what you want to accomplish.

If I could predict the line numbers of the targets of the pages I'm building in
advance, then this might work. But at this moment I think that is way too
complicated to predict, especially since the line count includes the rendered
HTML. Is there any intermediate step on the CodeMirror side that would
translate an identifier of some sort from the origin page to a line number of
the target page? The search/replace functionality or the bookmarks? In other
words, I can write *anything* into the link/cross-reference and I can write
*anything* in the vicinity of the target, and these can share a unique
identifier. But I'm going to guess that to go from one to the other would take
some non-trivial Javascript to work through the CodeMirror API to get a line
number from the target page.

> My take is: we should strip away everything beginning from the
> hash-sign to the end when opening a URL. That should be a small change
> to avoid such a stupidity. Second, would you expect that such a file
> is being created when you land on the page, or rather to be told that
> the file doesn't exist?

For SMC, a short-term fix would be to strip the post-# part for an
internal/relative URL. If the target page/worksheet does not exist, I'd expect
to get back "... does not exist" rather than creating a new empty one.

For my textbook project, the best thing to do now is to break the book into
small units (subsubsections?) up to whatever granularity an author provides, and
not even try to include a #-fragment in the URL. Then the reader will need to
scan/scroll the target page for what they expect to find.

Many (all?) of these cross-references in HTML are implemented as knowls. I'm
just assuming having knowls inside SMC is a big job best saved for later (or
maybe always a bad idea within CodeMirror). But as somebody who is
knowledgeable about knowls, I'd be very interested in your opinion on the
feasibility of that.

Thanks again for the reply.

Rob

Rob Beezer

unread,
Oct 26, 2016, 1:26:58 PM10/26/16
to sage-...@googlegroups.com
Thanks, William, for the ideas.

If sagews rendering is going to be redone, then we shouldn't think too hard
about it now. But I hope you can keep it in mind as you rework things.

An HTML document with compute cells would be a nice thing. Like an HTML page
with Sage cells. But hopefully a key difference would be the ability for a
reader to insert new text (annotations, basically) to the text and save the
results. Less ethereal than an HTML page.

Rob

William Stein

unread,
Oct 26, 2016, 1:28:17 PM10/26/16
to sage-cloud
On Wed, Oct 26, 2016 at 10:21 AM, Rob Beezer <bee...@ups.edu> wrote:
> Thanks very much, Harald.
>
> On 10/26/2016 09:40 AM, Harald Schilly wrote:
>>
>> Hello, do you mean normal anchor links? Usually, that makes no sense,
>> since in many codemirror based editors those parts of the document
>> aren't part of the webpage at all -- they only show the region where
>> you're currently in (performance, etc.)
>
>
> Yes, I'm trying to duplicate how a cross-reference would work in HTML from
> one page to another, when you want to land at a definite place. I'm not
> surprised that this is not so easy, since CodeMirror does not have the whole
> file/page.
>
>> What I can offer is a way to reference a concrete line number in such
>> an editor. Here is the slightly dusted ticket:
>> https://github.com/sagemathinc/smc/issues/161
>>
>> I'm aware that this ticket doesn't solve what you want to accomplish.
>
>
> If I could predict the line numbers of the targets of the pages I'm building
> in advance, then this might work. But at this moment I think that is way
> too complicated to predict, especially since the line count includes the
> rendered HTML.

Fortunately -- no, it doesn't.

The codemirror line numbers exactly match the lines numbers of the
sagews file you're generating. The entire rendered output is always
single line.


> Is there any intermediate step on the CodeMirror side that
> would translate an identifier of some sort from the origin page to a line
> number of the target page? The search/replace functionality or the
> bookmarks? In other words, I can write *anything* into the
> link/cross-reference and I can write *anything* in the vicinity of the
> target, and these can share a unique identifier. But I'm going to guess
> that to go from one to the other would take some non-trivial Javascript to
> work through the CodeMirror API to get a line number from the target page.

We could provide a full-text search ? feature, e.g.,

...filename?find='blah'

that jumps to the first instance of that search term.

>
>> My take is: we should strip away everything beginning from the
>> hash-sign to the end when opening a URL. That should be a small change
>> to avoid such a stupidity. Second, would you expect that such a file
>> is being created when you land on the page, or rather to be told that
>> the file doesn't exist?
>
>
> For SMC, a short-term fix would be to strip the post-# part for an
> internal/relative URL. If the target page/worksheet does not exist, I'd
> expect to get back "... does not exist" rather than creating a new empty
> one.
>
> For my textbook project, the best thing to do now is to break the book into
> small units (subsubsections?) up to whatever granularity an author provides,
> and not even try to include a #-fragment in the URL. Then the reader will
> need to scan/scroll the target page for what they expect to find.
>
> Many (all?) of these cross-references in HTML are implemented as knowls.
> I'm just assuming having knowls inside SMC is a big job best saved for later
> (or maybe always a bad idea within CodeMirror). But as somebody who is
> knowledgeable about knowls, I'd be very interested in your opinion on the
> feasibility of that.
>
> Thanks again for the reply.
>
> Rob
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cloud+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cloud/MTAwMDAyOC5iZWV6ZXI.1477502477%40quikprotect.
>
> For more options, visit https://groups.google.com/d/optout.



Rob Beezer

unread,
Oct 26, 2016, 1:42:34 PM10/26/16
to sage-...@googlegroups.com
On 10/26/2016 10:27 AM, William Stein wrote:
>> If I could predict the line numbers of the targets of the pages I'm building
>> in advance, then this might work. But at this moment I think that is way
>> too complicated to predict, especially since the line count includes the
>> rendered HTML.
>
> Fortunately -- no, it doesn't.
>
> The codemirror line numbers exactly match the lines numbers of the
> sagews file you're generating. The entire rendered output is always
> single line.

Oh, that's much better. I was looking at the line numbers in the gutter. ;-)

I've been trying to avoid a Python post-processing step, but maybe that is
inevitable. It'd be simple there to do a two-pass trip to first collect line
numbers of targets and then insert them into the links.

I guess the line numbers will become slightly off if a reader adds new text, but
they should stay close.

I'll keep an eye on: https://github.com/sagemathinc/smc/issues/161

Thanks,
Rob


William Stein

unread,
Oct 26, 2016, 1:46:33 PM10/26/16
to sage-cloud
On Wed, Oct 26, 2016 at 10:42 AM, Rob Beezer <bee...@ups.edu> wrote:
> On 10/26/2016 10:27 AM, William Stein wrote:
>>>
>>> If I could predict the line numbers of the targets of the pages I'm
>>> building
>>> in advance, then this might work. But at this moment I think that is way
>>> too complicated to predict, especially since the line count includes the
>>> rendered HTML.
>>
>>
>> Fortunately -- no, it doesn't.
>>
>> The codemirror line numbers exactly match the lines numbers of the
>> sagews file you're generating. The entire rendered output is always
>> single line.
>
>
> Oh, that's much better. I was looking at the line numbers in the gutter.
> ;-)

Those are the same line numbers I'm talking about. There is one line
for an entire block of output.

>
> I've been trying to avoid a Python post-processing step, but maybe that is
> inevitable. It'd be simple there to do a two-pass trip to first collect
> line numbers of targets and then insert them into the links.
>
> I guess the line numbers will become slightly off if a reader adds new text,
> but they should stay close.
>
> I'll keep an eye on: https://github.com/sagemathinc/smc/issues/161
>
> Thanks,
> Rob
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cloud+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cloud/MTAwMDAyMi5iZWV6ZXI.1477503752%40quikprotect.

Rob Beezer

unread,
Oct 26, 2016, 1:55:33 PM10/26/16
to sage-...@googlegroups.com
On 10/26/2016 10:46 AM, William Stein wrote:
> Those are the same line numbers I'm talking about. There is one line
> for an entire block of output.

OK, thanks - I'll get it straight when I get down to experimenting with the
sagews file.

Rob

William Stein

unread,
Oct 26, 2016, 1:57:39 PM10/26/16
to sage-cloud
While you're at it, try

https://github.com/sagemathinc/smc/issues/136

which is a bugfix you suggested a year ago, which I just merged.

>
> Rob
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cloud+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cloud/MTAwMDAwNS5iZWV6ZXI.1477504532%40quikprotect.

Rob Beezer

unread,
Oct 26, 2016, 2:37:53 PM10/26/16
to sage-...@googlegroups.com
On 10/26/2016 10:57 AM, William Stein wrote:
> While you're at it, try
>
> https://github.com/sagemathinc/smc/issues/136
>
> which is a bugfix you suggested a year ago, which I just merged.

Thanks! Seems to be working very well. A bit more on the ticket itself.

Rob
Reply all
Reply to author
Forward
0 new messages