Memo commands in Lino Noi¶
>>> from lino import startup
>>> startup('lino_book.projects.noi1e.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]
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öö 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 (⚹ Föö 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
.
Permalink URIs¶
Note that the URI of the link depends on the context.
Of course it depends on the site's front end (specfied in the default_ui
setting). But when the front end is
lino.modlib.extjs
, then we also get a different URL depending on whether
lino.core.requests.BaseRequest.permalink_uris
is set or not: Usually we
want a "javascript:..." URI because we don't want the page to reload when
executing an action.
For example when calling it e.g. from send_summary_emails
, we want a "permalink" whose
URI also works in the recipients email client where the JS application isn't yet
loaded. In that case we must explicitly set
lino.core.requests.BaseRequest.permalink_uris
to True.
>>> ses = rt.login('robin',
... renderer=settings.SITE.kernel.default_renderer)
>>> print(ses.parse_memo("See [ticket 1]."))
See <a href="javascript:Lino.tickets.Tickets.detail.run(null,{ "record_id": 1 })" title="Föö fails to bar when baz">#1</a>.
>>> ses.permalink_uris = True
>>> print(ses.parse_memo("See [ticket 1]."))
See <a href="/api/tickets/Tickets/1" title="Föö fails to bar when baz">#1</a>.
While the lino.modlib.bootstrap3
front end will render it
like this:
>>> ses = rt.login(renderer=dd.plugins.bootstrap3.renderer)
>>> print(ses.parse_memo("See [ticket 1]."))
See <a href="/bs3/tickets/Tickets/1" title="Föö fails to bar when baz">#1</a>.
When using this front end, the permalink_uris
parameter has no effect:
>>> ses.permalink_uris = True
>>> print(ses.parse_memo("See [ticket 1]."))
See <a href="/bs3/tickets/Tickets/1" title="Föö fails to bar when baz">#1</a>.
Or the plain text renderer will render:
>>> ses = rt.login()
>>> print(ses.parse_memo("See [ticket 1]."))
See <a href="Detail" title="Föö fails to bar when baz">#1</a>.
>>> ses.permalink_uris = True
>>> print(ses.parse_memo("See [ticket 1]."))
See <a href="Detail" title="Föö fails to bar when baz">#1</a>.