Skip to content

cxn-html: Display constructions in PyFCG notebooks

This merge request proposes to add several functions/routes necessary to add the following functionality to PyFCG: to show a Construction's HTML representation in a jupyter notebook when it is display'ed.

Note: To implement this, changes were made to the PyFCG, FCG-Go and babel repositories. To see the changes in effect, all three repos should be on their cxn-html branch. Each repo has a merge-request titled "cxn-html: Display constructions in PyFCG notebooks", all sharing this same description.

Testing

To see the changes in action, you can run grammar_writing.ipynb. When the sixth cell is run, you should see the firefighters_cxn in its HTML representation in the notebook.

Implementation

PyFCG

I implemented the _repr_html_ method of the Construction class, which determines what is shown when displayis called (implicitly) in a notebook. It requests the HTML of the construction to FCG-Go via one of 2 new routes: make_cxn_html or make_new_cxn_html and adds the necessary CSS to it. 2 types of HTML tag attribute (href and onclick) are removed because the HTML remains static in the notebook.

FCG-Go

FCG-Go receives the request (either through route fcg-make-cxn-html or fcg-make-new-cxn-html. It parses the payload and asks babel to (make-notebook-html cxn) where cxn is the construction that was sent by PyFCG.

Babel

make-notebook-html is a new method I implemented as a "stripped down" version of make-html for an fcg-construction. The construction's units are all fully expanded and as much "clickable" HTML elements were removed as possible.

Merge request reports

Loading