Is there a smarter way to handle intra-document links to nowhere?


(Pat Maddox) #1

intra-document-link.tbx (57.2 KB) is a really simple document - there’s a parent note, and a child note. The child note has a text link to the parent note. Using the built in HTML template, the parent HTML produces:

<h1>Parent</h1>

<h2>Child</h2>
<p>Child links back to <a href="#">parent</a>… but the link doesn’t really go anywhere.</p>

You can see that the text link becomes <a href="#">parent</a>, which isn’t really useful at all.

Ideally, there’d be some way for the link to produce an anchor that goes back to the parent header. But barring that, I’d rather just not have the link tag in there at all.

Is there a setting or attribute that will change the behavior of this “link to nowhere” within a document?


(Paul Walters) #2

Are you exporting, or just looking at the result in Preview? The link works fine if the “Parent” note is selected and I use File > Export > as HTML?


(Pat Maddox) #3

Ah yeah I’m not doing a multi-page export. I’m using exportedString so I’m dealing with a single HTML page, there are no real links.


(Mark Anderson) #4

Do you want intra-page jump links - or not. If the former, Tinderbox’s Help’s source TBX file aims to resolve just that issue - if you publish a composite page, how to retain notes between Tinderbox notes that are now links within a single HTML page. The technique does need some post-processing, as Tinderbox has never supported creating links to page anchors (without user configured post-processing).

If you want no link at all, I don’t think that’s possible as link creation is part of the overall HTML processing of $Text.


(Pat Maddox) #5

Yes I would like to have them.

This is the thing that’s not publicly available and I have to ask @eastgate for access, correct?

Are you able to share how to accomplish these links without sharing the TBX?


(Mark Anderson) #6

Let me go look. There’s nothing special - it just takes a little while to write (and more importantly - check) a new demo from scratch.

The second half of the process is the sed command in the TXT file to which I linked. I’ll see what I did at the template end. IIRC I seeded the $ID into the HTML and used the sed to matching the #anchor value.

More in a bit.

Footnote: $ID is intrinsic so differs between aliases and originals, so may result in unexpected links unless you plan carefully.


(Mark Anderson) #7

Ah, I think I too had $ID related issues so the TBX help file has aString attribute $AnchorName. A query finds all relevant (i.e. exporting) notes and has this action (which could equally well be a rule or edict):

$AnchorName =$HTMLExportPath.split("/").at(-1).replace(".html","");

Basically, we take the filename of the to-be-exported single HTML page and remove the file extension. Warning: Tinderbox only dupes exported HTML filenames at container scope, thus you need to consider if you have non-unique note names in your exporting pages and act accordingly**.

In our exporting templates, the recursing inner template includes this element for each note***:

<div class="header^value($OutlineDepth)^" id="x^value($AnchorName)^^if($IsAlias)^x^endIf^">

The ‘x’ preface in the id value is to ensure the value string is W3C standards compliant. I’m not sure about the $IsAlias fork in the text - I think we avoided alias issues by avoiding using them (or not trying to link to them). Having exported our single page of HTML, we then run this command line on it in Terminal:

sed -E 's:href=\"help[^\.]*\/([^\.]+)\.html\":href=\"#x\1\":g' print-export-source.html > print-export-source-proc.html

** this sort of gnarly edge case is, I suspect, one reason such a feature isn’t baked into the app as export can get quite nuanced and complex without an inexpert user realising (with resultant support issues arising).

*** IIRC we avoided aliases to simplify the problem of duplicated content and broken links

If you do need aliases and/or duplicate note titles, I suggest getting your export to work without them and then add in the extra aspects so you can more easily see where breakage occurs and get ideas as how to resolve that.