Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
Suggesters in Lino Noi¶
Compare the demo2
fixture of lino.modlib.comments
.
Side note: Code snippets (lines starting with >>>
) in this document get
tested as part of our development workflow. The following
initialization snippet tells you which demo project is being used in
this document.
>>> 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 href="/api/tickets/Tickets/11" title="#11 (Class-based Foos and Bars?)" style="text-decoration:none">#11</a> and <a href="/api/users/AllUsers/1" title="Robin Rood" style="text-decoration:none">@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 href="…" title="#11 (Class-based Foos and Bars?)">#11</a> and <a href="…" title="Robin Rood">@robin</a>.