minihtml Reference
Ver
:
Sublime Text contains a custom HTML and CSS engine, named minihtml, for displaying stylized content in editor panes. HTML content can be displayed in both popup windows and phantoms.
minihtml provides a limited subset of HTML and CSS features found in most web browsers. While only certain CSS and HTML features may be implemented, they are designed to be standards compliant. Any feature implemented should function the same way in minihtml as in a browser.
HTMLπ
Attributesπ
The following attributes are supported:
class
β for CSS selectorsid
β for CSS selectorsstyle
β inline CSS
4073href
β callback-based navigation, protocols support
4085title
β tooltips
Protocolsπ
In HTML sheets, popups, annotations and completion item details, the href=""
attribute of <a>
tags automatically supports three protocols:
http:
β standard URL, will use system default browser to openhttps:
β standard URL, will use system default browser to opensubl:
β a command name and args to invoke a command
Valid subl:
URL formats include:
subl:command_name
subl:command_name {"arg_name": arg_value, β¦}
For popups and annotations it is possible to define an on_navigate
callback
via the API that will be called for any URL except for the subl:
protocol.
This API-based approach was the only way to handle URLs before build 4073.
Inline Formattingπ
In the details field of completion items, quick panel items and list input items, there is support for a limited, inline formatting subset of minihtml. This allows for some basic text formatting, that respects the theme and color scheme the user has selected.
The supported tags are:
<a href="">
β protocols<b>
<strong>
<i>
<em>
<u>
<tt>
<code>
Best Practicesπ
To allow color scheme authors to tweak the look of popups and phantoms, it is
best to add a unique id=""
attribute to the <body>
tag of your pluginβs
HTML.
Within the <body>
tag, add a <style>
tag containing selectors that do
not use the id. Leave that for selectors in color schemes to be able to
override the plugin.
<body id="my-plugin-feature">
<style>
div.error {
background-color: red;
padding: 5px;
}
</style>
<div class="error"></div>
</body>
Predefined Classesπ
When minihtml processes the HTML markup, it will automatically add a single
class name to the <html>
tag. The class name will be dark
or light
,
and is designed to allow for advanced use of CSS in styling phantoms and
popups.
Which class is added is based on the lightness, in the HSL color space, of the
background color of the current color scheme. If the lightness is less than
0.5, dark
will be added. If the lightness is greater than or equal to 0.5,
light
will be added.
CSSπ
The following list provides an overview of supported properties and values:
display
:none
,inline
,block
,list-item
,inline-block
4085margin
: positive unitsmargin-top
: positive unitsmargin-right
: positive unitsmargin-bottom
: positive unitsmargin-left
: positive unitsposition
:static
,relative
top
: positive and negative unitsright
: positive and negative unitsbottom
: positive and negative unitsleft
: positive and negative unitsbackground-color
: colorsfont-family
: comma-separated list of font familiesfont-size
: positive unitsfont-style
:normal
,italic
font-weight
:normal
,bold
line-height
: positive unitstext-decoration
:none
,underline
4085text-align
:left
,right
,center
4099white-space
:normal
,nowrap
,pre
4170,pre-wrap
4170color
: colorspadding
: positive unitspadding-top
: positive unitspadding-right
: positive unitspadding-bottom
: positive unitspadding-left
: positive unitsborder
: positive units or border-style or colorsborder-top
: positive units or border-style or colorsborder-right
: positive units or border-style or colorsborder-bottom
: positive units or border-style or colorsborder-left
: positive units or border-style or colorsborder-style
:none
,solid
border-top-style
: border-styleborder-right-style
: border-styleborder-bottom-style
: border-styleborder-left-style
: border-styleborder-width
: positive unitsborder-top-width
: positive unitsborder-right-width
: positive unitsborder-bottom-width
: positive unitsborder-left-width
: positive unitsborder-color
: colorsborder-top-color
: colorsborder-right-color
: colorsborder-bottom-color
: colorsborder-left-color
: colorsborder-radius
: positive unitsborder-top-left-radius
: positive unitsborder-top-right-radius
: positive unitsborder-bottom-right-radius
: positive unitsborder-bottom-left-radius
: positive units
4050list-style-type
:circle
,square
anddisc
Unitsπ
Supported units of measurement include:
rem
em
px
pt
rem
units are recommended because they are based on the userβs font_size
setting, and they will not cascade.
Colorsπ
Colors may be specified via:
Named colors:
white
,tan
, etcShorthand hex:
#fff
Shorthand hex with alpha:
#fff8
Full hex:
#ffffff
Full hex with alpha:
#ffffff80
RGB functional notation:
rgb(255, 255, 255)
RGBA functional notation:
rgba(255, 255, 255, 0.5)
HSL functional notation:
hsl(0, 100%, 100%)
HSLA functional notation:
hsla(0, 100%, 100%, 0.5)
HWB functional notation: hwb(0, 20%, 20%), hwb(0, 20%, 20%, 0.5)
3181transparent
color()
Mod Function (Proprietary)π
Additionally, color values may be modified using the CSS Color Module Level 4 (05 July 2016) color-mod function with the following adjusters. Unfortunately in a later draft of CSS Color Module Level 4, the color-mod function was removed.
alpha()
/a()
3179saturation()
/s()
3179lightness()
/l()
blend()
blenda()
3181min-contrast()
(Proprietary)
.error {
background-color: color(var(--background) alpha(0.25));
}
.error {
background-color: color(var(--background) blend(red 50%));
}
The color-mod function will be most useful in combination with variables.
min-contrast()
Adjusterπ
The min-contrast()
adjuster for the color()
mod function is a
non-standard addition that is custom to minihtml. At the time of
implementation, the CSS Color Module Level 4 spec had a contrast()
adjuster,
but it only allowed taking a color and modifying it to provide contrast with
itself, as opposed to taking a second color (typically a background) and making
sure the foreground has sufficient contrast with the background.
min-contrast()
accepts two parameters: a background color to measure the
contrast against, and a minimum contrast ratio between the βbaseβ color and the
background color. The ratio will be a decimal number, typically between 2.0
and 4.5
.
.error {
background-color: color(var(--redish) min-contrast(var(--background) 2.5));
}
Please see the documentation for the contrast() adjuster for details about how the contrast ratio is calculated and how the color is modified to meet it.
Variablesπ
CSS variables are also supported using custom properties and the var()
functional notation. Custom properties are those starting with --
.
html {
--fg: #f00;
}
.error {
background-color: var(--fg);
}
The one limitation is that the var()
notation can not be used for part of a
multi-number value, such as padding
or margin
. With those aggregate
properties, the var()
notation must be used for the complete value.
Predefined Variablesπ
When a color scheme is loaded, the background and foreground colors are set to
CSS variables, along with the closest color found to a handful of basic colors.
These are all set in an html { }
rule set in the default CSS style sheet.
var(--background)
var(--foreground)
var(--accent)
3179var(--redish)
var(--orangish)
var(--yellowish)
var(--greenish)
var(--cyanish)
3179var(--bluish)
var(--purplish)
var(--pinkish)
The algorithm to pick the colors uses the HSL color space and uses several
heuristics to try and pick colors that are suitable for foreground use. In the
case that the automatic color selection is undesirable, color scheme authors
may override the appropriate values with their own html { }
rule set contained
in the popupCss
or phantomCss
settings.
If a variable with one of the predefined names is set in the selected .sublime-color-scheme, that value will be used instead of trying to find a match from the colors used in the color scheme.