1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-30 10:36:35 +02:00
joplin/packages/renderer
2024-12-12 16:40:09 +01:00
..
assets Desktop, Cli: Mermaid version update (#11367) 2024-11-13 10:07:54 +00:00
lib
MdToHtml Desktop: Fixes #11425: Fixed checkboxes alignment in note viewer 2024-11-22 20:18:38 +00:00
tests
Tools
vendor
.gitignore
assetsToHeaders.ts Chore: Refactor renderer package: Limit dependency on @joplin/lib and improve type safety (#9701) 2024-01-18 11:20:10 +00:00
defaultNoteStyle.js
defaultResourceModel.ts Chore: Refactor renderer package: Limit dependency on @joplin/lib and improve type safety (#9701) 2024-01-18 11:20:10 +00:00
headerAnchor.ts Tools: Implement @typescript-eslint/no-explicit-any rule 2024-04-05 12:16:49 +01:00
highlight.ts
HtmlToHtml.test.ts Desktop: Fixed an issue that could cause certain notes not to render when they contain an empty STYLE tag 2024-05-06 11:30:04 +01:00
HtmlToHtml.ts Desktop: Fix images fail to render in the preview pane for HTML notes (#10806) 2024-08-02 14:47:43 +01:00
htmlUtils.test.ts Desktop: Fixes #10061: Fix paste adds newlines in the Rich Text Editor when certain plugins are enabled (#10635) 2024-06-19 10:54:34 +01:00
htmlUtils.ts Desktop: Fix images fail to render in the preview pane for HTML notes (#10806) 2024-08-02 14:47:43 +01:00
index.ts Chore: Refactor renderer package: Limit dependency on @joplin/lib and improve type safety (#9701) 2024-01-18 11:20:10 +00:00
InMemoryCache.ts Tools: Implement @typescript-eslint/no-explicit-any rule 2024-04-05 12:16:49 +01:00
jest.config.js
MarkupToHtml.ts Tools: Implement @typescript-eslint/no-explicit-any rule 2024-04-05 12:16:49 +01:00
MdToHtml.ts Desktop: Fixes #11020: Fix clicking on most non-media resource links opens them inline (#11022) 2024-09-11 16:49:35 +01:00
noteStyle.ts Desktop: Fixed fallback icon size on HTML notes (#11448) 2024-11-27 12:14:32 +00:00
package.json Releasing sub-packages 2024-12-12 16:40:09 +01:00
publish.sh Chore: Rename instances of yarn run to just yarn 2024-01-26 20:19:28 +00:00
README.md
stringUtils.js
tsconfig.json
types.ts Windows: Fix PDF, video, and audio rendering (#10881) 2024-08-17 12:22:03 +01:00
urlUtils.js
utils.ts Windows: Fix PDF, video, and audio rendering (#10881) 2024-08-17 12:22:03 +01: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',
	},
];