1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/packages/renderer
2023-11-12 15:38:06 +00:00
..
assets lock files 2023-11-12 15:02:44 +00:00
lib
MdToHtml Mobile: Add support for drawing pictures (#7588) 2023-10-02 15:15:51 +01:00
tests
Tools
vendor
.gitignore
assetsToHeaders.js
defaultNoteStyle.js
headerAnchor.ts
highlight.ts
HtmlToHtml.test.ts Desktop: Fixes #8485: Note imported from Web Clipper is broken after being saved from the Rich Text editor 2023-07-26 17:37:24 +01:00
HtmlToHtml.ts Desktop: Fixes #8485: Note imported from Web Clipper is broken after being saved from the Rich Text editor 2023-07-26 17:37:24 +01:00
htmlUtils.test.ts Desktop: Resolves #8691: Improve pasting content from Word and Excel (#8705) 2023-08-21 18:37:33 +01:00
htmlUtils.ts Desktop: Allow attaching a file from the Markdown editor for HTML notes 2023-10-31 16:53:47 +00:00
index.ts
InMemoryCache.ts Tools: Apply eslint rule @typescript-eslint/no-inferrable-types with ignoreArguments=false 2023-06-30 09:11:26 +01:00
jest.config.js
MarkupToHtml.ts Desktop: Sanitize rendered output in safe mode (#8507) 2023-07-19 13:09:03 +01:00
MdToHtml.ts Plugins: Add support for getting plugin settings from a Markdown renderer 2023-11-03 19:45:21 +00:00
noteStyle.ts
package.json Releasing sub-packages 2023-11-12 15:38:06 +00:00
pathUtils.ts Tools: Apply eslint rule @typescript-eslint/no-inferrable-types with ignoreArguments=false 2023-06-30 09:11:26 +01:00
publish.sh
README.md
stringUtils.js
tsconfig.json Mobile: Add support for drawing pictures (#7588) 2023-10-02 15:15:51 +01:00
urlUtils.js
utils.ts

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',
	},
];