Use _canonical_uri to embed an external plain text file?

424 views
Skip to first unread message

si

unread,
Nov 6, 2020, 1:21:09 PM11/6/20
to TiddlyWiki
I have some external source-code files that I would like to add to my wiki as plain text so that I can make notes on them.

Rather than making another copy of the text, I thought I would be able to embed the file as I would a PDF or HTML file.

I set _canonical_uri to ./folder/code.py and changed the type to text/plain. This didn't work.

I noticed that if I change the type to text/html, the text does get embedded as though it were an html file.

Is there any way to embed text and have it appear as regular plain text?

TW Tones

unread,
Nov 6, 2020, 5:11:40 PM11/6/20
to TiddlyWiki
Si,

Have you tried the html object tag?

I have a newtworkcheck batch that I launch from a TiddlyDesktop wiki, that returns the result in a text file.


<a title={{!!tooltip}} href="file:///C:\Data\batches\runnetworkcheck.cmd" > Go</a>

<$button set="Networkcheck!!last-refresh" setTo=<<now "0hh:0mm">> >
Refresh {{Networkcheck!!last-refresh}}
</$button>

<object width="100%" height="930" data="file:///C:\Data\batches\networkcheck.txt"></object>

It also has a button that sets a field to cause a refresh and time stamps it.

Tones

si

unread,
Nov 8, 2020, 7:58:58 AM11/8/20
to TiddlyWiki
Hi Tones,

The HTML object method does display the file, but I can't add annotations to with dynannotate.I realize I was not clear about what I wanted to use the file for in my original post.

I'm trying to get the text file to display just as though it were a plain text tiddler stored in the wiki. I know I won't be able to edit it from the wiki, but I was hoping that I would be able to add annotations with dynannotate.

TW Tones

unread,
Nov 8, 2020, 8:34:46 PM11/8/20
to TiddlyWiki
Si,

Understood. I have tried to encourage others with more knowledge on this to help us make such included content interact more within tiddlywiki. I understand the problem may relate to the object being included in the standard DOM, but tiddlywiki manages its own DOM tree to preform all it's magic.

keep in mind I am not expert here.

A higher level of interaction with html and the standard DOM including between the DOM and Tiddlywikis own one would be nice, For example an action that will populate a local tiddler with the content displayed by the object.

I have actually installed full featured html pages within tiddlywiki, and by providing the additional files, css and scripts in the same directory as the single file tiddlywiki, have got them working. So I am confident we can create ways to interact with external resources.

Simply being able to save the output of something like;
<object width="100%" height="930" data="file:///C:\Data\batches\networkcheck.txt"></object>
into a tiddler, variable or on wikification would be great.

However you would be applying dynannotate to a copy.

Regards
Tones

Joshua Fontany

unread,
Nov 8, 2020, 11:44:49 PM11/8/20
to TiddlyWiki
This is possible if you are running your wiki on Node.js. If it is a single-file standalone HTML wiki your best bet is to import the text files by drag'n'drop.

If you are running on Node.js, you can use a "tiddlywiki.files" file (documentation here), to include a whole folder full of files at once into tiddlywiki. The config file defines the other "meta-data fields" like "type", etc. The folder in question has to be inside said wiki's "tiddlers" folder (where "tiddlers is parallel to a "tiddlywiki.info" config file). Your structure would be similar to:

WikiDir
|- "tiddlywiki.info" (json file for wiki config)
|- "tiddlers" dir
        |- "text-files" dir
                |- "tiddlywiki.files" (json file for text-file import config)
                |-  all the files to import 
        |- "other" dirs (in the "tiddlers" dir)
        |- tiddlers.tid(s) (text tiddlers in the "tiddlers" dir)  
|- "files" dir (outside "tidders" to serve images and such)

si

unread,
Nov 9, 2020, 9:21:16 AM11/9/20
to tiddl...@googlegroups.com
Hi Joshua, thanks for your reply.

I tried out your suggestion for node.js and although the tiddlers for the text-files do get created, the text still won't display.

I created the file "tiddlers/text-files/tiddlywiki.files" as you described, and put the file "Text file.txt" into the same directory.

Here is the contents of "tiddlywiki.files":

{
   
"directories": [
       
{
           
"path": "",
           
"filesRegExp": "^.*\\.txt$",
           
"isTiddlerFile": false,
           
"fields": {
               
"title": {"source": "basename-uri-decoded"},
               
"created": {"source": "created"},
               
"modified": {"source": "modified"},
               
"type": "text/plain",
               
"tags": ["$:/tags/AttachedFile"],
               
"text": "",
               
"_canonical_uri": {"source": "filename", "prefix": ""}
           
}
       
}
   
]
}


The result is that a tiddler for "Text file" does appear in my wiki, but still no text is displayed. See here.

I also tried the same thing but with PDFs and still the content would not display.

Any idea what I'm doing wrong?
Message has been deleted

Anjar

unread,
Nov 9, 2020, 10:32:27 AM11/9/20
to TiddlyWiki
Hi,

I'm rather interested in this as well as it may be a way of implementing access control through htaccess; you can have some content public but also put some content in a subfolder protected by htaccess and include it in the tiddlywiki. Works perfectly for pfs etc.

Best,
Anders

TiddlyTweeter

unread,
Nov 9, 2020, 12:17:08 PM11/9/20
to TiddlyWiki
Ciao Anjar

... you can have some content public but also put some content in a subfolder protected by htaccess and include it in the tiddlywiki. Works perfectly for pfs etc

Right. Though that is nothing to do with TW, or changes anything you do in it.

The only TW bit I can see is you COULD use the Bob version to create/delete  any needed .htaccess files on-the-fly.

Thoughts
TT

TiddlyTweeter

unread,
Nov 9, 2020, 12:19:17 PM11/9/20
to TiddlyWiki
text/html is likely the wrong type.

TT

Saq Imtiaz

unread,
Nov 9, 2020, 1:13:51 PM11/9/20
to TiddlyWiki
Skip the text and canonical Uri fields.

Anjar

unread,
Nov 9, 2020, 3:00:06 PM11/9/20
to TiddlyWiki
Hi TT,

I'm not sure I follow your thoughts. For example, I have an online tiddlywiki for sheet music and since some of the scores are in public domain and others not, I separate them and protect the latter with htaccess. That way I can still make a tiddler for it and tag it etc. and embed the pdf with _canonical_uri and application/pdf, but restrict access to myself only.

Similarly, I guess it would be trivial to have a html/php form embedded in tiddlywiki from a protected folder that creates "protected tiddlers" in an otherwise public tiddlywiki, which at least I think expands the usability of tiddlywiki, especially if it becomes possible to load those external files at start and treat them as ordinary tiddlers. Just a thought:)

Best,
Anders

TiddlyTweeter

unread,
Nov 9, 2020, 4:24:15 PM11/9/20
to TiddlyWiki
Ciao Anjar

My point was ONLY that .htaccess setup is NOT a TW issue. It is a server admin issue. So why are we talking about it?

In very smart TW like BOB you can manage the needed files in the online server version. But that is likely rare.

Hope this clarifies the scope for you.

TT

Joshua Fontany

unread,
Nov 9, 2020, 10:46:37 PM11/9/20
to TiddlyWiki
Saq caught it! You are overwriting the text field of each tiddler as it is imported with a blank string. Delete the "text" and "_cannonical_uri" fields from the config json, and you should be good. The reason we do not use "_canononical_uri" in this instance is that we are not asking the browser to fetch anything from a URL. Once the text from each file is loaded into TW as a tiddler, it is part of the native info ecosystem of TW.

I am actually exploring a way (using a well done XML pathing plugin) to "chunk" out PDFs into individual paragraph tiddlers (just an idea at this point).

Hope this helps,
Joshua F

si

unread,
Nov 10, 2020, 6:17:57 AM11/10/20
to TiddlyWiki
Thanks a lot Saq + Joshua!

I am actually exploring a way (using a well done XML pathing plugin) to "chunk" out PDFs into individual paragraph tiddlers (just an idea at this point).

Wow this would be awesome. I use PDFs all the time but they are incredibly inflexible. Slicing them into tiddlers would totally obliterate the barrier between reading and note taking. Please share if you get it working!

si

unread,
Nov 10, 2020, 2:23:29 PM11/10/20
to TiddlyWiki
Sorry guys I have another question about tiddlywiki.files files. Last one I promise!

I was hoping that I could get TiddlyWiki to load files from subfolders as well, with their titles set to their full file path.

Looking at the docs it seems this is not possible by default:

Note that the directory is not recursively searched; sub-directories are ignored (https://tiddlywiki.com/#tiddlywiki.files%20Files)

But I just wondered if there were any tricks to get this to work?

Joshua Fontany

unread,
Nov 10, 2020, 7:31:29 PM11/10/20
to TiddlyWiki
Researching the javascript that implements this in boot.sj, and... no.

You would need a subfolder and a `tiddlywiki.files` file for each folder of text files that you are importing.

BONUS EASTER EGG: The text files you are importing don't actually have to "live" in your wiki folder at all! The "path" property of the config can be set to a relative or absolute path including locations external to the wiki folder (such as "C:/text-files/folder1") and TW fetches from that location when building the wiki in memory.

So you can keep your folder structure on disk, not have to move them all into the wiki folder, but do a bit more setup to import them all.

Best,
Joshua Fontany
Reply all
Reply to author
Forward
0 new messages