When you view the source code of a website - you get a text-based document:
view-source:http://example.com/
I suppose, what I am asking is: is possible to have: 'http://example.com/index.txt', and remove the: '/index.txt' (using .htaccess) - so the website acts like a text document.
You just need to create a .htaccess file in your root directory and set the directory index like so:
DirectoryIndex index.txt
.htaccess Guide - DirectoryIndex Uses
In most cases, I would advise against this as you cannot use any form of code or formatting within your document. This means no hyperlinking, no images, nothing apart from plain text.
The important aspect in this is the Content-Type HTTP header sent by the server. If it's the usual text/html, the browser will interpret the document as HTML. To serve plain text, the header needs to specify text/plain. You can configure Apache to serve files as plain text using:
AddType text/plain .html .txt
Add whatever file extensions you want to that list (here: .html .txt).
If you're displaying plain text documents whose format is critical (frames, tables or columnar reports), you can wrap them in a <PRE> </PRE> couple of tags, or even better, <HTML><BODY><PRE> on top and </PRE></BODY></HTML> on bottom, which ensures wider compatibility. You can do this "on the fly" or mantain copies on disk/db for future use.
The <PRE> tag is used to tell the browser that the text enclosed is preformatted, and is usually rendered with a monospace font like Courier or similars, preserving text formatting, column alignment, etc.
Related
For most of my project's documentation I prefer a standard sphinx layout. However for the landing page I would prefer to use custom HTML/CSS/JS without any of the layout, TOC, or sidebars of the normal sphinx site. Is there a way to include a raw HTML standalone page in a sphinx-generated website in a way that completely disregards the normal layout of the rest of the site?
As a counter example I know that I can include raw HTML bits into a page using the following (see also this question)
.. raw:: html
:file: myfile-html
However this just embeds a file within the normal layout. I would like to have a completely standalone HTML page.
I just ran into this problem myself, and the way I solved it was to simply include the html file in my source/_static folder, then refer to it with a relative link.
So if source/_static/my_standalone.htm is the path where I have my non-generated HTML file, and the .rst file where I want to type my link is at source/otherfolder/index.rst, I write it like this in my rst:
Link to my non-Sphinx HTML file
===============================
To get to my standalone, non-generated HTML file,
just `click here <../_static/my_standalone.html>`_ now!
How do I convert an HTML file with content folder to a self-contained HTML file which can be viewed from anywhere with its images etc.
How can it be done so that it's also editable and stays self-contained, post-edit?
I basically need to make HTML file based documentation which can be viewed from anywhere. Unfortunately it HAS to be HTML, otherwise I would have made PDFs
You can use pandoc, it has an option to create self-contained html files https://pandoc.org/MANUAL.html#option--self-contained.
If you start with html, this is the command.
pandoc in.html --self-contained -o out.html
This tool can do a lot more things, for example, you can also generate html from markdown files or generate pdfs instead.
The most direct way is to convert all asset urls to data: urls. (There are online coverters available that will take a provided asset and produce a data: url from it.)
A possibly simpler way is to convert image and font urls to data: urls while instead inlining scripts and css.
Edit: Possibly of interest: inliner, a Node utility for doing this kind of thing. "Turns your web page to a single HTML file with everything inlined". Also performs a number of minifying optimizations.
I don't know exactly what you're envisioning, but HTML was never meant to be fully self-contained. There may be some loopholes that allow it in the end, but to my knowledge there are no premade tools that do this 'conversion'.
It would require the following things:
Converting all linked style sheets and scripts to inline style sheets and scripts. This means that whenever there's a <script src="http://url.to/foo.js"></script> you'll have to download foo.js and include it as such: <script type="text/javascript"> [this is the content of foo.js] </script>. Something similar applies to CSS and other linked source files.
Downloading all linked media (images mostly, I presume) and converting them to blobs (a service that provides you with a base64 blob you can use within a HTML file is https://www.base64-image.de/). This means replacing <img src="http://url.to/image.jpg" /> with <img src="data:image/png;base64,[converted image data goes here] />.
So there's gonna be some manual labour involved there, but it probably can be done (almost) fully.
Possibly there's a way to accomplish what you're wanting to do another way though, what exactly is your reason for wanting this?
Here's another option: write your documentation in markup, then use a tool such as "Marked 2" (http://marked2app.com) to convert to self-contained html. Works slick. Plus you can go back and edit the markup any time you need to update your documentation, then simply re-export your html file.
I am trying to include some images in a Genshi template for my Trac plugin, but it always shows only the alternative text because it cannot find the images.
I have the following (X)HTML code:
<div>
<img src="file://c:/path/to/image.png" alt="asdf" />
</div>
When I use this code with a simple html file and open it in the browser, the image is displayed correctly, which means that both the path and syntax are correct.
But when I insert the code snippet into a Genshi template and use it within Trac, the image cannot be found. However, when I look at the HTML source code in the web browser and copy the URLs into a new browser tab, it is again displayed correctly. This means that only the server cannot find the image.
The images are in a directory inside the python-egg file, and the path points directly to the directory created by Trac, which also contains my CSS and HTML files, both of which are loaded correctly. The images are correctly referenced in the setup script which creates the egg.
How do I have to reference images in (X)HTML documents when using them with a server?
Is there a special way to include images in Genshi documents? (I haven't found one.)
Thanks to the comment of RjOllos and this site I was able to fix it by trying all of the URL types. Although it says for a plugin to be /chrome/<pluginname>, it was actually just /chrome that worked. See the edit below! So the full URL is then <ip>:<port>/chrome/path/to/image.png.
EDIT: I discovered I actually used the /chrome/pluginname version, just that I did not use the name of my plugin as "pluginname". See my comment below. It seems like /chrome/pluginname should actually be /chrome/htdocsnameor something like that, in case you use a different name rather than the plugin name when implementing the ITemplateProvider. In my case I called it images, which was the same name as the folder. END OF EDIT
Another mistake I made was forgetting the initial slash (chrome/path/to/image.png), which caused Trac to assemble the URL to <ip>:<port>/<current page>/chrome/path/to/image.png.
I created a link in a html file to a text file (logcat.txt).
if i open this logcat.txt file via html link, need to open the file and pointed to specific line having keyword("Mylog").
How can i Do it?
You cannot link directly to a location inside a plain text file, even in a simple manner like by line number. There is nothing illogical with the idea; there are ways to link to a location in an HTML file, or in a PDF file, using a URL with a fragment identifier at the end (...#foo or ...#page=42 for example). And it would be possible to define a similar mechanism for plain text resources; but no such mechanism has been defined so far, still less implemented.
You might consider writing server-side code that converts the plain text file to an HTML document (possibly rendered with white-space: pre) so that you can link to specific locations there.
I created a static website in which each page has the following structure:
Common stuff like header, menu, etc.
Page specific stuff in main content div
Footer
In this website, all the common content is duplicated in each page. In order to improve the maintainability I refactored the pages to use server-side includes (SSI) so that the common content is not duplicated. The structure of each page is now
SSI for Common stuff like header, menu, etc.
Page specific stuff in main content div
SSI for footer
In the refactored site, for some reason the French characters no longer display properly in the page-specific content area, though they display fine in the content included via SSIs.
The included header specifies the character set as:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
If I open one of the main content pages in a browser it tells me that the character encoding is ISO-8859-1. I've tried adding a .htaccess file to the folder with the lines
AddDefaultCharset UTF-8
AddCharset UTF-8 .shtml
AddCharset UTF-8 .html
But still those pesky French accents aren't displaying properly on the version of the site that uses SSIs.
You are serving your pages as UTF-8, which is good, but at least some of the page is being dragged in from files which are not actually saved as UTF-8. SSI just throws the raw bytes in, it doesn't attempt to recode the includes so that their charsets match the file they're being included into.
You need to go through all your html and include files in a text editor and make sure each one is saved as UTF-8.
As John mentioned, you can avoid encoding issues by using character references for all non-ASCII characters, but it's a tremendous pain.
Your HTML document is using UTF-8 encoding, try these character codes for your accented letters: http://www.tony-franks.co.uk/UTF-8.htm
I had the same problem as you and finally found a solution that fixed it.
UTF8 makes an extra line on my site
Save all your files as UTF-8 without BOM (http://en.wikipedia.org/wiki/Byte_order_mark).