Welcome | Get started | Dive into Lino | Contribute | Reference
Suggesters in Lino Noi¶
Compare the demo2
fixture of lino.modlib.comments
.
This is a tested document. The following instructions are used for initialization:
>>> import lino
>>> lino.startup('lino_book.projects.noi1e.settings.demo')
>>> from lino.api.doctest import *
The memo parser in Lino Noi has two suggesters:
>>> mp = settings.SITE.plugins.memo.parser
>>> pprint(mp.suggesters)
{'#': <lino.modlib.memo.parser.Suggester object at ...>,
'@': <lino.modlib.memo.parser.Suggester object at ...>}
Where #
refers to a ticket and @
refers to a user.
>>> print(mp.parse("This comment refers to #11 and @robin."))
This comment refers to <a title="#11 (Class-based Foos and Bars?)" href="/api/tickets/Tickets/11">#11</a> and <a title="Robin Rood" href="/api/users/AllUsers/1">@robin</a>.
If the word behind a suggester char does not point to any existing database row, the text remains unchanged:
>>> print(mp.parse("This comment refers to #robin and @11."))
This comment refers to #robin and @11.
>>> print(mp.parse("This comment refers to # and @."))
This comment refers to # and @.
All parsing is done using a special anonymous user having user_type
lino.modlib.users.UserTypes.admin
because otherwise the stored previews
of memo texts would depend on who saved them. You can override this by
specifying your own action request:
>>> ses = rt.login('robin')
>>> print(mp.parse("This comment refers to #11 and @robin.", ar=ses))
This comment refers to <a title="#11 (Class-based Foos and Bars?)" href="Detail">#11</a> and <a title="Robin Rood" href="Detail">@robin</a>.