Markdown Viewer

Read-only Markdown renderer — fetches a .md file by URL (public web or SGApps fs://), renders it inline with navigation on in-page links to other .md files and a "Go Home" bar.
Internally this is the Code Editor webapp launched with a chrome-less preset: no sidebar, no top toolbars, no tab bar, light theme, and the markdown tab type pre-selected (not Monaco source — the rendered HTML view).
For an editable Markdown surface with WYSIWYG, DOCX/ODF import/export, and both source and preview modes, use Writer instead.

Live Demo

<iframe id="md-demo" src="/online/webapp/markdown-browser" width="100%" height="580" frameborder="0" style="border:1px solid #ccc; border-radius:4px;"></iframe>
<script>window._wsConnect('md-demo', 'mdSocket');</script>

Embed

<iframe src="https://sgapps.io/online/webapp/markdown-browser"
    width="100%" height="700" frameborder="0"></iframe>

Open with a Markdown URL

Encode the Markdown URL in base64 and append it as /url/&#x3C;base64&#x3E;:

var mdUrl = "https://sgapps.io/webapp-docs/README.md";
var src = "https://sgapps.io/online/webapp/markdown-browser/url/" + btoa(mdUrl);

Default (no arg) opens the Code Editor welcome page.

Navigation

Links inside the rendered Markdown behave contextually:

Relative image / asset URLs are resolved against the current .md file's folder.

API Events

Markdown Viewer inherits the full Code Editor API. The active tab is a markdown-render tab (not a Monaco text buffer), so these behave specifically:

files:open -- Open a .md File in a New Tab

socket.fire("webapp::instance::request", "files:open",
    "/files/README.md", "markdown",
    function (err, tabId) { /* ... */ }
);

<button onclick="window._ws('mdSocket')&&window.mdSocket.fire('webapp::instance::request','files:open','web:///scripts/modules/sgapps/applications/code-editor/documentation/index.md','markdown',function(err,id){if(err)alert('Error: '+err.message);else alert('Opened tab '+id)})">Try: Open Welcome Doc</button>

fs:write + files:open -- Render In-Memory Markdown

var md = "# Hello\n\nThis Markdown was written from the embedder.";
socket.fire("webapp::instance::request", "fs:write",
    "input://memory/doc.md", md,
    function (err) {
        if (err) return console.error(err);
        socket.fire("webapp::instance::request", "files:open",
            "input://memory/doc.md", "markdown");
    }
);

<button onclick="window._ws('mdSocket')&&window.mdSocket.fire('webapp::instance::request','fs:write','input://demo-md.md','# Hello from docs\n\nThis is rendered inline.\n\n- item A\n- item B\n\n> Thanks for trying!\n',function(err){if(err)return alert('Error: '+err.message);window.mdSocket.fire('webapp::instance::request','files:open','input://demo-md.md','markdown')})">Try: Render In-Memory MD</button>

files:list -- List Open Tabs

socket.fire("webapp::instance::request", "files:list",
    function (err, tabs) { console.log(tabs); }
);

<button onclick="window._ws('mdSocket')&&window.mdSocket.fire('webapp::instance::request','files:list',function(err,tabs){alert(JSON.stringify(tabs,null,2))})">Try: List Tabs</button>

Window Chrome Controls

Fullscreen (hide header + footer):

socket.fire("webapp::instance::embed-mode", true);

Granular controls — see Embedding.

Supported Mime Types

Registered for: text/x-markdown, text/markdown.
Opens from the SGApps window manager when a .md is double-clicked in File Manager. Also auto-selected for directory paths matching /public/documentation/, /public/share/*/, /apps/*/public/ via the readme-preview handler (renders the folder's README.md as the entry point).

Features

sgapps.io