1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-03 08:35:29 +02:00
joplin/packages/renderer
2021-07-03 16:40:44 +01:00
..
assets All: Update Mermaid: 8.8.4 -> 8.10.2 (#5092) 2021-06-18 08:53:16 +01:00
lib
MdToHtml Desktop: Fixes #4612: Fix mermaid diagrams in WYSIWYG editor (#4670) 2021-03-15 16:31:11 +00:00
tests Tools: Cleaned up tests and splitted sync tests into smaller parts 2020-12-01 18:05:24 +00:00
Tools
vendor
.gitignore
assetsToHeaders.js
defaultNoteStyle.js
HtmlToHtml.ts Desktop: Pass custom CSS property to all export handlers and renderers 2021-05-19 15:00:16 +02:00
htmlUtils.ts Desktop, Mobile: Filter out form elements from note body to prevent potential XSS (thanks to Dmytro Vdovychinskiy for the PoC) 2021-06-11 20:17:45 +02:00
index.ts Desktop, Mobile: Fixed issue where file:// URLs would not be rendered correctly 2021-01-02 16:53:59 +00:00
InMemoryCache.ts Tools: Apply rule @typescript-eslint/member-delimiter-style 2020-11-12 19:29:22 +00:00
jest.config.js Desktop, Mobile: Fixes #4119: Fixed links imported from ENEX as HTML 2020-11-20 16:04:47 +00:00
MarkupToHtml.ts Desktop: Pass custom CSS property to all export handlers and renderers 2021-05-19 15:00:16 +02:00
MdToHtml.ts Desktop: Pass custom CSS property to all export handlers and renderers 2021-05-19 15:00:16 +02:00
noteStyle.ts Mobile, Desktop: Fixes #3991: Added RTL support for Markdown editor and Preview. (#4822) 2021-04-30 16:03:03 +01:00
package-lock.json Setup version 2.2 2021-07-03 16:40:44 +01:00
package.json Setup version 2.2 2021-07-03 16:40:44 +01:00
pathUtils.ts Desktop: Add support for media players (video, audio and PDF) 2020-12-09 21:30:51 +00:00
publish.sh
README.md Server: Add support for sharing notes via a link 2021-01-29 18:45:11 +00:00
stringUtils.js
tsconfig.json
urlUtils.js
utils.ts Server: Add support for sharing notes via a link 2021-01-29 18:45:11 +00:00

Joplin Renderer

This is the renderer used by Joplin to render notes in Markdown or HTML format.

Installation

npm i -s joplin-renderer

Certain plugins require additional assets like CSS, fonts, etc. These assets are in the /assets directory and should be copied to wherever the application can find them at runtime.

Usage

const { MarkupToHtml } = require('joplin-renderer');

const options = {};

// The notes are rendered using the provided theme. The supported theme properties are in `defaultNoteStyle.js`
// and this is what is used if no theme is provided. A `theme` object can be provided to override default theme
// properties.
const theme = {};

const markdown = "Testing `MarkupToHtml` renderer";

const markupToHtml = new MarkupToHtml(options);
const result = await markupToHtml.render(MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN, markdown, theme, options);

console.info('HTML:', result.html);
console.info('Plugin assets:', result.pluginAssets);

When calling render(), an object with the following properties is returned:

  • html: The rendered HTML code
  • pluginAssets: The assets required by the plugins

The assets need to be loaded by the calling application. For example this is how they are loaded in the Joplin desktop application:

function loadPluginAssets(assets) {
	for (let i = 0; i < assets.length; i++) {
		const asset = assets[i];

		if (asset.mime === 'text/css') {
			const link = document.createElement('link');
			link.rel = 'stylesheet';
			link.href = 'pluginAssets/' + asset.name;
			document.getElementById('joplin-container-styleContainer').appendChild(link);
		}
	}
}

Development

Updating a markdown-it plugin

Whenever updating a Markdown-it plugin, such as Katex or Mermaid, make sure to run npm run buildAssets, which will compile the CSS and JS for use in the Joplin applications.

Adding asset files

A plugin (or rule) can have any number of assets, such as CSS or font files, associated with it. To add an asset to a plugin, follow these steps:

  • Add the file under /assets/PLUGIN_NAME/your-asset-file.css
  • Register this file within the plugin using context.pluginAssets[PLUGIN_NAME] = [{ name: 'your-asset-file.css' }]

See katex.js for an example of how this is done.

Adding inline CSS

A plugin can ask for some CSS to be included inline in the rendered HTML. This is convenient as it means no extra file needs to be packaged. Use this syntax to do this:

context.pluginAssets[PLUGIN_NAME] = [
	{
		inline: true,
		text: ".my-css { background-color: 'green' }",
		mime: 'text/css',
	},
];