Showing posts with label Lynx browser. Show all posts
Showing posts with label Lynx browser. Show all posts

Wednesday, September 14, 2011

Lynx: Associating filetypes with a program in Windows

After a few hours of trying and failing in lynx.cfg and searching the Internet, I found a reasonably good collection of ideas (kudos to Kenneth Kwok), which served me with inspiration for a working solution.

• The version of Lynx is 2.8.7rel1, unfortunately it doesn't support SSL (gonna work on getting Lynx with that some day...).
N., 15.09.2011. update: A fully functional and SSL-enabled, albeit an older, 2.8.5rel1, version of the browser is available at Claudio Santambrogio's (csant) website (beware that export and other restrictions may still apply to the downloader's country).

As I needed an SSL-based browser, then out of curiosity I started comparing both Lynx browsers' config files and to my great delight found that csant's external app configuration was more elegant than my previous discovery. Jump to a description of how to implement the better solution.

And yes, the options inspired by Kenneth Kwok are still valid, but there are now less scenarios to use them.
• The operating system is Windows xp SP3, other Windows operating systems may also apply, but exact instructions on how to change environment variables were gleaned from this version of Windows.

Unlike in the linked article, it turned out that I didn't need to use a .mailcap file to associate a helper app.

The interesting part is that Windows Lynx (still) requires batch files to send requests for an external application and a path to them must be set as a global or user environment variable.
  • Create a folder that will hold batch files. I created one in
    C:\Program Files\Lynx\Batches
  • Create an environment variable pointing to that path:

    In My Computer/System Properties > go to Advanced tab > click "Environment Variables" button > in the relevant window's "System variables" section > scroll down to Path, select it, click the Edit button;

    In the path editing window, the Path string is long, but you can add a semicolon to the end of the string (if it's missing), then right after the semicolon add

    C:\Program Files\Lynx\Batches

    and that's it. (No additional semicolon required.)

    Click OK to close the window, click OK in Environment Variables window — This will save and update the path in Windows xp (maybe 2000, too) or newer; click OK for System Properties window.

    You won't need to restart unless it's a Windows 9x OS, for which you'd need to edit autoexec.bat, enter a short-form path à la C:\PROGRA~1\Lynx\Batches and restart the system for changes to take effect.
  • Now, in the C:\Program Files\Lynx\Batches folder itself, assuming you only want an image viewer program to be associated, create paint.bat, edit it as follows:
    @ECHO OFF
    C:\WINDOWS\SYSTEM32\Mspaint.exe %1
    ^ In addition, you may wish to add %2 %3 %n — if you know that there may be more arguments passed from Lynx, but there's usually one.
    Save the batch file.
  • In lynx.cfg (opened either via WordPad or Notepad2 or something that supports both CR & LF newlines), go to a certain place in the file by searching for the image/png pattern. There, you will see which MIME types you must activate for each filetype suffix.

    I uncommented (deleted a hash # from the start of the line) all that were web images, such as those concerning .png, .gif, .jpg and .jpeg.
  • Then in lynx.cfg, go to part of the file using the VIEWER: search pattern. There, you will see a list of program commands associated with a particular MIME-type (they are short by default, because they're typically UNIX-specific).
    N., 15.09.2011.:
    Uncomment, or rather, copy, paste, and uncomment those for image formats, and modify the commands to look like this:
    VIEWER:image/gif:start mspaint %s
    VIEWER:image/png:start mspaint %s
    VIEWER:image/jpeg:start mspaint %s
    VIEWER:image/tiff:start gimp-2.6.exe %s #special case
    • The superb catch ^ is where one must use the start command to invoke a program that's located in the Windows Path environment variable.
    mspaint is the command-line name of the Windows Paint program, which is located in C:\WINDOWS\SYSTEM32 and that address is typically set as one of the locations in the Path environment variable.
    gimp-2.6.exe is a different case, where I separately had to include C:\Program Files\GIMP-2.0\bin in the Path environment variable to make it launch, as for some reason it was impossible to use the full program path in the Lynx config file.
    Uncomment, or rather, copy, paste, and uncomment those for image formats, and modify the commands to look like this:
    VIEWER:image/gif:paint.bat %s&:NON_XWINDOWS
    VIEWER:image/png:paint.bat %s&:NON_XWINDOWS
    VIEWER:image/tiff:gimp.bat %s&:NON_XWINDOWS
    VIEWER:image/jpeg:paint.bat %s&:NON_XWINDOWS
    • Up here ^, add paint.bat right after a colon that follows the mimetype;
    %s is the wildcard for the filename to be entered;
    • The ampersand & is there to leave the program in the background. It can be there in Windows, but it's useful in Unix-like systems.
    :NON_XWINDOWS [sic] basically specifies that the targetted application is not an X Window System program and this option can be there, too. In Windows it may mean that the batch program is not exactly a graphical program either.
  • Save the configuration file and I think you should be done.
    Launch Lynx, go to a page with an image file, then on it, press Enter/Return or the left key to activate.
Similar steps can be made for other filetypes and MIME-types (which can be added, btw, since the list in lynx.cfg is non-exhaustive) and you can add programs different than Paint for other filetypes. Above, I have setup a batch file to run The GIMP for the TIFF filetype.

Thursday, May 5, 2011

Adding formatting to CSS generated content

This solution (or workaround, if you like) came out of a need to write text visible only for modern browsers.

I have a case, where such text would point out a formatting feature containing further information in <ACRONYM> tags, only that severely out-of-date and text-only browsers do not support the dotted underline and border properties, so help text for these browsers was not necessary. I wouldn't use JavaScript (which uses document.write) and there are websites like WordPress (IINM) that only allow editing CSS files and may forbid JavaScript.

The CSS 2.1 specification has it that it's possible to create generated content before or after an element, using :before and :after pseudo-elements, respectively.

The best explanation about how it works is in the CSS2 technical recommendation at W3.

The difficult part is in how to format text within the content: property.

Well, there are two ways that work and a third way that is a workaround. The two ways are well-documented in the W3 technical recommendation (see above link), where it's possible to specify attributes with first-letter and first-line (for longer texts within content) pseudo-elements.

The Third Way

Specifying formatting for bits of text within the content: property is impossible, so the solution is to create one or more rulesets of :before or :after pseudo-elements with similar declaration blocks, wherein some rulesets' declarations are different.

In HTML, write the following snippets of code:
<SPAN CLASS=text></SPAN><SPAN CLASS=dotted></SPAN><SPAN CLASS=bits></SPAN> and so on...
In CSS, example code shows the following:
.text:after {content:'^ Mouse over text with\ ';}
.dotted:after {content:'dotted underlines'; border-bottom:dotted 1px; border-bottom-color:inherit;}
.bits:after {content:'\ for more infobits'}

/* ^ Use the backslash \ to escape special characters, including a space (or it won't be shown). */
The result:
Browsers, which don't support CSS :before and :after pseudo-elements, won't see this. ^

The result is used here in a previous blog post. The example text snipped was put in place of a paragraph break, but since the Lynx browser wouldn't create a paragraph break inside a list with <P></P> or <BR><BR>, or instead there was more space added in modern browsers with variants that included a non-breaking space &nbsp;, then the best solution was to wrap above HTML code within <DIV> tags and add a non-breaking space —
<DIV>&nbsp;<SPAN CLASS=text></SPAN></DIV>
Characteristics
The most interesting and equally obscure characteristic with CSS generated content is, that generated text cannot be directly copied — even when selecting a normal area that wraps around generated content, then only the wraparound selection is pasted.

While this may be useful to wonks interested about protecting original content, then it's still a chore to implement, and advanced users would still be adept at copying text from near the source (unless obfuscated). The technique is similar to mechanisms that disable direct text copying in advanced document files, like PDF, but with the difference in sophistication: PDF files have encryption and other features.

The (dubious) advantage is, that direct copying is disabled; and the disadvantage is, that a number of browsers don't support these pseudo-classes. And not just older (Netscape 4) and niche browsers (Lynx, Links, Elinks), but even Internet Explorer 7 doesn't.

16.12.2015. Update:

I recently wanted to add newlines to generated content, but after several turns of trial-and-error with \A in content:, I turned to a search engine and found about the best blog post by Chee Aun that describes the issue in detail.

The solution with Firefox is to specify white-space:pre-wrap — This preserves both wrapping and newlines.