Memo commands in Lino Noi

>>> from lino import startup
>>> startup('lino_book.projects.team.settings.demo')
>>> from lino.api.doctest import *

The description of a ticket and the text of a comment (short_text) are rich text fields.

And additionally they can contain memo markup commands (see memo : The memo parser).

Lino Noi memo command reference

url

Insert a link to an external web page. The first argument is the URL (mandatory). If no other argument is given, the URL is used as text. Otherwise the remaining text is used as the link text.

The link will always open in a new window (target="_blank")

Usage examples:

  • [url http://www.example.com]

  • [url http://www.example.com example]

  • [url http://www.example.com another example]

ticket

Refer to a ticket. Usage example:

See [ticket 1].

company

Refer to a company. Usage example:

I met Joe from [company 1] and we agreed...

person

Refer to a person. Usage example:

I met [person 7 Joe] and we agreed...

py

Refer to a Python object.

Usage examples:

  • [py lino]

  • [py lino.modlib.memo.parser]

  • [py lino_xl.lib.tickets.models.Ticket]

  • [py lino_xl.lib.tickets.models.Ticket tickets.Ticket]

The obj2memo method

You might want to programmatically generate a text containing memo markup.

For example when your code knows some database object and you want to create a description which would refer to your object if rendered with memo:

>>> ar = rt.login('robin')
>>> obj = rt.models.tickets.Ticket.objects.get(pk=1)
>>> txt = ar.obj2memo(obj)
>>> print(txt)
[ticket 1] (Föö fails to bar when baz)

Let's also check whether the produced text is valid:

>>> print(ar.parse_memo(txt))
<a href="Detail" title="F&#246;&#246; fails to bar when baz">#1</a> (Föö fails to bar when baz)

Suggesters

There are two suggesters in Lino Noi: when the user types a "#", they get a list of tickets. When they type a "@", they get a list with all users.

Every site instance has its global memo parser:

>>> mp = dd.plugins.memo.parser
>>> mp.suggesters.keys()
dict_keys(['@', '#'])

A suggester always returns a maximum of 5 suggestions:

>>> len(list(mp.suggesters['#'].get_suggestions()))
5
>>> list(mp.suggesters['#'].get_suggestions("12"))
[(12, '#12 (⚒ Foo cannot bar)')]
>>> list(mp.suggesters['#'].get_suggestions("why"))
[(20, '#20 (⚒ Why is foo so bar)'), (29, '#29 (☾ Why is foo so bar)'), (38, '#38 (☐ Why is foo so bar)'), (47, '#47 (☑ Why is foo so bar)'), (56, '#56 (☒ Why is foo so bar)')]
>>> list(mp.suggesters['@'].get_suggestions())
[('jean', 'Jean'), ('luc', 'Luc'), ('marc', 'Marc'), ('mathieu', 'Mathieu'), ('robin', 'Robin Rood')]
>>> list(mp.suggesters['@'].get_suggestions("ma"))
[('marc', 'Marc'), ('mathieu', 'Mathieu'), ('romain', 'Romain Raffault')]
>>> mp.suggesters['#'].get_object("1")
Ticket #1 ('#1 (⛶ Föö fails to bar when baz)')
>>> mp.parse("#1", ar)
'<a href="Detail" title="#1 (&#9974; F&#246;&#246; fails to bar when baz)">#1</a>'

Bleaching

Comments a being bleached by default.

Check whether content has been bleached

>>> print(comments.Comment.objects.filter(body="o:OfficeDocumentSettings").first())
None
>>> obj  = comments.Comment.objects.filter(body__contains="and follow your welcome messages").first()
>>> print(obj.short_preview)
breaking  (...)

Above comments were created by the demo2 fixture of lino.modlib.comments.