Understanding the "markdown preview" plugin

Hello!

I want to use Gnome Builder’s markdown preview feature in another project, and I would like to understand how it works.

I tried to find the callback function that gets triggered when the “Open preview…” button is pressed. I found the following menu.ui file:

<?xml version="1.0"?>
<interface>
  <menu id="ide-editor-page-menu">
    <section id="ide-editor-page-preview-section">
      <item>
        <attribute name="id">markdown-preview-item</attribute>
        <attribute name="label" translatable="yes">Open Preview…</attribute>
        <attribute name="action">workspace.markdown-preview.preview</attribute>
        <attribute name="hidden-when">action-disabled</attribute>
      </item>
    </section>
  </menu>
</interface>

I need your help to figure out the following things (please send the relevant place in the code):

  1. How this button connects to the overall document menu.

  2. Where is the callback function.

  3. How it takes the markdown text buffer and sends it to this plugin.

Here is an example of using the markdown preview:

  1. I’m not experienced with menus. After searching for: "ide-editor-page-menu", I found this: src/libide/editor/ide-editor-page.c · main · GNOME / gnome-builder · GitLab It uses some builder specific stuff like MenuManager, but underneath it’s Gtk.PopoverMenu
  2. From menu.ui we can find action path. Action name “preview” should be located somewhere in the sources. After a bit of searching for "preview": Action definition using builder macro here src/plugins/markdown-preview/gbp-markdown-preview-workspace-addin.c · main · GNOME / gnome-builder · GitLab. And the handler: src/plugins/markdown-preview/gbp-markdown-preview-workspace-addin.c · main · GNOME / gnome-builder · GitLab
  3. There is a handler of page-changed which receives new focused page and retrieved buffer from it: src/plugins/markdown-preview/gbp-markdown-preview-workspace-addin.c · main · GNOME / gnome-builder · GitLab

src/plugins/markdown-preview/gbp-markdown-html-generator.c · main · GNOME / gnome-builder · GitLab is also an interesting piece. It slaps html around buffer contents and returns it to IdeHtmlGenerator

Ide – 47 can help you figuring out the rest of it.

1 Like