# shtmlview(n) 1.0.0 shtmlview "basic HTML and Markdown viewer widget"

## Name

shtmlview - pur Tcl/Tk text widget with basic support for HTML and Markdown markup rendering

## Synopsis

- package require Tk
- package require snit
- package require Markdown ;# optional Markdown support
- package require img::jpeg ;# optional jpeg image support
- package require shtmlview::shtmlview ?1.0.0?

- ::shtmlview::shtmlview pathName ?options?
- pathName back
- pathName browse filename ?args?
- pathName dosearch string direction
- pathName forward
- pathName getFiles
- pathName getHistory
- pathName getTextWidget
- pathName helptext cmd ?options?
- pathName home
- pathName open
- pathName reload
- pathName url

## Description

The shtmlview::shtmlview package provides the shtmlview::shtmlview widget which is a standard tk text widget with support for rendering a reasonable subset of html tags and, if the tcllib library Markdown is available, as well for Markdown files. It is a pure Tcl/Tk widget which does not need any compilation.

The widget is not(!) to be intended to be used as a web browser. It only supports relative links on a local filesystem, it does not(!) support style sheets, it does not support any http(s) or webserver like links or images. It is tought as a fallback widget in cases where no other possibilities exists to display HTML or Markdown markup inside a Tk application. So it can be used in cases where the developer has control over the used subset of HTML markup or as a fallback mechanism where no other possibilities exists to display HTML or Markdown documents.

The widget is intended to be used for instance as a help viewer or in other cases where the developer has control about the used html tags. Comments and feedbacks are welcome. The shtmlview::shtmlview widget overloads the text widget and provides new commands, named back, browse, dosearch, forward, home, open, reload, url and new options, named -browsecmd, -home, -tablesupport, -toolbar.

Furthermore the file shtmlview.tcl can be used as standalone application to render Markdown and HTML files by executing shtmlview.tcl filename in the terminal.

The ::shtmlview::shtmlview command creates creates a new window (given by the pathName argument) and makes it into ::shtmlview::shtmlview widget. The ::shtmlview::shtmlview command returns its pathName argument. At the time this command is invoked, there must not exist a window named pathName, but pathName's parent must exist. The API described in this document is not the whole API offered by the snit object ::shtmlview::shtmlview. Instead, it is the subset of that API that is expected not to change in future versions.

Background: ::shtmlview::shtmlview is a pure Tcl/Tk widget based on the library htmllib developed in the 90ties by Stephen Uhler and Clif Flynt. This library was wrapped into the excellent mega-widget framework snit by Robert Heller in 2009. His widget however was tied directly into a help system. The author of this document just isolated the display part and added some functions such as changing font size and a few buttons in the toolbar. Also a rudimentary display of data tables was added. Later as well support for inline images and extended keybindings and Markdown support was added.

## INSTALLATION

The widget requires the tcllib snit package and optional, if desired to display Markdown files, the tcllib Markdown library. The shtmlview::shtmlview package is delivered as a normal Tcl package folder which can be placed anywhere on your file system or in a folder belonging to your Tcl library path. In case you installed it into a non-standard folder just use append your auto_path variable as shown below:

    lappend auto_path /path/to/parent-folder ;# of shtmlview folder
    package require shtmlview::shtmlview

Alternatively you can directly source the file shtmlview.tcl into your Tcl application.

## COMMANDS

::shtmlview::shtmlview pathName ?options?

  Creates and configures a shtmlview widget.

## WIDGET OPTIONS

To configure the internal text widget the helptext command courld be used directly.

-browsecmd cmd

  Each time a HTML or Markdown page is rendered the given -browsecmd is invoked. The actual URL is appended as first argument to the command.

-historycombo boolean

  If true (default is false) displays a ttk::combobox if the tile package is available in the toolbar. Can be only set a widget creation.

-home string

  Set's the homepage filename of the shtmlview widget. If not set, the first page browsed will be automatically set as the home page.

-tablesupport boolean

  If true (default) the widget will provide some table support. This will have some undesired results if table tags are misused as markup tool. Simple html tables with th and td tags should display however well if no internal markup inside those tags is implemented.

-toolbar boolean

  If true (default) a toolbar will be displayed on top providing standard buttons for methods back, forward and home as well as search facilities for the widget. Default: true

## WIDGET COMMANDS

Each shtmlview widget created with the above command supports the following commands and options:

pathName back

  Displays the previous HTML and Markdown page in the browsing history if any.

pathName browse filename ?args?

  Displays the HTML or Markdown page given by filename(s). The first given filename will be shown in the widget, the other, optional given filenames will be added to the history stack only and can be walked using the history keys, f and b.

pathName dosearch string direction

  Search and hilights the given string from the current index either in the given direction either forward (default) or backwards.

pathName forward

  Displays the next HTML or Markdown page in the browsing history if any.

pathName getFiles

  This command returns a list of all visited files, cleaned up for multiple entries and without anchor links.

pathName getHistory

  This command returns a list of the current history of visited files and anchors.

pathName getTextWidget

  This commands returns the internal pathname of the text widget. The developer can that way thereafter deal directly with the internal text widget if required. Alternatively the helptext command can be used. See below.

pathName helptext cmd ?options?

  This command exposes the internal text widget. See the following example:

          ::shtmlview::shtmlview .help
          .help browse index.html
          .help helptext configure -background yellow

pathName home

  Displays the first HTML or Markdown page which was called by pathName browse or set by -home.

pathName open

  Displays a standard file dialog to open a HTML or Markdown page to be displayed in the shtmlview::shtmlview widget.

pathName reload

  Reloads and redisplays the current HTML or Markdown page visible inside the shtmlview::shtmlview widget.

pathName url

  Returns the current URL displayed in the ::shtmlview::shtmlview widget.

## BINDINGS FOR THE WIDGET

The widget contain standard navigation key bindings to browse the content of an HTML or Markdown page. Furthermore the keypress s and r are bound to the start of forward and reverse searches in the content. The keys 'n' (next) and 'p' (previous) are used to repeat the current search. The keys 'f' and 'b' keys are bound to browsing forward and backward in the browse history. The 'q' key deletes the current file from the history and displays the next one. The 'TAB' key browses to the next hyperlink, and pressing the Return/Enter key process the current link. The key combination 'Ctrl-r' reloads the current page.

## EXAMPLE

        package require Tk
        package require snit
        package require shtmlview::shtmlview
        proc browsed {url} {
            puts "You browsed $url"
        }
        set help [::shtmlview::shtmlview .help -toolbar true  -browsecmd browsed]
        $help browse index.html
        pack $help -fill both -expand true -side left
        package require Markdown
        $help browser test.md

Further examples are in the source package for shtmlview::shtmlview.

## CHANGELOG

- 2022-02-25 version 0.9.2 - fix for tk_textCopy and documentation update

2022-03-06 version 0.9.3

- support for MouseWheel bindings

- fixing hyperlinks to http(s) links

- support for file-anchor links like 'file.html#anchor'

- support for '#' as link to the top

- thanks to aplsimple for suggestions and bug reports

2022-03-XX version 1.0.0

- HTML 3.2 tags div, sub, sup, small, big

- initial support for Markdown files

- initial support for base64 encoded inline image files

- support for jpg images if img::jpeg library is available

- support for svg images if critcl and librsvg-dev(el) or terminal application rsvg-convert or cairosvg are available

- back and forward as well for anchors

- first and last browse entry buttons for history

- history with full file path to allow directory changes

- improved usage line and install option

- keyboard bindings for next and previous search

- return and tab for links

- historycombo option

- toolbar fix

- browse fix for non-existing files

- removed unused css/stylesheet and web forms code

- thanks to pepdiz for bug-reports and suggestions

## TODO

- Markdown rendering using tcllib library Markdown in case URL ends with .md (done)

- Support for SVG images for instance using svgconvert https://wiki.tcl-lang.org/page/svgconvert at least on Linux/Windows

- More tags, see tag history add 3.2 tags: http://www.martinrinehart.com/frontend-engineering/engineers/html/html-tag-history.html (done)

## Thanks

Stephen Uhler, Clif Flynt and Robert Heller, they provided the majority of the code in this widget.

## Bugs, Ideas, Feedback

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such to the author of this package. Please also report any ideas for enhancements you may have for either package and/or documentation.

## Code Copyright

BSD License type:

Sun Microsystems, Inc. The following terms apply to all files a ssociated with the software unless explicitly disclaimed in individual files.

The authors hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply.

IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

RESTRICTED RIGHTS: Use, duplication or disclosure by the government is subject to the restrictions as set forth in subparagraph (c) (1) (ii) of the Rights in Technical Data and Computer Software Clause as DFARS 252.227-7013 and FAR 52.227-19.

## See Also

text

## Keywords

html, text, widget

## Copyright

Copyright © 2018-2022, Detlef Groth <detlef(at)dgroth(dot)de>
Copyright © 2009, Robert Heller
Copyright © 2000, Clif Flynt
Copyright © 1995-1999, Stephen Uhler