1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
.. _commands-display:
Display Commands
================
Display command is type of command that modifies item data before displaying.
The modified data are only used for displaying the item and are not stored.
The command is executed just before an item needs to be displayed. This can
sometimes happen multiple times for the same item if the data or
configuration changes or the tab was unloaded.
Display commands can be created in Command dialog by setting Type of Action
to :ref:`command-dialog-display`.
Use ``data()`` to retrieve current item data and ``setData()`` to set the
data to display (these are not stored permanently).
E.g. use slightly different color for plain text items.
.. code-block:: js
copyq:
if ( str(data(mimeText)) && !str(data(mimeHtml)) ) {
html = escapeHtml(data(mimeText))
setData(mimeHtml, '<span style="color:#764">' + html + '</span>')
}
E.g. try to interpret text as Markdown (with ``marked`` external utility).
.. code-block:: js
copyq:
var text = data(mimeText)
var result = execute('marked', null, text)
if (result && result.exit_code == 0) {
setData(mimeHtml, result.stdout)
}
|