1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/ReactNativeClient/lib/joplin-renderer
Laurent Cozic 84c3ef144d
Desktop: Resolves #176: Added experimental WYSIWYG editor (#2556)
* Trying to get TuiEditor to work

* Tests with TinyMCE

* Fixed build

* Improved asset loading

* Added support for Joplin source blocks

* Added support for Joplin source blocks

* Better integration

* Make sure noteDidUpdate event is always dispatched at the right time

* Minor tweaks

* Fixed tests

* Add support for checkboxes

* Minor refactoring

* Added support for file attachments

* Add support for fenced code blocks

* Fix new line issue on code block

* Added support for Fountain scripts

* Refactoring

* Better handling of saving and loading notes

* Fix saving and loading ntoes

* Handle multi-note selection and fixed new note creation issue

* Fixed newline issue in test

* Fixed newline issue in test

* Improve saving and loading

* Improve saving and loading note

* Removed undeeded prop

* Fixed issue when new note being saved is incorrectly reloaded

* Refactoring and improve saving of note when unmounting component

* Fixed TypeScript error

* Small changes

* Improved further handling of saving and loading notes

* Handle provisional notes and fixed various saving and loading bugs

* Adding back support for HTML notes

* Added support for HTML notes

* Better handling of editable nodes

* Preserve image HTML tag when the size is set

* Handle switching between editor when the note has note finished saving

* Handle templates

* Handle templates

* Handle loading note that is being saved

* Handle note being reloaded via sync

* Clean up

* Clean up and improved logging

* Fixed TS error

* Fixed a few issues

* Fixed test

* Logging

* Various improvements

* Add blockquote support

* Moved CWD operation to shim

* Removed deleted files

* Added support for Joplin commands
2020-03-09 23:24:57 +00:00
..
assets Desktop, Mobile: Fixes #2638: Improved Mermaid rendering on small viewports 2020-03-04 01:55:48 +00:00
MdToHtml Desktop: Resolves #176: Added experimental WYSIWYG editor (#2556) 2020-03-09 23:24:57 +00:00
tests
Tools Desktop, Mobile: Fixes #2477: Add new Katex fonts to improve rendering (#2478) 2020-02-11 22:53:12 +00:00
vendor
.gitignore
assetsToHeaders.js Desktop, Mobile: Fixes #2357: Fix slow rendering and memory leak issues with Katex notes 2020-02-08 11:11:04 +00:00
defaultNoteStyle.js
HtmlToHtml.js Desktop: Resolves #176: Added experimental WYSIWYG editor (#2556) 2020-03-09 23:24:57 +00:00
htmlUtils.js All: Regression: Fixed issue with style embeded in notes 2020-03-06 18:22:40 +00:00
index.js
MarkupToHtml.js All: Security: Fixed potential Arbitrary File Read via XSS 2020-02-13 23:59:23 +00:00
MdToHtml.js Desktop: Resolves #176: Added experimental WYSIWYG editor (#2556) 2020-03-09 23:24:57 +00:00
noteStyle.js Desktop: Resolves #176: Added experimental WYSIWYG editor (#2556) 2020-03-09 23:24:57 +00:00
package-lock.json Desktop, Mobile: Resolves #2001: Added Mermaid diagrams support 2020-02-11 22:28:43 +00:00
package.json All: Fixes #2667: Fixed sanitize function so that it does not break HTML 2020-03-06 00:54:21 +00:00
pathUtils.js
publish.sh
README.md Desktop, Mobile: Fixes #2374: Fix rendering of certain letters in Katex. Fixed printing when note contains Katex code 2020-02-08 00:15:56 +00:00
stringUtils.js
urlUtils.js
utils.js

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

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