-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat: don't use JupyterLab math rendering We still need to ship our own math renderer to render `math_` tokens, so let's avoid using two different renderers in the same implementation * WIP: initial commit * Feat: add support for JupyterLab's ILatexTypesetter We migrate the math parsing responsibility to the MarkdownIt parser. Any element matching `.math` will be rendered using the typesetter. We add `markdown-it-dollarmath` to perform math parsing of $-math * Refactor: rename typesetter → typesetter-adaptor Feat: remove unneeded math wrappers * Chore: restore yarn lock * Refactor: remove debug print * Feat: add rank to plugins * Feat: add rank to plugins * Feat: add pre-parse hook * Feat: don't return node form postRender * Package: set alpha version of new release * Docs: improve documentation * Fix: set double_inline
- Loading branch information
Showing
12 changed files
with
297 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ build-backend = "hatchling.build" | |
name = "jupyterlab-markup" | ||
description = "Extensible markdown rendering support in markdown" | ||
readme = "README.md" | ||
license = "BSD-3-Clause" | ||
license = { file="LICENSE" } | ||
requires-python = ">=3.7" | ||
authors = [ | ||
{ name = "Angus Hollands", email = "[email protected]" }, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# setup.py shim for use with versions of JupyterLab that require | ||
# it for extensions. | ||
__import__("setuptools").setup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { PACKAGE_NS, simpleMarkdownItPlugin } from '..'; | ||
|
||
interface IRenderOptions { | ||
displayMode: boolean; | ||
} | ||
|
||
/** | ||
* ADd support for math parsing | ||
*/ | ||
export const dollarmath = simpleMarkdownItPlugin(PACKAGE_NS, { | ||
id: 'markdown-it-dollarmath', | ||
title: 'Dollar Math', | ||
description: 'Parse inline and display LaTeX math using $-delimiters', | ||
documentationUrls: { | ||
Plugin: 'https://github.com/executablebooks/markdown-it-dollarmath' | ||
}, | ||
plugin: async () => { | ||
const dollarmathPlugin = await import( | ||
/* webpackChunkName: "markdown-it-anchor" */ 'markdown-it-dollarmath' | ||
); | ||
return [ | ||
dollarmathPlugin.default, | ||
{ | ||
allow_space: true, | ||
allow_digits: true, | ||
double_inline: true, | ||
allow_labels: true, | ||
labelNormalizer(label: string) { | ||
return label.replace(/[\s]+/g, '-'); | ||
}, | ||
renderer(content: string, opts: IRenderOptions) { | ||
const { displayMode } = opts; | ||
if (displayMode) { | ||
return `$$${content}$$`; | ||
} else { | ||
return `$${content}$`; | ||
} | ||
}, | ||
labelRenderer(label: string) { | ||
return `<a href="#${label}" class="mathlabel" title="Permalink to this equation">¶<a>`; | ||
} | ||
} | ||
]; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { IMarkdownIt, PACKAGE_NS } from '..'; | ||
import { ILatexTypesetter } from '@jupyterlab/rendermime'; | ||
import { JupyterFrontEndPlugin } from '@jupyterlab/application'; | ||
|
||
/** | ||
* Adds anchors to headers | ||
*/ | ||
const plugin_id = 'typesetter-adaptor'; | ||
export const typesetterAdaptor: JupyterFrontEndPlugin<void> = { | ||
id: `${PACKAGE_NS}:${plugin_id}`, | ||
autoStart: true, | ||
requires: [IMarkdownIt, ILatexTypesetter], | ||
activate: (app, markdownIt: IMarkdownIt, typesetter: ILatexTypesetter) => { | ||
const provider: IMarkdownIt.IPluginProvider = { | ||
id: plugin_id, | ||
title: 'ILatexTypesetter Adaptor', | ||
description: | ||
'Enable math rendering using JupyterLab ILatexTypesetter interface', | ||
documentationUrls: {}, | ||
plugin: async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
return [md => {}]; | ||
}, | ||
postRenderHook: async () => { | ||
const math_selectors = ['.math']; | ||
return { | ||
async postRender(node: HTMLElement): Promise<void> { | ||
// Find nodes to typeset | ||
const nodes = [ | ||
...node.querySelectorAll(math_selectors.join(',')) | ||
] as HTMLElement[]; | ||
// Only typeset these nodes | ||
await Promise.all(nodes.map(node => typesetter.typeset(node))); | ||
} | ||
}; | ||
} | ||
}; | ||
markdownIt.addPluginProvider(provider); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.